Files
onspring-api-sdk-javascript/src/models/Field.ts
T

82 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-02-02 21:37:40 -06:00
import { FieldStatus } from '../enums/FieldStatus';
import { FieldType } from '../enums/FieldType';
2023-02-02 22:52:14 -06:00
/**
* @class Field - Represents a Field.
*/
2023-02-02 21:37:40 -06:00
export class Field {
2023-02-02 22:52:14 -06:00
/**
* @property {number} id - The id of the Field.
*/
2023-02-02 21:37:40 -06:00
public id: number;
2023-02-02 22:52:14 -06:00
/**
* @property {number} appId - The id of the App that the Field belongs to.
*/
2023-02-02 21:37:40 -06:00
public appId: number;
2023-02-02 22:52:14 -06:00
/**
* @property {number} name - The name of the Field.
*/
2023-02-02 21:37:40 -06:00
public name: string;
2023-02-02 22:52:14 -06:00
/**
* @property {FieldType} type - The type of the Field.
*/
2023-02-02 21:37:40 -06:00
public type: FieldType;
2023-02-02 22:52:14 -06:00
/**
* @property {FieldStatus} status - The status of the Field.
*/
2023-02-02 21:37:40 -06:00
public status: FieldStatus;
2023-02-02 22:52:14 -06:00
/**
* @property {boolean} isRequired - Indicates whether or not the Field is required.
*/
2023-02-02 21:37:40 -06:00
public isRequired: boolean;
2023-02-02 22:52:14 -06:00
/**
* @property {boolean} isUnique - Indicates whether or not the Field is required to be unique.
*/
2023-02-02 21:37:40 -06:00
public isUnique: boolean;
2023-02-02 22:52:14 -06:00
/**
* @constructor - Creates a new 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 {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.
*/
2023-02-02 21:37:40 -06:00
public constructor(
id: number,
appId: number,
name: string,
type: string,
status: string,
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.isRequired = isRequired;
this.isUnique = isUnique;
}
}