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/setService.js

20 lines
684 B
JavaScript

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);
}
}
}