@zohocrm/typescript-sdk-7.0
Version:
TypeScript SDK for Zoho CRM
103 lines (102 loc) • 4.54 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParameterMap = exports.MasterModel = void 0;
const header_param_validator_1 = require("../utils/util/header_param_validator");
const sdk_exception_1 = require("../core/com/zoho/crm/api/exception/sdk_exception");
const constants_1 = require("../utils/util/constants");
const Logger = __importStar(require("winston"));
const datatype_converter_1 = require("../utils/util/datatype_converter");
/**
* This class represents the HTTP parameter name and value.
*/
class ParameterMap {
constructor() {
this.parameterMap = new Map();
}
/**
* This is a getter method to get parameter map.
* @returns {Map} A Map representing the API request parameters.
*/
getParameterMap() {
return this.parameterMap;
}
/**
* The method to add parameter name and value.
* @param {Param} param - A Param class instance.
* @param {object} value - An object containing the parameter value.
* @throws {SDKException}
*/
async add(param, value) {
if (param == null || param == undefined) {
throw new sdk_exception_1.SDKException(constants_1.Constants.PARAMETER_NULL_ERROR, constants_1.Constants.PARAM_INSTANCE_NULL_ERROR);
}
let paramName = param.getName();
if (paramName == null || paramName == undefined) {
throw new sdk_exception_1.SDKException(constants_1.Constants.PARAM_NAME_NULL_ERROR, constants_1.Constants.PARAM_NAME_NULL_ERROR_MESSAGE);
}
if (value == null) {
throw new sdk_exception_1.SDKException(constants_1.Constants.PARAMETER_NULL_ERROR, paramName + constants_1.Constants.NULL_VALUE_ERROR_MESSAGE);
}
try {
let paramClassName = param.getClassName();
let parsedParamValue;
if (paramClassName !== undefined && paramClassName !== null) {
parsedParamValue = await new header_param_validator_1.HeaderParamValidator().validate(paramName, paramClassName, value).catch(err => { throw err; });
}
else {
try {
let type = Object.prototype.toString.call(value);
parsedParamValue = await datatype_converter_1.DatatypeConverter.postConvert(value, type.toLowerCase());
}
catch (err) {
parsedParamValue = value;
}
}
if (parsedParamValue === true || parsedParamValue === false) {
parsedParamValue = JSON.stringify(parsedParamValue);
}
if (this.parameterMap.has(paramName) && this.parameterMap.get(paramName) != null) {
let paramValue = this.parameterMap.get(paramName);
if (paramValue !== undefined) {
paramValue = paramValue.concat(",", parsedParamValue.toString());
this.parameterMap.set(paramName, paramValue);
}
}
else {
this.parameterMap.set(paramName, parsedParamValue.toString());
}
}
catch (error) {
if (!(error instanceof sdk_exception_1.SDKException)) {
error = new sdk_exception_1.SDKException(null, null, null, error);
}
Logger.error(constants_1.Constants.PARAM_EXCEPTION, error);
throw error;
}
}
}
exports.MasterModel = ParameterMap;
exports.ParameterMap = ParameterMap;
;