feat: implement method to Record model to allow it to convert itself to a SaveRecordRequest

This commit is contained in:
Stevan Freeborn
2023-02-13 17:13:52 -06:00
parent 74d247047e
commit f07cd3043a
2 changed files with 41 additions and 0 deletions
+10
View File
@@ -1,4 +1,5 @@
import { type RecordValue } from './RecordValue';
import { SaveRecordRequest } from './SaveRecordRequest';
/**
* @class Record - A record in an app.
@@ -53,4 +54,13 @@ export class Record {
public addValues(fieldData: Array<RecordValue<any>>): void {
this.fieldData = this.fieldData.concat(fieldData);
}
public convertToSaveRecordRequest(): SaveRecordRequest {
const fields = this.fieldData.reduce((acc, cur) => {
acc.set(cur.fieldId, cur.value);
return acc;
}, new Map<number, any>());
return new SaveRecordRequest(this.appId, this.recordId, fields);
}
}