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

21 lines
687 B
JavaScript
Raw 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();
for (let u in data)
await s["set"+u.charAt(0).toUpperCase()+u.slice(1)](data[u]);
socket.emit("set service", data);
socket.broadcast.emit("set service", data);
} catch (e) {
socket.emit("internal error");
console.error(e);
}
}
}