UNPKG

@zohocrm/nodejs-sdk-2.0

Version:
203 lines (168 loc) 5.2 kB
const Constants = require("../../../../../../utils/util/constants").MasterModel; const SDKException = require("../exception/sdk_exception").MasterModel; class Variable{ apiName; name; description; id; type; variableGroup; value; keyModified = new Map(); /** * The method to get the apiName * @returns {String} A String representing the apiName */ getAPIName() { return this.apiName; } /** * The method to set the value to apiName * @param {String} apiName A String representing the apiName */ setAPIName(apiName) { if((apiName != null) && (!(Object.prototype.toString.call(apiName) == "[object String]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: apiName EXPECTED TYPE: String", null, null); } this.apiName = apiName; this.keyModified.set("api_name", 1); } /** * The method to get the name * @returns {String} A String representing the name */ getName() { return this.name; } /** * The method to set the value to name * @param {String} name A String representing the name */ setName(name) { if((name != null) && (!(Object.prototype.toString.call(name) == "[object String]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: name EXPECTED TYPE: String", null, null); } this.name = name; this.keyModified.set("name", 1); } /** * The method to get the description * @returns {String} A String representing the description */ getDescription() { return this.description; } /** * The method to set the value to description * @param {String} description A String representing the description */ setDescription(description) { if((description != null) && (!(Object.prototype.toString.call(description) == "[object String]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: description EXPECTED TYPE: String", null, null); } this.description = description; this.keyModified.set("description", 1); } /** * The method to get the id * @returns {BigInt} A BigInt representing the id */ getId() { return this.id; } /** * The method to set the value to id * @param {BigInt} id A BigInt representing the id */ setId(id) { if((id != null) && (!(Object.prototype.toString.call(id) == "[object BigInt]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: id EXPECTED TYPE: BigInt", null, null); } this.id = id; this.keyModified.set("id", 1); } /** * The method to get the type * @returns {String} A String representing the type */ getType() { return this.type; } /** * The method to set the value to type * @param {String} type A String representing the type */ setType(type) { if((type != null) && (!(Object.prototype.toString.call(type) == "[object String]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: type EXPECTED TYPE: String", null, null); } this.type = type; this.keyModified.set("type", 1); } /** * The method to get the variableGroup * @returns {VariableGroup} An instance of VariableGroup */ getVariableGroup() { return this.variableGroup; } /** * The method to set the value to variableGroup * @param {VariableGroup} variableGroup An instance of VariableGroup */ setVariableGroup(variableGroup) { const VariableGroup = require("../variable_groups/variable_group").MasterModel; if((variableGroup != null) && (!(variableGroup instanceof VariableGroup))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: variableGroup EXPECTED TYPE: VariableGroup", null, null); } this.variableGroup = variableGroup; this.keyModified.set("variable_group", 1); } /** * The method to get the value * @returns {Object} An Object representing the value */ getValue() { return this.value; } /** * The method to set the value to value * @param {Object} value An Object representing the value */ setValue(value) { this.value = value; this.keyModified.set("value", 1); } /** * The method to check if the user has modified the given key * @param {String} key A String representing the key * @returns {number} A number representing the modification */ isKeyModified(key) { if((key != null) && (!(Object.prototype.toString.call(key) == "[object String]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: key EXPECTED TYPE: String", null, null); } if(this.keyModified.has(key)) { return this.keyModified.get(key); } return null; } /** * The method to mark the given key as modified * @param {String} key A String representing the key * @param {number} modification A number representing the modification */ setKeyModified(key, modification) { if((key != null) && (!(Object.prototype.toString.call(key) == "[object String]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: key EXPECTED TYPE: String", null, null); } if((modification != null) && (!(Object.prototype.toString.call(modification) == "[object Number]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: modification EXPECTED TYPE: number", null, null); } this.keyModified.set(key, modification); } } module.exports = { MasterModel : Variable, Variable : Variable }