feat: begin implementing getReportsByAppId method
This commit is contained in:
@@ -9,10 +9,12 @@ import { FileInfo } from './FileInfo';
|
|||||||
import { FormulaField } from './FormulaField';
|
import { FormulaField } from './FormulaField';
|
||||||
import { GetPagedAppsResponse } from './GetPagedAppsResponse';
|
import { GetPagedAppsResponse } from './GetPagedAppsResponse';
|
||||||
import { GetPagedFieldsResponse } from './GetPagedFieldsResponse';
|
import { GetPagedFieldsResponse } from './GetPagedFieldsResponse';
|
||||||
|
import { GetPagedReportsResponse } from './GetPagedReportsResponse';
|
||||||
import { ListField } from './ListField';
|
import { ListField } from './ListField';
|
||||||
import { ListItemResponse } from './ListItemResponse';
|
import { ListItemResponse } from './ListItemResponse';
|
||||||
import { ListValue } from './ListValue';
|
import { ListValue } from './ListValue';
|
||||||
import { ReferenceField } from './ReferenceField';
|
import { ReferenceField } from './ReferenceField';
|
||||||
|
import { Report } from './Report';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class ApiResponse - A generic response object for API requests.
|
* @class ApiResponse - A generic response object for API requests.
|
||||||
@@ -275,6 +277,28 @@ export class ApiResponse<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public asGetPagedReportsResponseType(): ApiResponse<GetPagedReportsResponse> {
|
||||||
|
const apiResponse = this as ApiResponse<any>;
|
||||||
|
|
||||||
|
const reports = apiResponse.data.items.map((item: any) => {
|
||||||
|
return new Report(item.id, item.appId, item.name, item.description);
|
||||||
|
});
|
||||||
|
|
||||||
|
const getPagedReportsResponse = new GetPagedReportsResponse(
|
||||||
|
reports,
|
||||||
|
apiResponse.data.pageNumber,
|
||||||
|
apiResponse.data.pageSize,
|
||||||
|
apiResponse.data.totalPages,
|
||||||
|
apiResponse.data.totalRecords
|
||||||
|
);
|
||||||
|
|
||||||
|
return new ApiResponse<GetPagedReportsResponse>(
|
||||||
|
apiResponse.statusCode,
|
||||||
|
apiResponse.message,
|
||||||
|
getPagedReportsResponse
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method asFileCollectionType - Converts the field item to the appropriate field object based upon the field item's type.
|
* @method asFileCollectionType - Converts the field item to the appropriate field object based upon the field item's type.
|
||||||
* @param fieldItem - The field item to convert.
|
* @param fieldItem - The field item to convert.
|
||||||
|
|||||||
@@ -219,9 +219,13 @@ export class EndpointFactory {
|
|||||||
/**
|
/**
|
||||||
* @method getReportsByAppIdEndpoint - Gets the get reports by app id endpoint.
|
* @method getReportsByAppIdEndpoint - Gets the get reports by app id endpoint.
|
||||||
* @param {number} appId - The id of the app.
|
* @param {number} appId - The id of the app.
|
||||||
|
* @param {PagingRequest} pagingRequest - The paging information that will be used to make the request.
|
||||||
* @returns {string} - The get reports by app id endpoint.
|
* @returns {string} - The get reports by app id endpoint.
|
||||||
*/
|
*/
|
||||||
public static getReportsByAppIdEndpoint(appId: number): string {
|
public static getReportsByAppIdEndpoint(
|
||||||
return `/Reports/appId/${appId}`;
|
appId: number,
|
||||||
|
pagingRequest: PagingRequest
|
||||||
|
): string {
|
||||||
|
return `/Reports/appId/${appId}?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { PagedResponse } from './PagedResponse';
|
||||||
|
import { type Report } from './Report';
|
||||||
|
|
||||||
|
export class GetPagedReportsResponse extends PagedResponse<Report> {
|
||||||
|
constructor(
|
||||||
|
items: Report[],
|
||||||
|
pageNumber: number,
|
||||||
|
pageSize: number,
|
||||||
|
totalPages: number,
|
||||||
|
totalRecords: number
|
||||||
|
) {
|
||||||
|
super(items, pageNumber, pageSize, totalPages, totalRecords);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -306,6 +306,24 @@ export class OnspringClient {
|
|||||||
return apiResponse;
|
return apiResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getReportsByAppId(
|
||||||
|
appId: number,
|
||||||
|
pagingRequest: PagingRequest = new PagingRequest(1, 50)
|
||||||
|
) {
|
||||||
|
const endpoint = EndpointFactory.getReportsByAppIdEndpoint(
|
||||||
|
appId,
|
||||||
|
pagingRequest
|
||||||
|
);
|
||||||
|
|
||||||
|
const apiResponse = await this.get<any>(endpoint);
|
||||||
|
|
||||||
|
if (apiResponse.isSuccessful === false) {
|
||||||
|
return apiResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResponse.asGetPagedReportsResponseType();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method get - Makes a GET request to the specified endpoint.
|
* @method get - Makes a GET request to the specified endpoint.
|
||||||
* @param {string} endpoint - The endpoint that will be used to make the request.
|
* @param {string} endpoint - The endpoint that will be used to make the request.
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* @class Report - Represents a report.
|
||||||
|
*/
|
||||||
|
export class Report {
|
||||||
|
/**
|
||||||
|
* @property {number} appId - The id of the app.
|
||||||
|
*/
|
||||||
|
public appId: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number} id - The id of the report.
|
||||||
|
*/
|
||||||
|
public id: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {string} name - The name of the report.
|
||||||
|
*/
|
||||||
|
public name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {string} description - The description of the report.
|
||||||
|
*/
|
||||||
|
public description: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of the Report class.
|
||||||
|
*/
|
||||||
|
constructor(appId: number, id: number, name: string, description: string) {
|
||||||
|
this.appId = appId;
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -942,4 +942,45 @@ describe('ApiResponse', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('asGetPagedReportsResponse', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(ApiResponse.prototype.asGetPagedReportsResponseType).to.not.be
|
||||||
|
.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be a function', function () {
|
||||||
|
expect(ApiResponse.prototype.asGetPagedReportsResponseType).to.be.a(
|
||||||
|
'function'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have no parameters', function () {
|
||||||
|
expect(
|
||||||
|
ApiResponse.prototype.asGetPagedReportsResponseType.length
|
||||||
|
).to.equal(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an ApiResponse<GetPagedReportsResponse>', function () {
|
||||||
|
const mockResponseData = [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
id: 1,
|
||||||
|
name: 'string',
|
||||||
|
description: 'description',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
appId: 2,
|
||||||
|
id: 2,
|
||||||
|
name: 'string',
|
||||||
|
description: 'description'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
const getPagedReportsResponse = apiResponse.asGetPagedReportsResponseType();
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -162,8 +162,11 @@ describe('EndpointFactory', function () {
|
|||||||
|
|
||||||
describe('getReportsByAppIdEndpoint', function () {
|
describe('getReportsByAppIdEndpoint', function () {
|
||||||
it('should return the correct reports by app id endpoint', function () {
|
it('should return the correct reports by app id endpoint', function () {
|
||||||
const result = EndpointFactory.getReportsByAppIdEndpoint(1);
|
const result = EndpointFactory.getReportsByAppIdEndpoint(
|
||||||
expect(result).to.equal('/Reports/appId/1');
|
1,
|
||||||
|
new PagingRequest(2, 1000)
|
||||||
|
);
|
||||||
|
expect(result).to.equal('/Reports/appId/1?pageSize=1000&pageNumber=2');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user