Ajout gestion Look & Sync firmwares, et routes BST
This commit is contained in:
278
controllers/api.controller.js
Normal file
278
controllers/api.controller.js
Normal file
@@ -0,0 +1,278 @@
|
||||
const services = require('../services')
|
||||
|
||||
const { device } = services
|
||||
|
||||
const getPrograms = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const programs = await device.getPrograms(req.params.msn);
|
||||
res.send(programs);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const postPrograms = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const programs = await device.postPrograms(req.params.msn, req.body.programs, req.body.timestamp);
|
||||
res.send(programs);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const putPrograms = async (req, res, next) => {
|
||||
try {
|
||||
var programs = await device.postPrograms(req.params.msn, req.body.programs, req.body.timestamp);
|
||||
res.send(programs);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const deletePrograms = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const programs = await device.postPrograms(req.params.msn, [], req.body.timestamp);
|
||||
res.send(programs);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const getConfiguration = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const configuration = await device.getConfiguration(req.params.msn);
|
||||
res.send(configuration);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const postConfiguration = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const configuration = await device.postConfiguration(req.params.msn, req.body.configuration, req.body.timestamp);
|
||||
res.send(configuration);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const putConfiguration = async (req, res, next) => {
|
||||
try {
|
||||
var configuration = await device.postConfiguration(req.params.msn, req.body.configuration, req.body.timestamp);
|
||||
res.send(configuration);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const deleteConfiguration = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const configuration = await device.postConfiguration(req.params.msn, [], req.body.timestamp);
|
||||
res.send(configuration);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const getSlots = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const slots = await device.getSlots(req.params.msn);
|
||||
res.send(slots);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const postSlots = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const slots = await device.postSlots(req.params.msn, req.body.slots, req.body.timestamp);
|
||||
res.send(slots);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const putSlots = async (req, res, next) => {
|
||||
try {
|
||||
var slots = await device.postSlots(req.params.msn, req.body.slots, req.body.timestamp);
|
||||
res.send(slots);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const deleteSlots = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const slots = await device.postSlots(req.params.msn, [], req.body.timestamp);
|
||||
res.send(slots);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const getManualCommand = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const manualCommand = await device.getManualCommand(req.params.msn);
|
||||
res.send(manualCommand);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const postManualCommand = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const manualCommand = await device.postManualCommand(req.params.msn, req.body.manualCommand);
|
||||
res.send(manualCommand);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const putManualCommand = async (req, res, next) => {
|
||||
try {
|
||||
var manualCommand = await device.postManualCommand(req.params.msn, req.body.manualCommand);
|
||||
res.send(manualCommand);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const deleteManualCommand = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const manualCommand = await device.postManualCommand(req.params.msn, null);
|
||||
res.send(manualCommand);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const getStatusCommand = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const statusCommand = await device.getStatusCommand(req.params.msn);
|
||||
res.send(statusCommand);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const postStatusCommand = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const statusCommand = await device.postStatusCommand(req.params.msn, req.body.statusCommand);
|
||||
res.send(statusCommand);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const putStatusCommand = async (req, res, next) => {
|
||||
try {
|
||||
var statusCommand = await device.postStatusCommand(req.params.msn, req.body.statusCommand);
|
||||
res.send(statusCommand);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const deleteStatusCommand = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const statusCommand = await device.postStatusCommand(req.params.msn, null);
|
||||
res.send(statusCommand);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const getAcknowledgedAlerts = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const acknowledgedAlerts = await device.getAcknowledgedAlerts(req.params.msn);
|
||||
res.send(acknowledgedAlerts);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const postAcknowledgedAlerts = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const acknowledgedAlerts = await device.postAcknowledgedAlerts(req.params.msn, req.body.acknowledgedAlerts);
|
||||
res.send(acknowledgedAlerts);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const putAcknowledgedAlerts = async (req, res, next) => {
|
||||
try {
|
||||
var acknowledgedAlerts = await device.postAcknowledgedAlerts(req.params.msn, req.body.acknowledgedAlerts);
|
||||
res.send(acknowledgedAlerts);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const deleteAcknowledgedAlerts = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
try {
|
||||
const acknowledgedAlerts = await device.postAcknowledgedAlerts(req.params.msn, null);
|
||||
res.send(acknowledged);
|
||||
} catch (error) {
|
||||
res.status(500).send({message: error.message || "unknown_error"});
|
||||
}
|
||||
}
|
||||
|
||||
const ping = async (req, res, next) => {
|
||||
///// Emit event to server
|
||||
res.sendStatus(200);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getPrograms,
|
||||
postPrograms,
|
||||
putPrograms,
|
||||
deletePrograms,
|
||||
|
||||
getConfiguration,
|
||||
postConfiguration,
|
||||
putConfiguration,
|
||||
deleteConfiguration,
|
||||
|
||||
getSlots,
|
||||
postSlots,
|
||||
putSlots,
|
||||
deleteSlots,
|
||||
|
||||
getManualCommand,
|
||||
postManualCommand,
|
||||
putManualCommand,
|
||||
deleteManualCommand,
|
||||
|
||||
getStatusCommand,
|
||||
postStatusCommand,
|
||||
putStatusCommand,
|
||||
deleteStatusCommand,
|
||||
|
||||
getAcknowledgedAlerts,
|
||||
postAcknowledgedAlerts,
|
||||
putAcknowledgedAlerts,
|
||||
deleteAcknowledgedAlerts,
|
||||
|
||||
ping,
|
||||
}
|
||||
Reference in New Issue
Block a user