Some code refactor
This commit is contained in:
parent
8f4cad8be6
commit
19f79a5fdc
5 changed files with 36 additions and 40 deletions
|
@ -1,4 +1,5 @@
|
|||
const models = require("../models")
|
||||
const utils = require("./utils")
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
|
@ -27,20 +28,8 @@ module.exports = socket => {
|
|||
await c.addDrink(await models.Drink.findByPk(data.drink));
|
||||
if (data.dessert)
|
||||
await c.setDessert(await models.Drink.findByPk(data.dessert));
|
||||
let send = {
|
||||
number: c.number,
|
||||
sandwich: c.sandwich ? c.sandwich.username : null,
|
||||
client: c.client ? c.client.firstName + " " + c.client.lastName : null,
|
||||
dish: c.Dish ? c.Dish.name : null,
|
||||
ingredients: c.Ingredients ? c.Ingredients.map(i => i.name) : null,
|
||||
sauces: c.Sauces ? c.Sauces.map(s => s.name) : null,
|
||||
drink: c.Drink ? c.Drink.name : null,
|
||||
dessert: c.Dessert ? c.Dessert.name : null,
|
||||
error: c.error,
|
||||
give: c.give,
|
||||
done: c.done,
|
||||
WIP: c.WIP
|
||||
}
|
||||
|
||||
let send = utils.commandExport(c);
|
||||
socket.emit("new command", send);
|
||||
socket.broadcast.emit("new command", send);
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const models = require("../models")
|
||||
const utils = require("./utils")
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
|
@ -10,12 +11,7 @@ module.exports = socket => {
|
|||
c.give = null;
|
||||
c.error = false;
|
||||
|
||||
let service = models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}});
|
||||
if (c.WIP && service) {
|
||||
let sandwichs = [service.sandwich1Id, service.sandwich2Id, service.sandwich3Id]
|
||||
if (c.sandwichId in sandwichs)
|
||||
service["sandwich"+sandwichs.indexOf(c.sandwichId)+1] = false;
|
||||
}
|
||||
utils.resetService(c, await models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}}));
|
||||
c.WIP = false;
|
||||
|
||||
await c.save();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const models = require("../models")
|
||||
const utils = require("./utils")
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
|
@ -9,12 +10,7 @@ module.exports = socket => {
|
|||
|
||||
c.give = new Date()
|
||||
|
||||
let service = models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}});
|
||||
if (c.WIP && service) {
|
||||
let sandwiches = [service.sandwich1Id, service.sandwich2Id, service.sandwich3Id]
|
||||
if (c.sandwichId in sandwiches)
|
||||
service["sandwich"+sandwiches.indexOf(c.sandwichId)+1] = false;
|
||||
}
|
||||
utils.resetService(c, await models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}}));
|
||||
c.WIP = false;
|
||||
|
||||
await c.save();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const models = require("../models")
|
||||
const utils = require("./utils")
|
||||
|
||||
module.exports = socket => {
|
||||
return async () => {
|
||||
|
@ -12,20 +13,7 @@ module.exports = socket => {
|
|||
order: ["number"],
|
||||
include: [models.Dish, models.Ingredient, models.Sauce, models.Drink, models.Dessert, "client", "pc", "sandwich"]
|
||||
})) {
|
||||
commands.push({
|
||||
number: c.number,
|
||||
sandwich: c.sandwich ? c.sandwich.username : null,
|
||||
client: c.client ? c.client.firstName + " " + c.client.lastName : null,
|
||||
dish: c.Dish ? c.Dish.name : null,
|
||||
ingredients: c.Ingredients ? c.Ingredients.map(i => i.name) : null,
|
||||
sauces: c.Sauces ? c.Sauces.map(s => s.name) : null,
|
||||
drink: c.Drink ? c.Drink.name : null,
|
||||
dessert: c.Dessert ? c.Dessert.name : null,
|
||||
error: c.error,
|
||||
give: c.give,
|
||||
done: c.done,
|
||||
WIP: c.WIP
|
||||
});
|
||||
commands.push(utils.commandExport(c));
|
||||
}
|
||||
socket.emit("list command", commands);
|
||||
}
|
||||
|
|
27
sockets/utils.js
Normal file
27
sockets/utils.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
function commandExport (c ) {
|
||||
return {
|
||||
number: c.number,
|
||||
sandwich: c.sandwich ? c.sandwich.username : null,
|
||||
client: c.client ? c.client.firstName + " " + c.client.lastName : null,
|
||||
dish: c.Dish ? c.Dish.name : null,
|
||||
ingredients: c.Ingredients ? c.Ingredients.map(i => i.name) : null,
|
||||
sauces: c.Sauces ? c.Sauces.map(s => s.name) : null,
|
||||
drink: c.Drink ? c.Drink.name : null,
|
||||
dessert: c.Dessert ? c.Dessert.name : null,
|
||||
error: c.error,
|
||||
give: c.give,
|
||||
done: c.done,
|
||||
WIP: c.WIP
|
||||
}
|
||||
}
|
||||
|
||||
function resetService(c, service) {
|
||||
if (c.WIP && service) {
|
||||
let sandwiches = [service.sandwich1Id, service.sandwich2Id, service.sandwich3Id]
|
||||
if (c.sandwichId in sandwiches)
|
||||
service["sandwich"+sandwiches.indexOf(c.sandwichId)+1] = false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.commandExport = commandExport;
|
||||
module.exports.resetService = resetService;
|
Reference in a new issue