UNPKG

@tuanltntu/n8n-nodes-bitrix24

Version:

Comprehensive n8n community node for Bitrix24 API integration with CRM, Tasks, Chat, Telephony, and more

126 lines 5.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserResourceHandler = void 0; const n8n_workflow_1 = require("n8n-workflow"); const ResourceHandlerBase_1 = require("./ResourceHandlerBase"); /** * Xử lý các tác vụ User của Bitrix24 */ class UserResourceHandler extends ResourceHandlerBase_1.ResourceHandlerBase { constructor(executeFunctions, returnData, options = {}) { super(executeFunctions, returnData, options); this.resourceEndpoints = { get: "user.get", getAll: "user.get", getCurrent: "user.current", }; } /** * Xử lý tác vụ User */ async process() { for (let i = 0; i < this.items.length; i++) { try { const operation = this.getNodeParameter("operation", i); switch (operation) { case "get": await this.handleGet(i); break; case "getAll": await this.handleGetAll(i); break; case "getCurrent": await this.handleGetCurrent(i); break; default: throw new n8n_workflow_1.NodeOperationError(this.executeFunctions.getNode(), `Không hỗ trợ tác vụ "${operation}" cho User`, { itemIndex: i }); } } catch (error) { if (this.executeFunctions.continueOnFail()) { this.returnData.push({ json: { error: error.message } }); continue; } throw error; } } return this.returnData; } /** * Xử lý tham số tùy chỉnh */ processCustomParameters(options, params, itemIndex) { if (!options.customParameters) return; try { const customParams = typeof options.customParameters === "string" ? this.parseJsonParameter(options.customParameters, "Custom parameters phải là JSON hợp lệ", itemIndex) : options.customParameters; Object.assign(params, customParams); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.executeFunctions.getNode(), "Custom parameters phải là JSON hợp lệ", { itemIndex }); } } /** * Xử lý 'get' */ async handleGet(itemIndex) { const userId = this.getNodeParameter("userId", itemIndex); const options = this.getNodeParameter("options", itemIndex, {}); const queryParams = { ID: userId }; if (options.customParameters) { try { const customParams = this.parseJsonParameter(options.customParameters, 'JSON không hợp lệ trong trường "Custom Parameters"', itemIndex); Object.assign(queryParams, customParams); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.executeFunctions.getNode(), 'JSON không hợp lệ trong trường "Custom Parameters"', { itemIndex }); } } const responseData = await this.makeApiCall(this.resourceEndpoints.get, {}, queryParams, itemIndex); this.addResponseToReturnData(responseData, itemIndex); } /** * Xử lý 'getAll' */ async handleGetAll(itemIndex) { const returnAll = this.getNodeParameter("returnAll", itemIndex, false); const options = this.getNodeParameter("options", itemIndex, {}); const qs = {}; if (options.filter) { qs.FILTER = options.filter; } if (options.order) { qs.ORDER = options.order; } if (options.adminMode) { qs.ADMIN_MODE = options.adminMode ? "Y" : "N"; } // Xử lý custom parameters if (options.customParameters) { try { const customParams = this.parseJsonParameter(options.customParameters, 'JSON không hợp lệ trong trường "Custom Parameters"', itemIndex); Object.assign(qs, customParams); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.executeFunctions.getNode(), 'JSON không hợp lệ trong trường "Custom Parameters"', { itemIndex }); } } // Đặt giá trị mặc định cho start để đảm bảo phân trang hoạt động đúng if (!returnAll) { qs.start = -1; } const responseData = await this.makeApiCall(this.resourceEndpoints.get, {}, qs, itemIndex, returnAll); this.addResponseToReturnData(responseData, itemIndex); } /** * Xử lý 'getCurrent' */ async handleGetCurrent(itemIndex) { const responseData = await this.makeApiCall(this.resourceEndpoints.getCurrent, {}, {}, itemIndex); this.addResponseToReturnData(responseData, itemIndex); } } exports.UserResourceHandler = UserResourceHandler; //# sourceMappingURL=UserResourceHandler.js.map