Ajout routes API PUT/DEL
This commit is contained in:
@@ -19,12 +19,15 @@ const getRequestToDo = async function (msn) {
|
||||
try {
|
||||
var todos = []
|
||||
const children = await dbcontroller.getDeviceChildren(msn)
|
||||
var parent = await dbcontroller.getDevice(msn)
|
||||
children.push(parent)
|
||||
|
||||
for (const child of children) {
|
||||
///// Retrieve child
|
||||
const device = await dbcontroller.getDevice(child.msn)
|
||||
const msn = child.msn || child.relayMsn || null
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
|
||||
var todo = { msn : child.msn }
|
||||
var todo = { serialNumber : msn }
|
||||
|
||||
///// Programs
|
||||
if (device.programs != undefined) {
|
||||
@@ -138,6 +141,47 @@ const postPrograms = async function (msn, programs, timestamp) {
|
||||
}
|
||||
}
|
||||
|
||||
const putPrograms = async function (msn, programs, timestamp) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
var device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variables
|
||||
if (programs) {
|
||||
device.programs = { timestamp: timestamp || util.unixTimestamp(), programs: { ...device.programs.programs, ...programs } }
|
||||
} else {
|
||||
device.programmingTimestamp = device.programs.timestamp;
|
||||
// device.programs = undefined
|
||||
}
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device)
|
||||
|
||||
return device.programs
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const deletePrograms = async function (msn) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variables
|
||||
device.programs = { timestamp: 0, programs: undefined }
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device, msn)
|
||||
|
||||
return device.programs
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const getConfiguration = async function (msn) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
@@ -173,6 +217,47 @@ const postConfiguration = async function (msn, configuration, timestamp) {
|
||||
}
|
||||
}
|
||||
|
||||
const putConfiguration = async function (msn, configuration, timestamp) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variables
|
||||
if (configuration) {
|
||||
device.configuration = { timestamp: timestamp || util.unixTimestamp(), configuration: { ...device.configuration.configuration, ...configuration }}
|
||||
} else {
|
||||
device.configurationTimestamp = device.configuration.timestamp;
|
||||
// device.configuration = undefined
|
||||
}
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device)
|
||||
|
||||
return device.configuration
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const deleteConfiguration = async function (msn) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variables
|
||||
device.configuration = { timestamp: 0, configuration: undefined }
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device, msn)
|
||||
|
||||
return device.configuration
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const getSlots = async function (msn) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
@@ -208,6 +293,47 @@ const postSlots = async function (msn, slots, timestamp) {
|
||||
}
|
||||
}
|
||||
|
||||
const putSlots = async function (msn, slots, timestamp) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variables
|
||||
if (slots) {
|
||||
device.slots = { timestamp: timestamp || util.unixTimestamp(), slots: { ...device.slots.slots, ...slots } }
|
||||
} else {
|
||||
device.programmingTimestamp = device.slots.timestamp;
|
||||
// device.slots = undefined
|
||||
}
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device, msn)
|
||||
|
||||
return device.slots
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const deleteSlots = async function (msn) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variables
|
||||
device.slots = { timestamp: 0, slots: undefined }
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device, msn)
|
||||
|
||||
return device.slots
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const getManualCommand = async function (msn) {
|
||||
try {
|
||||
@@ -243,6 +369,46 @@ const postManualCommand = async function (msn, manualCommand) {
|
||||
}
|
||||
}
|
||||
|
||||
const putManualCommand = async function (msn, manualCommand) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variable
|
||||
if (manualCommand) {
|
||||
device.manualCommand = { timestamp: util.unixTimestamp(), manualCommand: { ...device.manualCommand.manualCommand, ...manualCommand } }
|
||||
} else {
|
||||
device.manualCommand = undefined
|
||||
}
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device, msn)
|
||||
|
||||
return device.manualCommand
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const deleteManualCommand = async function (msn, manualCommand) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variable
|
||||
device.manualCommand = { timestamp: 0, manualCommand: undefined }
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device, msn)
|
||||
|
||||
return device.manualCommand
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusCommand = async function (msn) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
@@ -277,6 +443,46 @@ const postStatusCommand = async function (msn, statusCommand) {
|
||||
}
|
||||
}
|
||||
|
||||
const putStatusCommand = async function (msn, statusCommand) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variable
|
||||
if (statusCommand) {
|
||||
device.statusCommand = { timestamp: util.unixTimestamp(), statusCommand: { ...device.statusCommand.statusCommand, ...statusCommand } }
|
||||
} else {
|
||||
device.statusCommand = undefined
|
||||
}
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device, msn)
|
||||
|
||||
return device.statusCommand
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const deleteStatusCommand = async function (msn) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variable
|
||||
device.statusCommand = { timestamp: 0, statusCommand: undefined }
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device, msn)
|
||||
|
||||
return device.statusCommand
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const getAcknowledgedAlerts = async function (msn) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
@@ -310,6 +516,45 @@ const postAcknowledgedAlerts = async function (msn, acknowledgedAlerts) {
|
||||
}
|
||||
}
|
||||
|
||||
const putAcknowledgedAlerts = async function (msn, acknowledgedAlerts) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variable
|
||||
if (acknowledgedAlerts) {
|
||||
device.acknowledgedAlerts = { timestamp: util.unixTimestamp(), acknowledgedAlerts: { ...device.acknowledgedAlerts.acknowledgedAlerts, ...acknowledgedAlerts } }
|
||||
} else {
|
||||
device.acknowledgedAlerts = undefined
|
||||
}
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device, msn)
|
||||
|
||||
return device.acknowledgedAlerts
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const deleteAcknowledgedAlerts = async function (msn) {
|
||||
try {
|
||||
///// Retrieve device
|
||||
const device = await dbcontroller.getDevice(msn)
|
||||
if (!device) { throw({message: "module_not_found_for_this_identifier"}) }
|
||||
|
||||
///// Set variable
|
||||
device.acknowledgedAlerts = { timestamp: 0, acknowledgedAlerts: undefined }
|
||||
|
||||
///// Update device
|
||||
await dbcontroller.updateDevice(device, msn)
|
||||
|
||||
return device.acknowledgedAlerts
|
||||
} catch (e) {
|
||||
throw new Error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
getStatus,
|
||||
@@ -318,14 +563,26 @@ module.exports = {
|
||||
getRequestToDo,
|
||||
getPrograms,
|
||||
postPrograms,
|
||||
putPrograms,
|
||||
deletePrograms,
|
||||
getConfiguration,
|
||||
postConfiguration,
|
||||
putConfiguration,
|
||||
deleteConfiguration,
|
||||
getSlots,
|
||||
postSlots,
|
||||
putSlots,
|
||||
deleteSlots,
|
||||
getManualCommand,
|
||||
postManualCommand,
|
||||
putManualCommand,
|
||||
deleteManualCommand,
|
||||
getStatusCommand,
|
||||
postStatusCommand,
|
||||
putStatusCommand,
|
||||
deleteStatusCommand,
|
||||
getAcknowledgedAlerts,
|
||||
postAcknowledgedAlerts,
|
||||
putAcknowledgedAlerts,
|
||||
deleteAcknowledgedAlerts,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user