Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
kfet/sockets/set/setService.js

25 lines
848 B
JavaScript
Raw Permalink Normal View History

2020-05-31 22:47:20 +02:00
const models = require("../../models");
module.exports = socket => {
return async (data) => {
try {
let s = await models.Service.findOne({where: {date: {[models.Sequelize.Op.eq]: new Date()}}, include: ["sandwich1", "sandwich2", "sandwich3", "commi1", "commi2"]})
if (!s)
s = await models.Service.create();
2020-06-01 17:32:49 +02:00
for (let u in data) {
if (!(s[u] && s[u].username === data[u]) || !data[u])
s[u + "Busy"] = false;
await s["set" + u.charAt(0).toUpperCase() + u.slice(1)](data[u]);
}
2020-06-01 17:32:49 +02:00
await s.save();
socket.emit("set service", data);
socket.broadcast.emit("set service", data);
} catch (e) {
socket.emit("internal error");
console.error(e);
}
}
}