fix: allow value property of record value model to be generically typed. feat: added methods to record model to allow adding a record value to the field data property or adding multiple record values to the field data property. wrote tests for these two new methods.
This commit is contained in:
+25
-3
@@ -17,18 +17,40 @@ export class Record {
|
||||
/**
|
||||
* @property {RecordValue[]} fieldData - The data for the fields in the record.
|
||||
*/
|
||||
public fieldData: RecordValue[];
|
||||
public fieldData: Array<RecordValue<any>>;
|
||||
|
||||
/**
|
||||
* @constructor - Creates a new instance of Record.
|
||||
* @param {number} appId - The id of the app that the record belongs to.
|
||||
* @param {number} recordId - The id of the record.
|
||||
* @param {RecordValue[]} fieldData - The data for the fields in the record.
|
||||
* @param {RecordValue<any>[]} fieldData - The data for the fields in the record.
|
||||
* @returns {Record} - A new instance of Record.
|
||||
*/
|
||||
constructor(appId: number, recordId: number, fieldData: RecordValue[] = []) {
|
||||
constructor(
|
||||
appId: number,
|
||||
recordId: number,
|
||||
fieldData: Array<RecordValue<any>> = []
|
||||
) {
|
||||
this.appId = appId;
|
||||
this.recordId = recordId;
|
||||
this.fieldData = fieldData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method addValue - Adds a value to the record.
|
||||
* @param {RecordValue<any>} fieldData - The value to add to the record.
|
||||
* @returns {void}
|
||||
*/
|
||||
public addValue(fieldData: RecordValue<any>): void {
|
||||
this.fieldData.push(fieldData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @method addValues - Adds values to the record.
|
||||
* @param {Array<RecordValue<any>>} fieldData - The values to add to the record.
|
||||
* @returns {void}
|
||||
*/
|
||||
public addValues(fieldData: Array<RecordValue<any>>): void {
|
||||
this.fieldData = this.fieldData.concat(fieldData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { TimeSpanData } from './TimeSpanData';
|
||||
/**
|
||||
* @class RecordValue - A value for a field in a record.
|
||||
*/
|
||||
export class RecordValue {
|
||||
export class RecordValue<T> {
|
||||
/**
|
||||
* @property {RecordValueType} type - The type of the record value.
|
||||
*/
|
||||
@@ -23,9 +23,9 @@ export class RecordValue {
|
||||
public fieldId: number;
|
||||
|
||||
/**
|
||||
* @property {any} value - The value of the field.
|
||||
* @property {T | any} value - The value of the field.
|
||||
*/
|
||||
public value: any;
|
||||
public value: T | any;
|
||||
|
||||
/**
|
||||
* @constructor - Creates a new instance of RecordValue.
|
||||
@@ -34,7 +34,7 @@ export class RecordValue {
|
||||
* @param {any} value - The value of the field.
|
||||
* @returns {RecordValue} - A new instance of RecordValue.
|
||||
*/
|
||||
constructor(type: RecordValueType, fieldId: number, value: any) {
|
||||
constructor(type: RecordValueType, fieldId: number, value: T | any) {
|
||||
this.type = type;
|
||||
this.fieldId = fieldId;
|
||||
this.value = value;
|
||||
|
||||
Reference in New Issue
Block a user