feat: begin working on implementing record methods

This commit is contained in:
StevanFreeborn
2023-02-09 22:21:20 -06:00
parent 3b3e210920
commit fde8b50717
30 changed files with 629 additions and 286 deletions
+75
View File
@@ -0,0 +1,75 @@
/**
* @enum RecordValueType - The type of the record value.
*/
export enum RecordValueType {
/**
* @constant String - The record value is a string.
* @type {string}
*/
String = 'String',
/**
* @constant Integer - The record value is an integer.
* @type {string}
*/
Integer = 'Integer',
/**
* @constant Decimal - The record value is a decimal.
* @type {string}
*/
Decimal = 'Decimal',
/**
* @constant Date - The record value is a Date.
* @type {string}
*/
Date = 'Date',
/**
* @constant TimeSpan - The record value is a TimeSpan.
* @type {string}
*/
TimeSpan = 'TimeSpan',
/**
* @constant Guid - The record value is a Guid.
*/
Guid = 'Guid',
/**
* @constant StringList - The record value is a list of strings.
* @type {string}
*/
StringList = 'StringList',
/**
* @constant IntegerList - The record value is a list of integers.
* @type {string}
*/
IntegerList = 'IntegerList',
/**
* @constant GuidList - The record value is a list of Guids.
* @type {string}
*/
GuidList = 'GuidList',
/**
* @constant AttachmentList - The record value is a list of attachments.
* @type {string}
*/
AttachmentList = 'AttachmentList',
/**
* @constant ScoringGroupList - The record value is a list of scoring groups.
* @type {string}
*/
ScoringGroupList = 'ScoringGroupList',
/**
* @constant FileList - The record value is a list of files.
* @type {string}
*/
FileList = 'FileList',
}
-75
View File
@@ -1,75 +0,0 @@
/**
* @enum ResultValueType - The type of the result value.
*/
export enum ResultValueType {
/**
* @constant String - The result value is a string.
* @type {string}
*/
String = 'String',
/**
* @constant Integer - The result value is an integer.
* @type {string}
*/
Integer = 'Integer',
/**
* @constant Decimal - The result value is a decimal.
* @type {string}
*/
Decimal = 'Decimal',
/**
* @constant Date - The result value is a Date.
* @type {string}
*/
Date = 'Date',
/**
* @constant TimeSpan - The result value is a TimeSpan.
* @type {string}
*/
TimeSpan = 'TimeSpan',
/**
* @constant Guid - The result value is a Guid.
*/
Guid = 'Guid',
/**
* @constant StringList - The result value is a list of strings.
* @type {string}
*/
StringList = 'StringList',
/**
* @constant IntegerList - The result value is a list of integers.
* @type {string}
*/
IntegerList = 'IntegerList',
/**
* @constant GuidList - The result value is a list of Guids.
* @type {string}
*/
GuidList = 'GuidList',
/**
* @constant AttachmentList - The result value is a list of attachments.
* @type {string}
*/
AttachmentList = 'AttachmentList',
/**
* @constant ScoringGroupList - The result value is a list of scoring groups.
* @type {string}
*/
ScoringGroupList = 'ScoringGroupList',
/**
* @constant FileList - The result value is a list of files.
* @type {string}
*/
FileList = 'FileList',
}
+22 -12
View File
@@ -1,5 +1,8 @@
import { type AxiosResponse } from 'axios';
import { FieldStatus } from '../enums/FieldStatus';
import { FieldType } from '../enums/FieldType';
import { FormulaOutputType } from '../enums/FormulaOutputType';
import { Multiplicity } from '../enums/Multiplicity';
import { App } from './App';
import { CollectionResponse } from './CollectionResponse';
import { CreatedWithIdResponse } from './CreatedWithIdResponse';
@@ -327,48 +330,55 @@ export class ApiResponse<T> {
* @returns {Field} - The converted field object.
*/
private static getFieldByType(fieldItem: any): Field {
switch (fieldItem.type) {
const type = FieldType[fieldItem.type];
const status = FieldStatus[fieldItem.status];
switch (type) {
case FieldType.Reference: {
const multiplicity = Multiplicity[fieldItem.multiplicity];
return new ReferenceField(
fieldItem.id,
fieldItem.appId,
fieldItem.name,
fieldItem.type,
fieldItem.status,
type,
status,
fieldItem.isRequired,
fieldItem.isUnique,
fieldItem.multiplicity,
multiplicity,
fieldItem.referencedAppId
);
}
case FieldType.List: {
const values = ApiResponse.getListValues(fieldItem);
const multiplicity = Multiplicity[fieldItem.multiplicity];
return new ListField(
fieldItem.id,
fieldItem.appId,
fieldItem.name,
fieldItem.type,
fieldItem.status,
type,
status,
fieldItem.isRequired,
fieldItem.isUnique,
fieldItem.multiplicity,
multiplicity,
fieldItem.listId,
values
);
}
case FieldType.Formula: {
const values = ApiResponse.getListValues(fieldItem);
const outputType = FormulaOutputType[fieldItem.outputType];
return new FormulaField(
fieldItem.id,
fieldItem.appId,
fieldItem.name,
fieldItem.type,
fieldItem.status,
type,
status,
fieldItem.isRequired,
fieldItem.isUnique,
fieldItem.outputType,
outputType,
values
);
}
@@ -377,8 +387,8 @@ export class ApiResponse<T> {
fieldItem.id,
fieldItem.appId,
fieldItem.name,
fieldItem.type,
fieldItem.status,
type,
status,
fieldItem.isRequired,
fieldItem.isUnique
);
+3 -3
View File
@@ -5,17 +5,17 @@ export class App {
/**
* @property {string} href - The URL to the app
*/
href: string;
public href: string;
/**
* @property {number} id - The id of the app
*/
id: number;
public id: number;
/**
* @property {string} name - The name of the app
*/
name: string;
public name: string;
/**
* @constructor - Creates a new instance of the App class.
+18
View File
@@ -0,0 +1,18 @@
export class Attachment {
public fileId: number;
public fileName: string;
public notes: string;
public storageLocation: string;
constructor(
fileId: number,
fileName: string,
notes: string,
storageLocation: string
) {
this.fileId = fileId;
this.fileName = fileName;
this.notes = notes;
this.storageLocation = storageLocation;
}
}
+8 -18
View File
@@ -1,5 +1,5 @@
import { FieldStatus } from '../enums/FieldStatus';
import { FieldType } from '../enums/FieldType';
import { type FieldStatus } from '../enums/FieldStatus';
import { type FieldType } from '../enums/FieldType';
/**
* @class Field - Represents a Field.
@@ -45,36 +45,26 @@ export class Field {
* @param {number} id - The id of the Field.
* @param {number} appId - The id of the App that the Field belongs to.
* @param {string} name - The name of the Field.
* @param {string} type - The type of the Field.
* @param {string} status - The status of the Field.
* @param {FieldType} type - The type of the Field.
* @param {FieldStatus} status - The status of the Field.
* @param {boolean} isRequired - Indicates whether or not the Field is required.
* @param {boolean} isUnique - Indicates whether or not the Field is required to be unique.
* @returns {Field} - A new Field.
* @throws {Error} - Throws an error if the type is not valid.
* @throws {Error} - Throws an error if the status is not valid.
*/
public constructor(
id: number,
appId: number,
name: string,
type: string,
status: string,
type: FieldType,
status: FieldStatus,
isRequired: boolean,
isUnique: boolean
) {
if (FieldType[type] === undefined) {
throw new Error(`The type '${type}' is not a valid FieldType.`);
}
if (FieldStatus[status] === undefined) {
throw new Error(`The status '${status}' is not a valid FieldStatus.`);
}
this.id = id;
this.appId = appId;
this.name = name;
this.type = FieldType[type];
this.status = FieldStatus[status];
this.type = type;
this.status = status;
this.isRequired = isRequired;
this.isUnique = isUnique;
}
+10 -16
View File
@@ -1,4 +1,6 @@
import { FormulaOutputType } from '../enums/FormulaOutputType';
import { type FieldStatus } from '../enums/FieldStatus';
import { type FieldType } from '../enums/FieldType';
import { type FormulaOutputType } from '../enums/FormulaOutputType';
import { Field } from './Field';
import { type ListValue } from './ListValue';
@@ -21,35 +23,27 @@ export class FormulaField extends Field {
* @param {number} id - The id of the formula field.
* @param {number} appId - The id of the app the formula field belongs to.
* @param {string} name - The name of the formula field.
* @param {string} type - The type of the formula field.
* @param {string} status - The status of the formula field.
* @param {FieldType} type - The type of the formula field.
* @param {FieldStatus} status - The status of the formula field.
* @param {boolean} isRequired - Whether the formula field is required.
* @param {boolean} isUnique - Whether the formula field is unique.
* @param {string} outputType - The output type of the formula field.
* @param {FormulaOutputType} outputType - The output type of the formula field.
* @param {ListValue[]} values - The list values of the formula field.
* @returns {FormulaField} - A new FormulaField.
* @throws {Error} - Throws an error if the outputType is not a valid FormulaOutputType.
*/
constructor(
id: number,
appId: number,
name: string,
type: string,
status: string,
type: FieldType,
status: FieldStatus,
isRequired: boolean,
isUnique: boolean,
outputType: string,
outputType: FormulaOutputType,
values: ListValue[]
) {
super(id, appId, name, type, status, isRequired, isUnique);
if (FormulaOutputType[outputType] === undefined) {
throw new Error(
`The outputType ${outputType} is not a valid FormulaOutputType.`
);
}
this.outputType = FormulaOutputType[outputType];
this.outputType = outputType;
this.values = values;
}
}
+10 -16
View File
@@ -1,4 +1,6 @@
import { Multiplicity } from '../enums/Multiplicity';
import { type FieldStatus } from '../enums/FieldStatus';
import { type FieldType } from '../enums/FieldType';
import { type Multiplicity } from '../enums/Multiplicity';
import { Field } from './Field';
import { type ListValue } from './ListValue';
@@ -26,37 +28,29 @@ export class ListField extends Field {
* @param {number} id - The id of the list field.
* @param {number} appId - The id of the app the list field belongs to.
* @param {string} name - The name of the list field.
* @param {string} type - The type of the list field.
* @param {string} status - The status of the list field.
* @param {FieldType} type - The type of the list field.
* @param {FieldStatus} status - The status of the list field.
* @param {boolean} isRequired - Whether the list field is required.
* @param {boolean} isUnique - Whether the list field is unique.
* @param {string} multiplicity - The multiplicity of the list field.
* @param {Multiplicity} multiplicity - The multiplicity of the list field.
* @param {number} listId - The id of the list the list field belongs to.
* @param {ListValue[]} values - The list values of the list field.
* @returns {ListField} - A new ListField.
* @throws {Error} - Throws an error if the multiplicity is not a valid Multiplicity.
*/
constructor(
id: number,
appId: number,
name: string,
type: string,
status: string,
type: FieldType,
status: FieldStatus,
isRequired: boolean,
isUnique: boolean,
multiplicity: string,
multiplicity: Multiplicity,
listId: number,
values: ListValue[]
) {
super(id, appId, name, type, status, isRequired, isUnique);
if (Multiplicity[multiplicity] === undefined) {
throw new Error(
`The multiplicity ${multiplicity} is not a valid Multiplicity.`
);
}
this.multiplicity = Multiplicity[multiplicity];
this.multiplicity = multiplicity;
this.listId = listId;
this.values = values;
}
+1 -1
View File
@@ -23,7 +23,7 @@ export class ListValue {
public numericValue: number;
/**
*
* @property {string} color - The color of the list value.
*/
public color: string;
+2 -2
View File
@@ -7,12 +7,12 @@ export class PagingRequest {
/**
* @property {number} pageNumber - The page number of the request.
*/
pageNumber: number;
public pageNumber: number;
/**
* @property {number} pageSize - The page size of the request.
*/
pageSize: number;
public pageSize: number;
/**
* @constructor - Creates a new instance of the PagingRequest class.
+38
View File
@@ -0,0 +1,38 @@
import { type RecordValue } from './RecordValue';
/**
* @class Record - A record in an app.
*/
export class Record {
/**
* @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 {Array<RecordValue<any>>} fieldData - The data for the fields in the record.
*/
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 {Array<RecordValue<any>>} fieldData - The data for the fields in the record.
* @returns {Record} - A new instance of Record.
*/
constructor(
appId: number,
recordId: number,
fieldData: Array<RecordValue<any>>
) {
this.appId = appId;
this.recordId = recordId;
this.fieldData = fieldData;
}
}
+34
View File
@@ -0,0 +1,34 @@
import { type RecordValueType } from '../enums/RecordValueType';
/**
* @class RecordValue - A value for a field in a record.
*/
export class RecordValue<T> {
/**
* @property {RecordValueType} type - The type of the record value.
*/
public type: RecordValueType;
/**
* @property {number} fieldId - The id of the field.
*/
public fieldId: number;
/**
* @property {T} value - The value of the field.
*/
public value: T;
/**
* @constructor - Creates a new instance of RecordValue.
* @param {RecordValueType} type - The type of the record value.
* @param {number} fieldId - The id of the field.
* @param {T} value - The value of the field.
* @returns {RecordValue} - A new instance of RecordValue.
*/
constructor(type: RecordValueType, fieldId: number, value: T) {
this.type = type;
this.fieldId = fieldId;
this.value = value;
}
}
+10 -16
View File
@@ -1,4 +1,6 @@
import { Multiplicity } from '../enums/Multiplicity';
import { type FieldStatus } from '../enums/FieldStatus';
import { type FieldType } from '../enums/FieldType';
import { type Multiplicity } from '../enums/Multiplicity';
import { Field } from './Field';
/**
@@ -20,35 +22,27 @@ export class ReferenceField extends Field {
* @param {number} id - The id of the reference field.
* @param {number} appId - The id of the app the reference field belongs to.
* @param {string} name - The name of the reference field.
* @param {string} type - The type of the reference field.
* @param {string} status - The status of the reference field.
* @param {FieldType} type - The type of the reference field.
* @param {FieldStatus} status - The status of the reference field.
* @param {boolean} isRequired - Whether the reference field is required.
* @param {boolean} isUnique - Whether the reference field is unique.
* @param {string} multiplicity - The multiplicity of the reference field.
* @param {Multiplicity} multiplicity - The multiplicity of the reference field.
* @param {number} referencedAppId - The id of the app the reference field references.
* @returns {ReferenceField} - A new ReferenceField.
* @throws {Error} - Throws an error if the multiplicity is not a valid Multiplicity.jjkdleroritlasaxmvjd
*/
constructor(
id: number,
appId: number,
name: string,
type: string,
status: string,
type: FieldType,
status: FieldStatus,
isRequired: boolean,
isUnique: boolean,
multiplicity: string,
multiplicity: Multiplicity,
referencedAppId: number
) {
super(id, appId, name, type, status, isRequired, isUnique);
if (Multiplicity[multiplicity] === undefined) {
throw new Error(
`The multiplicity ${multiplicity} is not a valid Multiplicity.`
);
}
this.multiplicity = Multiplicity[multiplicity];
this.multiplicity = multiplicity;
this.referencedAppId = referencedAppId;
}
}
+18 -2
View File
@@ -1,8 +1,24 @@
/**
* @class Row - Represents a row of data in a report.
*/
export class Row {
/**
* @property {number} recordId - The id of the record that the row represents.
*/
public recordId: number;
public cells: object[];
constructor(recordId: number, cells: object[]) {
/**
* @property {any[]} cells - The cells in the row.
*/
public cells: any[];
/**
* @constructor - Creates a new instance of Row.
* @param {number} recordId - The id of the record that the row represents.
* @param {any[]} cells - The cells in the row.
* @returns {Row} - A new instance of Row.
*/
constructor(recordId: number, cells: any[]) {
this.recordId = recordId;
this.cells = cells;
}
+44
View File
@@ -0,0 +1,44 @@
/**
* @class ScoringGroup - A class that represents a scoring group.
*/
export class ScoringGroup {
/**
* @property {string} listValueId - The id of the list value.
*/
public listValueId: string;
/**
* @property {string} name - The name of the scoring group.
*/
public name: string;
/**
* @property {number} score - The score of the scoring group.
*/
public score: number;
/**
* @property {number} maximumScore - The maximum score of the scoring group.
*/
public maximumScore: number;
/**
* @constructor - Creates a new instance of ScoringGroup.
* @param {string} listValueId - The id of the list value.
* @param {string} name - The name of the scoring group.
* @param {number} score - The score of the scoring group.
* @param {number} maximumScore - The maximum score of the scoring group.
* @returns {ScoringGroup} - A new instance of ScoringGroup.
*/
constructor(
listValueId: string,
name: string,
score: number,
maximumScore: number
) {
this.listValueId = listValueId;
this.name = name;
this.score = score;
this.maximumScore = maximumScore;
}
}
+49
View File
@@ -0,0 +1,49 @@
import { type TimeSpanIncrement } from '../enums/TimeSpanIncrement';
import { type TimeSpanRecurrenceType } from '../enums/TimeSpanRecurrenceType';
export class TimeSpanData {
/**
* @property {number} quantity - The quantity of the time span.
*/
public quantity: number;
/**
* @property {TimeSpanIncrement} increment - The increment of the time span.
*/
public increment: TimeSpanIncrement;
/**
* @property {TimeSpanRecurrence} recurrence - The recurrence of the time span.
*/
public recurrence: TimeSpanRecurrenceType;
/**
* @property {number} endAfterOccurrences - The number of occurrences of the time span.
*/
public endAfterOccurrences: number;
public endByDate: Date;
/**
* @constructor - Creates a new instance of TimeSpanData.
* @param {number} quantity - The quantity of the time span.
* @param {TimeSpanIncrement} increment - The increment of the time span.
* @param {TimeSpanRecurrenceType} recurrence - The recurrence of the time span.
* @param {number} endAfterOccurrences - The number of occurrences of the time span.
* @param {Date} endByDate - The end date of the time span.
* @returns {TimeSpanData} - A new instance of TimeSpanData.
*/
constructor(
quantity: number,
increment: TimeSpanIncrement,
recurrence: TimeSpanRecurrenceType,
endAfterOccurrences: number,
endByDate: Date
) {
this.quantity = quantity;
this.increment = increment;
this.recurrence = recurrence;
this.endAfterOccurrences = endAfterOccurrences;
this.endByDate = endByDate;
}
}