UNPKG

n8n-nodes-netbox

Version:

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

95 lines (94 loc) 4.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listContactAssignments = listContactAssignments; exports.getContactAssignment = getContactAssignment; exports.createContactAssignment = createContactAssignment; exports.updateContactAssignment = updateContactAssignment; exports.deleteContactAssignment = deleteContactAssignment; const apiRequest_1 = require("../../../helpers/apiRequest"); const responseFormatter_1 = require("../../../helpers/responseFormatter"); async function listContactAssignments() { const returnAll = this.getNodeParameter('returnAll', 0); const filters = this.getNodeParameter('filters', 0, {}); const qs = {}; Object.assign(qs, filters); if (returnAll) { const response = await apiRequest_1.apiRequestAllItems.call(this, 'GET', '/api/tenancy/contact-assignments/', {}, qs); return responseFormatter_1.formatResponse.call(this, response); } else { const limit = this.getNodeParameter('limit', 0); qs.limit = limit; const response = await apiRequest_1.apiRequest.call(this, 'GET', '/api/tenancy/contact-assignments/', {}, qs); return responseFormatter_1.formatResponse.call(this, response); } } async function getContactAssignment() { const contactAssignmentId = this.getNodeParameter('id', 0); try { const endpoint = `/api/tenancy/contact-assignments/${contactAssignmentId}/`; const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { throw new Error(`Failed to get contact assignment: ${error.message}`); } } async function createContactAssignment() { const objectType = this.getNodeParameter('object_type', 0); const objectId = this.getNodeParameter('object_id', 0); const contact = this.getNodeParameter('contact', 0); const role = this.getNodeParameter('role', 0); const additionalFields = this.getNodeParameter('additionalFields', 0); const body = { object_type: objectType, object_id: objectId, contact, role, }; try { // Add all additional fields to the request body Object.assign(body, additionalFields); const endpoint = '/api/tenancy/contact-assignments/'; const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { throw new Error(`Failed to create contact assignment: ${error.message}`); } } async function updateContactAssignment() { const contactAssignmentId = this.getNodeParameter('id', 0); const objectType = this.getNodeParameter('object_type', 0); const objectId = this.getNodeParameter('object_id', 0); const contact = this.getNodeParameter('contact', 0); const role = this.getNodeParameter('role', 0); const additionalFields = this.getNodeParameter('additionalFields', 0); const body = { object_type: objectType, object_id: objectId, contact, role, }; try { // Add all additional fields to the request body Object.assign(body, additionalFields); const endpoint = `/api/tenancy/contact-assignments/${contactAssignmentId}/`; const response = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, body); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { throw new Error(`Failed to update contact assignment: ${error.message}`); } } async function deleteContactAssignment() { const contactAssignmentId = this.getNodeParameter('id', 0); try { const endpoint = `/api/tenancy/contact-assignments/${contactAssignmentId}/`; await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint); return [{ json: { success: true } }]; } catch (error) { throw new Error(`Failed to delete contact assignment: ${error.message}`); } }