feat: finish writing tests for getRecordsByIds method
This commit is contained in:
@@ -392,6 +392,32 @@ export class ApiResponse<T> {
|
||||
);
|
||||
}
|
||||
|
||||
public asRecordCollectionType(): ApiResponse<CollectionResponse<Record>> {
|
||||
const apiResponse = this as ApiResponse<any>;
|
||||
|
||||
const records = apiResponse.data.items.map((item: any) => {
|
||||
const recordValues = item.fieldData.map((fieldData: any) => {
|
||||
return new RecordValue(
|
||||
fieldData.type,
|
||||
fieldData.fieldId,
|
||||
fieldData.value
|
||||
);
|
||||
});
|
||||
return new Record(item.appId, item.recordId, recordValues);
|
||||
});
|
||||
|
||||
const collectionResponse = new CollectionResponse<Record>(
|
||||
apiResponse.data.count,
|
||||
records
|
||||
);
|
||||
|
||||
return new ApiResponse<CollectionResponse<Record>>(
|
||||
apiResponse.statusCode,
|
||||
apiResponse.message,
|
||||
collectionResponse
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
|
||||
@@ -357,10 +357,22 @@ export class OnspringClient {
|
||||
return apiResponse.asRecordType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @method getRecordsByIds - Gets records by their ids.
|
||||
* @param {GetRecordsRequest} request - The request that will be used to get the records.
|
||||
* @returns {Promise<ApiResponse<CollectionResponse<Record>>>} - A promise that resolves to an ApiResponse of type CollectionResponse of type Record.
|
||||
*/
|
||||
public async getRecordsByIds(
|
||||
request: GetRecordsRequest
|
||||
): Promise<ApiResponse<CollectionResponse<Record>>> {
|
||||
throw new Error('Not implemented');
|
||||
const endpoint = EndpointFactory.getRecordsByIdsEndpoint();
|
||||
const apiResponse = await this.post<any>(endpoint, request);
|
||||
|
||||
if (apiResponse.isSuccessful === false) {
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
return apiResponse.asRecordCollectionType();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user