UNPKG

n8n-nodes-arubacentral

Version:

n8n community node for Aruba Central API integration with comprehensive monitoring, configuration, and management capabilities

68 lines (67 loc) 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDeviceGroup = getDeviceGroup; exports.moveDevicesToGroup = moveDevicesToGroup; const apiRequest_1 = require("../../../helpers/apiRequest"); const responseFormatter_1 = require("../../../helpers/responseFormatter"); /** * Get the group associated with a specific device */ async function getDeviceGroup() { try { const deviceSerial = this.getNodeParameter('deviceSerial', 0); if (!deviceSerial) { throw new Error('Device serial is required'); } console.log(`Getting group for device with serial: ${deviceSerial}`); const endpoint = `/configuration/v1/devices/${deviceSerial}/group`; const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint); console.log('API Response for getDeviceGroup:', response); return (0, responseFormatter_1.formatResponse)(response); } catch (error) { console.log('ERROR in getDeviceGroup:', error); throw error; } } /** * Move devices to a specific group */ async function moveDevicesToGroup() { try { const group = this.getNodeParameter('group', 0); const serials = this.getNodeParameter('serials', 0); const preserveConfigOverrides = this.getNodeParameter('preserve_config_overrides', 0, []); if (!group || !serials || serials.length === 0) { throw new Error('Group name and at least one device serial are required'); } console.log(`Moving ${serials.length} devices to group: ${group}`); console.log(`Device serials: ${serials.join(', ')}`); const body = { group, serials, }; if (preserveConfigOverrides.length > 0) { body.preserve_config_overrides = preserveConfigOverrides; console.log(`Preserving config overrides for: ${preserveConfigOverrides.join(', ')}`); } const endpoint = '/configuration/v1/devices/move'; const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body); console.log('API Response for moveDevicesToGroup:', response); // Handle string response if (typeof response === 'string') { console.log('Received string response, converting to object'); const formattedResponse = { success: response.toLowerCase().includes('success'), message: response, serials: serials, }; return (0, responseFormatter_1.formatResponse)(formattedResponse); } return (0, responseFormatter_1.formatResponse)(response); } catch (error) { console.log('ERROR in moveDevicesToGroup:', error); throw error; } }