feat: begin implementing getReportsByAppId method

This commit is contained in:
Stevan Freeborn
2023-02-08 16:38:36 +00:00
parent b6605a4275
commit f0aeb51f60
7 changed files with 142 additions and 4 deletions
+24
View File
@@ -9,10 +9,12 @@ import { FileInfo } from './FileInfo';
import { FormulaField } from './FormulaField';
import { GetPagedAppsResponse } from './GetPagedAppsResponse';
import { GetPagedFieldsResponse } from './GetPagedFieldsResponse';
import { GetPagedReportsResponse } from './GetPagedReportsResponse';
import { ListField } from './ListField';
import { ListItemResponse } from './ListItemResponse';
import { ListValue } from './ListValue';
import { ReferenceField } from './ReferenceField';
import { Report } from './Report';
/**
* @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.
* @param fieldItem - The field item to convert.
+6 -2
View File
@@ -219,9 +219,13 @@ export class EndpointFactory {
/**
* @method getReportsByAppIdEndpoint - Gets the get reports by app id endpoint.
* @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.
*/
public static getReportsByAppIdEndpoint(appId: number): string {
return `/Reports/appId/${appId}`;
public static getReportsByAppIdEndpoint(
appId: number,
pagingRequest: PagingRequest
): string {
return `/Reports/appId/${appId}?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
}
}
+14
View File
@@ -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);
}
}
+18
View File
@@ -306,6 +306,24 @@ export class OnspringClient {
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.
* @param {string} endpoint - The endpoint that will be used to make the request.
+34
View File
@@ -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;
}
}