feat: finish implementing getRecordById method

This commit is contained in:
Stevan Freeborn
2023-02-10 23:22:41 -06:00
parent 6ba77ce1d4
commit 0af3a9d7ca
14 changed files with 1208 additions and 104 deletions
+10 -1
View File
@@ -17,6 +17,7 @@ import { ListField } from './ListField';
import { ListItemResponse } from './ListItemResponse';
import { ListValue } from './ListValue';
import { Record } from './Record';
import { RecordValue } from './RecordValue';
import { ReferenceField } from './ReferenceField';
import { Report } from './Report';
import { ReportData } from './ReportData';
@@ -336,10 +337,18 @@ export class ApiResponse<T> {
public asRecordType(): ApiResponse<Record> {
const apiResponse = this as ApiResponse<any>;
const recordValues = apiResponse.data.fieldData.map((fieldData: any) => {
return new RecordValue(
fieldData.type,
fieldData.fieldId,
fieldData.value
);
});
const record = new Record(
apiResponse.data.appId,
apiResponse.data.recordId,
apiResponse.data.fieldData
recordValues
);
return new ApiResponse<Record>(
+46 -46
View File
@@ -1,46 +1,46 @@
import { type DataFormat } from '../enums/DataFormat';
/**
* @class GetRecordRequest - A request to get a record.
*/
export class GetRecordRequest {
/**
* @property {number} appId - The id of the app that the record belongs to.
*/
public appId: number;
/**
* @property {number} recordId - The id of the record.
*/
public recordId: number;
/**
* @property {number[]} fieldIds - The ids of the fields to include in the response.
*/
public fieldIds: number[];
/**
* @property {DataFormat} dataFormat - The format of the data in the response.
*/
public dataFormat: DataFormat;
/**
* @constructor - Creates a new instance of GetRecordRequest.
* @param {number} appId - The id of the app that the record belongs to.
* @param {number} recordId - The id of the record.
* @param {number[]} fieldIds - The ids of the fields to include in the response.
* @param {DataFormat} dataFormat - The format of the data in the response.
* @returns {GetRecordRequest} - A new instance of GetRecordRequest.
*/
constructor(
appId: number,
recordId: number,
fieldIds: number[],
dataFormat: DataFormat
) {
this.appId = appId;
this.recordId = recordId;
this.fieldIds = fieldIds;
this.dataFormat = dataFormat;
}
}
import { DataFormat } from '../enums/DataFormat';
/**
* @class GetRecordRequest - A request to get a record.
*/
export class GetRecordRequest {
/**
* @property {number} appId - The id of the app that the record belongs to.
*/
public appId: number;
/**
* @property {number} recordId - The id of the record.
*/
public recordId: number;
/**
* @property {number[]} fieldIds - The ids of the fields to include in the response.
*/
public fieldIds: number[];
/**
* @property {DataFormat} dataFormat - The format of the data in the response.
*/
public dataFormat: DataFormat;
/**
* @constructor - Creates a new instance of GetRecordRequest.
* @param {number} appId - The id of the app that the record belongs to.
* @param {number} recordId - The id of the record.
* @param {number[]} fieldIds - The ids of the fields to include in the response.
* @param {DataFormat} dataFormat - The format of the data in the response.
* @returns {GetRecordRequest} - A new instance of GetRecordRequest.
*/
constructor(
appId: number,
recordId: number,
fieldIds: number[] = [],
dataFormat: DataFormat = DataFormat.Raw
) {
this.appId = appId;
this.recordId = recordId;
this.fieldIds = fieldIds;
this.dataFormat = dataFormat;
}
}
+4 -2
View File
@@ -313,9 +313,11 @@ export class OnspringClient {
public async getRecordById(
request: GetRecordRequest
): Promise<ApiResponse<Record>> {
const { appId, recordId, ...params } = request;
const { appId, recordId, fieldIds, dataFormat } = request;
const endpoint = EndpointFactory.getRecordByIdEndpoint(appId, recordId);
const apiResponse = await this.get<any>(endpoint, { params });
const apiResponse = await this.get<any>(endpoint, {
params: { fieldIds: fieldIds.join(','), dataFormat },
});
if (apiResponse.isSuccessful === false) {
return apiResponse;
+11 -12
View File
@@ -78,18 +78,17 @@ export class RecordValue {
*/
public asAttachmentArray(): Attachment[] {
this.validateType([RecordValueType.AttachmentList]);
const storageLocation = FileStorageSite[this.value.storageLocation];
if (storageLocation === undefined) {
throw new Error(
`${
this.value.storageLocation as string
} is not a valid FileStorageSite.`
);
}
return this.value.map((attachment: any) => {
const storageLocation = FileStorageSite[attachment.storageLocation];
if (storageLocation === undefined) {
throw new Error(
`${
this.value.storageLocation as string
} is not a valid FileStorageSite.`
);
}
const hasNotes =
attachment.notes !== null && attachment.notes !== undefined;
@@ -177,7 +176,7 @@ export class RecordValue {
scoringGroup.listValueId,
scoringGroup.name,
scoringGroup.score,
scoringGroup.maximunScore
scoringGroup.maximumScore
)
);
}