Simplify arming steps

This commit is contained in:
2018-05-16 22:14:41 -06:00
parent 3388e86d3d
commit 56ef19708d
5 changed files with 727 additions and 35 deletions
+30 -31
View File
@@ -71,33 +71,31 @@ const users = [
];
// Hardcoded data - can only be changed by admin
const lockoutData = {
lockouts: [
{
id: 0,
mac: 'ABCDEF000000',
},
{
id: 1,
mac: '2C3AE843A15F',
},
{
id: 2,
mac: '2C3AE8439EAD',
},
{
id: 3,
mac: 'ABCDEF000003',
},
],
};
const lockoutData = [
{
id: 0,
mac: 'ABCDEF000000',
},
{
id: 1,
mac: '2C3AE843A15F',
},
{
id: 2,
mac: '2C3AE8439EAD',
},
{
id: 3,
mac: 'ABCDEF000003',
},
];
// Derived data - changes through use of system
let toolStatus = lockoutData.lockouts.map(x => (
let toolStatus = lockoutData.map(x => (
{
id: x.id,
action: '',
state: '',
state: 'off',
lastState: 'n/a',
}
));
@@ -140,7 +138,7 @@ app.post('/api/lockout/:mac', (req, res) => {
const mac = req.params.mac;
console.log('Request from MAC: ' + mac + ': ' + JSON.stringify(req.body));
const lockout = lockoutData.lockouts.find(x => x.mac === mac);
const lockout = lockoutData.find(x => x.mac === mac);
if (!lockout) {
res.sendStatus(404);
}
@@ -176,6 +174,10 @@ app.post('/api/lockout/:mac', (req, res) => {
toolStatus[toolIndex] = tool;
});
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'dist', 'index.html'));
});
// Socket.io websocket stuff:
// TODO : remove on prod
@@ -191,16 +193,13 @@ io.on('connection', socket => {
const toolId = data.change.toolId;
const action = data.change.action;
// TODO ; Make this part prettier
if (user) {
if (user.authorizedTools.includes(data.change.toolId)) {
const toolIndex = toolStatus.findIndex(x => x.id === toolId);
if (user && user.authorizedTools.includes(data.change.toolId)) {
const toolIndex = toolStatus.findIndex(x => x.id === toolId);
toolStatus[toolIndex].action = action;
toolStatus[toolIndex].action = action;
console.log(toolStatus);
io.sockets.emit('toolStatus', toolStatus);
}
console.log(toolStatus);
io.sockets.emit('toolStatus', toolStatus);
}
});
});