feat: continuing to work on implementing records methods

This commit is contained in:
StevanFreeborn
2023-02-10 00:49:50 -06:00
parent fde8b50717
commit 6ba77ce1d4
14 changed files with 494 additions and 105 deletions
+30
View File
@@ -16,6 +16,7 @@ import { GetPagedReportsResponse } from './GetPagedReportsResponse';
import { ListField } from './ListField';
import { ListItemResponse } from './ListItemResponse';
import { ListValue } from './ListValue';
import { Record } from './Record';
import { ReferenceField } from './ReferenceField';
import { Report } from './Report';
import { ReportData } from './ReportData';
@@ -308,6 +309,10 @@ export class ApiResponse<T> {
);
}
/**
* @method asReportDataType - Converts the ApiResponse to an ApiResponse<ReportData>.
* @returns {ApiResponse<ReportData>} - An ApiResponse<ReportData>.
*/
asReportDataType(): ApiResponse<ReportData> {
const apiResponse = this as ApiResponse<any>;
@@ -324,15 +329,40 @@ export class ApiResponse<T> {
);
}
/**
* @method asRecordType - Converts the ApiResponse to an ApiResponse<Record>.
* @returns {ApiResponse<Record>} - An ApiResponse<Record>.
*/
public asRecordType(): ApiResponse<Record> {
const apiResponse = this as ApiResponse<any>;
const record = new Record(
apiResponse.data.appId,
apiResponse.data.recordId,
apiResponse.data.fieldData
);
return new ApiResponse<Record>(
apiResponse.statusCode,
apiResponse.message,
record
);
}
/**
* @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.
* @returns {Field} - The converted field object.
* @throws {Error} - If the field item's type is unknown.
*/
private static getFieldByType(fieldItem: any): Field {
const type = FieldType[fieldItem.type];
const status = FieldStatus[fieldItem.status];
if (type === undefined) {
throw new Error(`Unknown field type: ${fieldItem.type as string}`);
}
switch (type) {
case FieldType.Reference: {
const multiplicity = Multiplicity[fieldItem.multiplicity];