feat: implement getReportById method
This commit is contained in:
@@ -15,6 +15,8 @@ import { ListItemResponse } from './ListItemResponse';
|
||||
import { ListValue } from './ListValue';
|
||||
import { ReferenceField } from './ReferenceField';
|
||||
import { Report } from './Report';
|
||||
import { ReportData } from './ReportData';
|
||||
import { Row } from './Row';
|
||||
|
||||
/**
|
||||
* @class ApiResponse - A generic response object for API requests.
|
||||
@@ -303,6 +305,22 @@ export class ApiResponse<T> {
|
||||
);
|
||||
}
|
||||
|
||||
asReportDataType(): ApiResponse<ReportData> {
|
||||
const apiResponse = this as ApiResponse<any>;
|
||||
|
||||
const rows = apiResponse.data.rows.map((row) => {
|
||||
return new Row(row.recordId, row.cells);
|
||||
});
|
||||
|
||||
const reportData = new ReportData(apiResponse.data.columns, rows);
|
||||
|
||||
return new ApiResponse<ReportData>(
|
||||
apiResponse.statusCode,
|
||||
apiResponse.message,
|
||||
reportData
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @method asFileCollectionType - Converts the field item to the appropriate field object based upon the field item's type.
|
||||
* @param {any} fieldItem - The field item to convert.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { type DataFormat } from '../enums/DataFormat';
|
||||
import { type ReportDataType } from '../enums/ReportDataType';
|
||||
import { type PagingRequest } from './PagingRequest';
|
||||
|
||||
/**
|
||||
@@ -210,10 +212,16 @@ export class EndpointFactory {
|
||||
/**
|
||||
* @method getReportByIdEndpoint - Gets the get report by id endpoint.
|
||||
* @param {number} reportId - The id of the report.
|
||||
* @param {DataFormat} apiDataFormat - The data format that will be used to make the request.
|
||||
* @param {ReportDataType} reportDataType - The report data type that will be used to make the request.
|
||||
* @returns {string} - The get report by id endpoint.
|
||||
*/
|
||||
public static getReportByIdEndpoint(reportId: number): string {
|
||||
return `/Reports/id/${reportId}`;
|
||||
public static getReportByIdEndpoint(
|
||||
reportId: number,
|
||||
apiDataFormat: DataFormat,
|
||||
reportDataType: ReportDataType
|
||||
): string {
|
||||
return `/Reports/id/${reportId}?apiDataFormat=${apiDataFormat}&dataType=${reportDataType}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,8 @@ import { PagingRequest } from './PagingRequest';
|
||||
import { ArgumentValidator } from './ArgumentValidator';
|
||||
import { EndpointFactory } from './EndpointFactory';
|
||||
import { ApiResponseFactory } from './ApiResponseFactory';
|
||||
import { DataFormat } from '../enums/DataFormat';
|
||||
import { ReportDataType } from '../enums/ReportDataType';
|
||||
import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
|
||||
import { type ApiResponse } from './ApiResponse';
|
||||
import { type GetPagedAppsResponse } from './GetPagedAppsResponse';
|
||||
@@ -17,6 +19,7 @@ import { type File } from './File';
|
||||
import { type ListItemResponse } from './ListItemResponse';
|
||||
import { type ListItemRequest } from './ListItemRequest';
|
||||
import { type GetPagedReportsResponse } from './GetPagedReportsResponse';
|
||||
import { type ReportData } from './ReportData';
|
||||
|
||||
/**
|
||||
* @class OnspringClient - A client that can communicate with the Onspring API.
|
||||
@@ -331,6 +334,26 @@ export class OnspringClient {
|
||||
return apiResponse.asGetPagedReportsResponseType();
|
||||
}
|
||||
|
||||
public async getReportById(
|
||||
reportId: number,
|
||||
apiDataFormat: DataFormat = DataFormat.Raw,
|
||||
reportDataType: ReportDataType = ReportDataType.ReportData
|
||||
): Promise<ApiResponse<ReportData>> {
|
||||
const endpoint = EndpointFactory.getReportByIdEndpoint(
|
||||
reportId,
|
||||
apiDataFormat,
|
||||
reportDataType
|
||||
);
|
||||
|
||||
const apiResponse = await this.get<any>(endpoint);
|
||||
|
||||
if (apiResponse.isSuccessful === false) {
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
return apiResponse.asReportDataType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @method get - Makes a GET request to the specified endpoint.
|
||||
* @param {string} endpoint - The endpoint that will be used to make the request.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { type Row } from './Row';
|
||||
|
||||
export class ReportData {
|
||||
public columns: string[];
|
||||
public rows: Row[];
|
||||
|
||||
constructor(columns: string[], rows: Row[]) {
|
||||
this.columns = columns;
|
||||
this.rows = rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export class Row {
|
||||
public recordId: number;
|
||||
public cells: object[];
|
||||
|
||||
constructor(recordId: number, cells: object[]) {
|
||||
this.recordId = recordId;
|
||||
this.cells = cells;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user