UNPKG

n8n-nodes-netbox

Version:

n8n community node for NetBox API integration with comprehensive DCIM, IPAM, Virtualization, Circuits, Wireless, and data center management operations

130 lines (129 loc) 4.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listModuleBays = listModuleBays; exports.getModuleBay = getModuleBay; exports.createModuleBay = createModuleBay; exports.updateModuleBay = updateModuleBay; exports.deleteModuleBay = deleteModuleBay; const apiRequest_1 = require("../../../helpers/apiRequest"); const responseFormatter_1 = require("../../../helpers/responseFormatter"); async function listModuleBays() { try { // Get pagination parameters const returnAll = this.getNodeParameter('returnAll', 0); // Get filters - this will include all the advanced filter fields const filters = this.getNodeParameter('filters', 0, {}); // Prepare query parameters const queryParams = { ...filters }; let responseData; if (returnAll) { // Add higher limit to the first query when listing module bays if (!queryParams.limit) { queryParams.limit = 500; // Higher limit for faster pagination } responseData = await apiRequest_1.apiRequestAllItems.call(this, 'GET', '/api/dcim/module-bays/', {}, queryParams); } else { const limit = this.getNodeParameter('limit', 0); queryParams.limit = limit; const response = await apiRequest_1.apiRequest.call(this, 'GET', '/api/dcim/module-bays/', {}, queryParams); responseData = response.results || response; } return responseFormatter_1.formatResponse.call(this, responseData); } catch (error) { throw error; } } async function getModuleBay() { try { const moduleBayId = this.getNodeParameter('moduleBayId', 0); const responseData = await apiRequest_1.apiRequest.call(this, 'GET', `/api/dcim/module-bays/${moduleBayId}/`); return responseFormatter_1.formatResponse.call(this, responseData); } catch (error) { throw error; } } async function createModuleBay() { try { const body = {}; // Required fields const device = this.getNodeParameter('device', 0); const name = this.getNodeParameter('moduleBayName', 0); body.device = device; body.name = name; // Optional fields const additionalFields = this.getNodeParameter('additionalFields', 0, {}); if (additionalFields.installed_module) { body.installed_module = additionalFields.installed_module; } if (additionalFields.label) { body.label = additionalFields.label; } if (additionalFields.position) { body.position = additionalFields.position; } if (additionalFields.description) { body.description = additionalFields.description; } if (additionalFields.tags) { body.tags = additionalFields.tags; } if (additionalFields.custom_fields) { body.custom_fields = JSON.parse(additionalFields.custom_fields); } const responseData = await apiRequest_1.apiRequest.call(this, 'POST', '/api/dcim/module-bays/', body); return responseFormatter_1.formatResponse.call(this, responseData); } catch (error) { throw error; } } async function updateModuleBay() { try { const moduleBayId = this.getNodeParameter('moduleBayId', 0); const body = {}; // Optional fields for update const updateFields = this.getNodeParameter('updateFields', 0, {}); if (updateFields.device) { body.device = updateFields.device; } if (updateFields.name) { body.name = updateFields.name; } if (updateFields.installed_module) { body.installed_module = updateFields.installed_module; } if (updateFields.label) { body.label = updateFields.label; } if (updateFields.position) { body.position = updateFields.position; } if (updateFields.description) { body.description = updateFields.description; } if (updateFields.tags) { body.tags = updateFields.tags; } if (updateFields.custom_fields) { body.custom_fields = JSON.parse(updateFields.custom_fields); } const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', `/api/dcim/module-bays/${moduleBayId}/`, body); return responseFormatter_1.formatResponse.call(this, responseData); } catch (error) { throw error; } } async function deleteModuleBay() { try { const moduleBayId = this.getNodeParameter('moduleBayId', 0); await apiRequest_1.apiRequest.call(this, 'DELETE', `/api/dcim/module-bays/${moduleBayId}/`); return [{ json: { success: true } }]; } catch (error) { throw error; } }