Files
lsp/controllers/grtd.controller.js
2025-09-17 18:05:08 +02:00

240 lines
5.6 KiB
JavaScript

const services = require('../services')
const util = require('../util')
const { device } = services
const getModuleMsn = (req) => {
return req.query.msn || req.query.id || req.body.module
}
const getRelayMsn = (req) => {
return req.body.relayMsn
}
const postGetRequestToDo = async (req, res, next) => {
///// Emit event to server
try {
await device.postRequestToDo(getRelayMsn(req), req.body);
const todo = await device.getRequestToDo(getRelayMsn(req));
var response = { todo };
console.log(req.body);
res.send(response);
} catch (error) {
res.sendStatus(500);
}
}
const getModuleConfiguration = async (req, res, next) => {
try {
///// Emit event to server
var response = await device.getConfiguration(getModuleMsn(req))
res.send(response.configuration);
} catch (error) {
res.sendStatus(500);
}
}
const setModuleConfiguration = async (req, res, next) => {
try {
///// Emit event to server
await device.postConfiguration(getModuleMsn(req), req.body, util.dateToTimestamp(req.body.flashTimeStamp))
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
const reportModuleDataSent = async (req, res, next) => {
try {
///// Emit event to server
await device.postConfiguration(getModuleMsn(req), null, util.dateToTimestamp(req.body.sentAt))
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
const getModulePrograms = async (req, res, next) => {
try {
///// Emit event to server
var response = await device.getPrograms(getModuleMsn(req))
res.send(response.programs);
} catch (error) {
res.sendStatus(500);
}
}
const setModulePrograms = async (req, res, next) => {
try {
///// Emit event to server
await device.postPrograms(getModuleMsn(req), req.body, util.dateToTimestamp(req.body.flashTimeStamp))
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
const reportProgramsDataSent = async (req, res, next) => {
try {
///// Emit event to server
await device.postPrograms(getModuleMsn(req), null, util.dateToTimestamp(req.body.programmingTimestamp))
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
const reportAllModuleProgramsDataSent = async (req, res, next) => {
try {
///// Emit event to server
await device.postPrograms(getModuleMsn(req), null, util.dateToTimestamp(req.body.sentAt))
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
const getModuleSlots = async (req, res, next) => {
try {
///// Emit event to server
var response = await device.getSlots(getModuleMsn(req))
res.send(response.slots);
} catch (error) {
res.sendStatus(500);
}
}
const setModuleSlots = async (req, res, next) => {
try {
///// Emit event to server
await device.postSlots(getModuleMsn(req), req.body, util.dateToTimestamp(req.body.flashTimeStamp))
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
const reportSlotsDataSent = async (req, res, next) => {
try {
///// Emit event to server
await device.postSlots(getModuleMsn(req), null, util.dateToTimestamp(req.body.programmingTimestamp))
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
const reportAllModuleSlotsDataSent = async (req, res, next) => {
try {
///// Emit event to server
await device.postSlots(getModuleMsn(req), null, util.dateToTimestamp(req.body.sentAt))
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
const getManualCommand = async (req, res, next) => {
try {
///// Emit event to server
var response = await device.getManualCommand(getModuleMsn(req))
res.send(response.manualCommand);
} catch (error) {
res.sendStatus(500);
}
}
const reportManualCommandSent = async (req, res, next) => {
try {
///// Emit event to server
await device.postManualCommand(getModuleMsn(req), null)
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
const getStatusCommand = async (req, res, next) => {
try {
///// Emit event to server
var response = await device.getStatusCommand(getModuleMsn(req))
res.send(response.statusCommand);
} catch (error) {
res.sendStatus(500);
}
}
const reportStatusCommandSent = async (req, res, next) => {
try {
///// Emit event to server
await device.postStatusCommand(getModuleMsn(req), null)
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
const getAcknowledgeAlerts = async (req, res, next) => {
try {
///// Emit event to server
var response = await device.getAcknowledgedAlerts(getModuleMsn(req))
res.send(response.acknowledgedAlerts);
} catch (error) {
res.sendStatus(500);
}
}
const reportAcknowledgeAlerts = async (req, res, next) => {
try {
///// Emit event to server
await device.postAcknowledgedAlerts(getModuleMsn(req), null)
res.sendStatus(200);
} catch (error) {
res.sendStatus(500);
}
}
module.exports = {
postGetRequestToDo,
getModuleConfiguration,
setModuleConfiguration,
reportModuleDataSent,
getModulePrograms,
setModulePrograms,
reportProgramsDataSent,
reportAllModuleProgramsDataSent,
getModuleSlots,
setModuleSlots,
reportSlotsDataSent,
reportAllModuleSlotsDataSent,
getManualCommand,
reportManualCommandSent,
getStatusCommand,
reportStatusCommandSent,
getAcknowledgeAlerts,
reportAcknowledgeAlerts,
}