zcrmsdk
Version:
Node JS SDK for Zoho CRM
226 lines (187 loc) • 6.11 kB
JavaScript
const Constants = require("../../../../../../utils/util/constants").MasterModel;
const SDKException = require("../exception/sdk_exception").MasterModel;
class Record{
keyValues = new Map();
keyModified = new Map();
/**
* The method to get the id
* @returns {BigInt} A BigInt representing the id
*/
getId() {
return this.getKeyValue("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.addKeyValue("id", id);
}
/**
* The method to get the createdBy
* @returns {User} An instance of User
*/
getCreatedBy() {
return this.getKeyValue("Created_By");
}
/**
* The method to set the value to createdBy
* @param {User} createdBy An instance of User
*/
setCreatedBy(createdBy) {
const User = require("../users/user").MasterModel;
if((createdBy != null) && (!(createdBy instanceof User))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: createdBy EXPECTED TYPE: User", null, null);
}
this.addKeyValue("Created_By", createdBy);
}
/**
* The method to get the createdTime
* @returns {Date} An instance of Date
*/
getCreatedTime() {
return this.getKeyValue("Created_Time");
}
/**
* The method to set the value to createdTime
* @param {Date} createdTime An instance of Date
*/
setCreatedTime(createdTime) {
if((createdTime != null) && (!(createdTime instanceof Date))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: createdTime EXPECTED TYPE: Date", null, null);
}
this.addKeyValue("Created_Time", createdTime);
}
/**
* The method to get the modifiedBy
* @returns {User} An instance of User
*/
getModifiedBy() {
return this.getKeyValue("Modified_By");
}
/**
* The method to set the value to modifiedBy
* @param {User} modifiedBy An instance of User
*/
setModifiedBy(modifiedBy) {
const User = require("../users/user").MasterModel;
if((modifiedBy != null) && (!(modifiedBy instanceof User))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: modifiedBy EXPECTED TYPE: User", null, null);
}
this.addKeyValue("Modified_By", modifiedBy);
}
/**
* The method to get the modifiedTime
* @returns {Date} An instance of Date
*/
getModifiedTime() {
return this.getKeyValue("Modified_Time");
}
/**
* The method to set the value to modifiedTime
* @param {Date} modifiedTime An instance of Date
*/
setModifiedTime(modifiedTime) {
if((modifiedTime != null) && (!(modifiedTime instanceof Date))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: modifiedTime EXPECTED TYPE: Date", null, null);
}
this.addKeyValue("Modified_Time", modifiedTime);
}
/**
* The method to get the tag
* @returns {Array} An Array representing the tag
*/
getTag() {
return this.getKeyValue("Tag");
}
/**
* The method to set the value to tag
* @param {Array} tag An Array representing the tag
*/
setTag(tag) {
if((tag != null) && (!(Object.prototype.toString.call(tag) == "[object Array]"))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: tag EXPECTED TYPE: Array", null, null);
}
this.addKeyValue("Tag", tag);
}
/**
* The method to add field value
* @param {Field} field An instance of Field
* @param {*} value An object
*/
addFieldValue(field, value) {
const Field = require("./field").MasterModel;
if((field != null) && (!(field instanceof Field))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: field EXPECTED TYPE: Field", null, null);
}
this.addKeyValue(field.getAPIName(), value);
}
/**
* The method to add key value
* @param {String} apiName A String representing the apiName
* @param {Object} value An Object representing the value
*/
addKeyValue(apiName, value) {
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.keyValues.set(apiName, value);
this.keyModified.set(apiName, 1);
}
/**
* The method to get key value
* @param {String} apiName A String representing the apiName
* @returns {Object} An Object representing the keyValue
*/
getKeyValue(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);
}
if(this.keyValues.has(apiName)) {
return this.keyValues.get(apiName);
}
return null;
}
/**
* The method to get key values
* @returns {Map} A Map representing the keyValues
*/
getKeyValues() {
return this.keyValues;
}
/**
* 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 : Record,
Record : Record
}