@zohocrm/nodejs-sdk-2.0
Version:
Node JS SDK for Zoho CRM
214 lines (191 loc) • 8.73 kB
JavaScript
const Param = require("../../../../../../routes/param").MasterModel;
const ParameterMap = require("../../../../../../routes/parameter_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 AttachmentsOperations{
recordId;
moduleAPIName;
/**
* Creates an instance of AttachmentsOperations with the given parameters
* @param {String} moduleAPIName A String representing the moduleAPIName
* @param {BigInt} recordId A BigInt representing the recordId
*/
constructor(moduleAPIName, recordId){
if((!(Object.prototype.toString.call(moduleAPIName) == "[object String]"))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: moduleAPIName EXPECTED TYPE: String", null, null);
}
if((!(Object.prototype.toString.call(recordId) == "[object BigInt]"))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: recordId EXPECTED TYPE: BigInt", null, null);
}
this.moduleAPIName = moduleAPIName;
this.recordId = recordId;
}
/**
* The method to download attachment
* @param {BigInt} id A BigInt representing the id
* @returns {APIResponse} An instance of APIResponse
* @throws {SDKException}
*/
async downloadAttachment(id) {
if((!(Object.prototype.toString.call(id) == "[object BigInt]"))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: id EXPECTED TYPE: BigInt", null, null);
}
var handlerInstance = new CommonAPIHandler();
var apiPath = '';
apiPath = apiPath.concat("/crm/v2/");
apiPath = apiPath.concat(this.moduleAPIName.toString());
apiPath = apiPath.concat("/");
apiPath = apiPath.concat(this.recordId.toString());
apiPath = apiPath.concat("/Attachments/");
apiPath = apiPath.concat(id.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/x-download");
}
/**
* The method to delete attachment
* @param {BigInt} id A BigInt representing the id
* @returns {APIResponse} An instance of APIResponse
* @throws {SDKException}
*/
async deleteAttachment(id) {
if((!(Object.prototype.toString.call(id) == "[object BigInt]"))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: id EXPECTED TYPE: BigInt", null, null);
}
var handlerInstance = new CommonAPIHandler();
var apiPath = '';
apiPath = apiPath.concat("/crm/v2/");
apiPath = apiPath.concat(this.moduleAPIName.toString());
apiPath = apiPath.concat("/");
apiPath = apiPath.concat(this.recordId.toString());
apiPath = apiPath.concat("/Attachments/");
apiPath = apiPath.concat(id.toString());
handlerInstance.setAPIPath(apiPath);
handlerInstance.setHttpMethod(Constants.REQUEST_METHOD_DELETE);
handlerInstance.setCategoryMethod(Constants.REQUEST_METHOD_DELETE);
let ActionHandler = require.resolve("./action_handler");
return handlerInstance.apiCall(ActionHandler, "application/json");
}
/**
* The method to get attachments
* @param {ParameterMap} paramInstance An instance of ParameterMap
* @returns {APIResponse} An instance of APIResponse
* @throws {SDKException}
*/
async getAttachments(paramInstance=null) {
if((paramInstance != null) && (!(paramInstance instanceof ParameterMap))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: paramInstance EXPECTED TYPE: ParameterMap", null, null);
}
var handlerInstance = new CommonAPIHandler();
var apiPath = '';
apiPath = apiPath.concat("/crm/v2/");
apiPath = apiPath.concat(this.moduleAPIName.toString());
apiPath = apiPath.concat("/");
apiPath = apiPath.concat(this.recordId.toString());
apiPath = apiPath.concat("/Attachments");
handlerInstance.setAPIPath(apiPath);
handlerInstance.setHttpMethod(Constants.REQUEST_METHOD_GET);
handlerInstance.setCategoryMethod(Constants.REQUEST_CATEGORY_READ);
handlerInstance.setParam(paramInstance);
let ResponseHandler = require.resolve("./response_handler");
return handlerInstance.apiCall(ResponseHandler, "application/json");
}
/**
* The method to upload attachment
* @param {FileBodyWrapper} request An instance of FileBodyWrapper
* @returns {APIResponse} An instance of APIResponse
* @throws {SDKException}
*/
async uploadAttachment(request) {
const FileBodyWrapper = require("./file_body_wrapper").MasterModel;
if((request != null) && (!(request instanceof FileBodyWrapper))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: request EXPECTED TYPE: FileBodyWrapper", null, null);
}
var handlerInstance = new CommonAPIHandler();
var apiPath = '';
apiPath = apiPath.concat("/crm/v2/");
apiPath = apiPath.concat(this.moduleAPIName.toString());
apiPath = apiPath.concat("/");
apiPath = apiPath.concat(this.recordId.toString());
apiPath = apiPath.concat("/Attachments");
handlerInstance.setAPIPath(apiPath);
handlerInstance.setHttpMethod(Constants.REQUEST_METHOD_POST);
handlerInstance.setCategoryMethod(Constants.REQUEST_CATEGORY_CREATE);
handlerInstance.setContentType("multipart/form-data");
handlerInstance.setRequest(request);
handlerInstance.setMandatoryChecker(true);
let ActionHandler = require.resolve("./action_handler");
return handlerInstance.apiCall(ActionHandler, "application/json");
}
/**
* The method to upload link attachment
* @param {ParameterMap} paramInstance An instance of ParameterMap
* @returns {APIResponse} An instance of APIResponse
* @throws {SDKException}
*/
async uploadLinkAttachment(paramInstance=null) {
if((paramInstance != null) && (!(paramInstance instanceof ParameterMap))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: paramInstance EXPECTED TYPE: ParameterMap", null, null);
}
var handlerInstance = new CommonAPIHandler();
var apiPath = '';
apiPath = apiPath.concat("/crm/v2/");
apiPath = apiPath.concat(this.moduleAPIName.toString());
apiPath = apiPath.concat("/");
apiPath = apiPath.concat(this.recordId.toString());
apiPath = apiPath.concat("/Attachments");
handlerInstance.setAPIPath(apiPath);
handlerInstance.setHttpMethod(Constants.REQUEST_METHOD_POST);
handlerInstance.setCategoryMethod(Constants.REQUEST_CATEGORY_CREATE);
handlerInstance.setMandatoryChecker(true);
handlerInstance.setParam(paramInstance);
let ActionHandler = require.resolve("./action_handler");
return handlerInstance.apiCall(ActionHandler, "application/json");
}
/**
* The method to delete attachments
* @param {ParameterMap} paramInstance An instance of ParameterMap
* @returns {APIResponse} An instance of APIResponse
* @throws {SDKException}
*/
async deleteAttachments(paramInstance=null) {
if((paramInstance != null) && (!(paramInstance instanceof ParameterMap))) {
throw new SDKException(Constants.DATA_TYPE_ERROR, "KEY: paramInstance EXPECTED TYPE: ParameterMap", null, null);
}
var handlerInstance = new CommonAPIHandler();
var apiPath = '';
apiPath = apiPath.concat("/crm/v2/");
apiPath = apiPath.concat(this.moduleAPIName.toString());
apiPath = apiPath.concat("/");
apiPath = apiPath.concat(this.recordId.toString());
apiPath = apiPath.concat("/Attachments");
handlerInstance.setAPIPath(apiPath);
handlerInstance.setHttpMethod(Constants.REQUEST_METHOD_DELETE);
handlerInstance.setCategoryMethod(Constants.REQUEST_METHOD_DELETE);
handlerInstance.setParam(paramInstance);
let ActionHandler = require.resolve("./action_handler");
return handlerInstance.apiCall(ActionHandler, "application/json");
}
}
class GetAttachmentsParam{
static FIELDS = new Param("fields", "com.zoho.crm.api.Attachments.GetAttachmentsParam");
static PAGE = new Param("page", "com.zoho.crm.api.Attachments.GetAttachmentsParam");
static PER_PAGE = new Param("per_page", "com.zoho.crm.api.Attachments.GetAttachmentsParam");
}
class UploadLinkAttachmentParam{
static ATTACHMENTURL = new Param("attachmentUrl", "com.zoho.crm.api.Attachments.UploadLinkAttachmentParam");
}
class DeleteAttachmentsParam{
static IDS = new Param("ids", "com.zoho.crm.api.Attachments.DeleteAttachmentsParam");
}
module.exports = {
MasterModel : AttachmentsOperations,
AttachmentsOperations : AttachmentsOperations,
DeleteAttachmentsParam : DeleteAttachmentsParam,
UploadLinkAttachmentParam : UploadLinkAttachmentParam,
GetAttachmentsParam : GetAttachmentsParam
}