UNPKG

@zohocrm/nodejs-sdk-2.0

Version:
122 lines (110 loc) 5.13 kB
const Header = require("../../../../../../routes/header").MasterModel; const HeaderMap = require("../../../../../../routes/header_map").MasterModel; const APIResponse = require("../../../../../../routes/controllers/api_response").MasterModel; const CommonAPIHandler = require("../../../../../../routes/middlewares/common_api_handler").MasterModel; const Constants = require("../../../../../../utils/util/constants").MasterModel; const SDKException = require("../exception/sdk_exception").MasterModel; class ModulesOperations{ /** * The method to get modules * @param {HeaderMap} headerInstance An instance of HeaderMap * @returns {APIResponse} An instance of APIResponse * @throws {SDKException} */ async getModules(headerInstance=null) { if((headerInstance != null) && (!(headerInstance instanceof HeaderMap))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: headerInstance EXPECTED TYPE: HeaderMap", null, null); } var handlerInstance = new CommonAPIHandler(); var apiPath = ''; apiPath = apiPath.concat("/crm/v2/settings/modules"); handlerInstance.setAPIPath(apiPath); handlerInstance.setHttpMethod(Constants.REQUEST_METHOD_GET); handlerInstance.setCategoryMethod(Constants.REQUEST_CATEGORY_READ); handlerInstance.setHeader(headerInstance); let ResponseHandler = require.resolve("./response_handler"); return handlerInstance.apiCall(ResponseHandler, "application/json"); } /** * The method to get module * @param {String} apiName A String representing the apiName * @returns {APIResponse} An instance of APIResponse * @throws {SDKException} */ async getModule(apiName) { if((!(Object.prototype.toString.call(apiName) == "[object String]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: apiName EXPECTED TYPE: String", null, null); } var handlerInstance = new CommonAPIHandler(); var apiPath = ''; apiPath = apiPath.concat("/crm/v2/settings/modules/"); apiPath = apiPath.concat(apiName.toString()); handlerInstance.setAPIPath(apiPath); handlerInstance.setHttpMethod(Constants.REQUEST_METHOD_GET); handlerInstance.setCategoryMethod(Constants.REQUEST_CATEGORY_READ); let ResponseHandler = require.resolve("./response_handler"); return handlerInstance.apiCall(ResponseHandler, "application/json"); } /** * The method to update module by api name * @param {String} apiName A String representing the apiName * @param {BodyWrapper} request An instance of BodyWrapper * @returns {APIResponse} An instance of APIResponse * @throws {SDKException} */ async updateModuleByAPIName(apiName, request) { const BodyWrapper = require("./body_wrapper").MasterModel; if((!(Object.prototype.toString.call(apiName) == "[object String]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: apiName EXPECTED TYPE: String", null, null); } if((request != null) && (!(request instanceof BodyWrapper))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: request EXPECTED TYPE: BodyWrapper", null, null); } var handlerInstance = new CommonAPIHandler(); var apiPath = ''; apiPath = apiPath.concat("/crm/v2/settings/modules/"); apiPath = apiPath.concat(apiName.toString()); handlerInstance.setAPIPath(apiPath); handlerInstance.setHttpMethod(Constants.REQUEST_METHOD_PUT); handlerInstance.setCategoryMethod(Constants.REQUEST_CATEGORY_UPDATE); handlerInstance.setContentType("application/json"); handlerInstance.setRequest(request); let ActionHandler = require.resolve("./action_handler"); return handlerInstance.apiCall(ActionHandler, "application/json"); } /** * The method to update module by id * @param {BigInt} id A BigInt representing the id * @param {BodyWrapper} request An instance of BodyWrapper * @returns {APIResponse} An instance of APIResponse * @throws {SDKException} */ async updateModuleById(id, request) { const BodyWrapper = require("./body_wrapper").MasterModel; if((!(Object.prototype.toString.call(id) == "[object BigInt]"))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: id EXPECTED TYPE: BigInt", null, null); } if((request != null) && (!(request instanceof BodyWrapper))) { throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: request EXPECTED TYPE: BodyWrapper", null, null); } var handlerInstance = new CommonAPIHandler(); var apiPath = ''; apiPath = apiPath.concat("/crm/v2/settings/modules/"); apiPath = apiPath.concat(id.toString()); handlerInstance.setAPIPath(apiPath); handlerInstance.setHttpMethod(Constants.REQUEST_METHOD_PUT); handlerInstance.setCategoryMethod(Constants.REQUEST_CATEGORY_UPDATE); handlerInstance.setContentType("application/json"); handlerInstance.setRequest(request); let ActionHandler = require.resolve("./action_handler"); return handlerInstance.apiCall(ActionHandler, "application/json"); } } class GetModulesHeader{ static IF_MODIFIED_SINCE = new Header("If-Modified-Since", "com.zoho.crm.api.Modules.GetModulesHeader"); } module.exports = { MasterModel : ModulesOperations, ModulesOperations : ModulesOperations, GetModulesHeader : GetModulesHeader }