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 models = require("../models")
|
||||||
|
const utils = require("./utils")
|
||||||
|
|
||||||
module.exports = socket => {
|
module.exports = socket => {
|
||||||
return async (data) => {
|
return async (data) => {
|
||||||
|
@ -27,20 +28,8 @@ module.exports = socket => {
|
||||||
await c.addDrink(await models.Drink.findByPk(data.drink));
|
await c.addDrink(await models.Drink.findByPk(data.drink));
|
||||||
if (data.dessert)
|
if (data.dessert)
|
||||||
await c.setDessert(await models.Drink.findByPk(data.dessert));
|
await c.setDessert(await models.Drink.findByPk(data.dessert));
|
||||||
let send = {
|
|
||||||
number: c.number,
|
let send = utils.commandExport(c);
|
||||||
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
|
|
||||||
}
|
|
||||||
socket.emit("new command", send);
|
socket.emit("new command", send);
|
||||||
socket.broadcast.emit("new command", send);
|
socket.broadcast.emit("new command", send);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const models = require("../models")
|
const models = require("../models")
|
||||||
|
const utils = require("./utils")
|
||||||
|
|
||||||
module.exports = socket => {
|
module.exports = socket => {
|
||||||
return async (data) => {
|
return async (data) => {
|
||||||
|
@ -10,12 +11,7 @@ module.exports = socket => {
|
||||||
c.give = null;
|
c.give = null;
|
||||||
c.error = false;
|
c.error = false;
|
||||||
|
|
||||||
let service = models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}});
|
utils.resetService(c, await 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;
|
|
||||||
}
|
|
||||||
c.WIP = false;
|
c.WIP = false;
|
||||||
|
|
||||||
await c.save();
|
await c.save();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const models = require("../models")
|
const models = require("../models")
|
||||||
|
const utils = require("./utils")
|
||||||
|
|
||||||
module.exports = socket => {
|
module.exports = socket => {
|
||||||
return async (data) => {
|
return async (data) => {
|
||||||
|
@ -9,12 +10,7 @@ module.exports = socket => {
|
||||||
|
|
||||||
c.give = new Date()
|
c.give = new Date()
|
||||||
|
|
||||||
let service = models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}});
|
utils.resetService(c, await 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;
|
|
||||||
}
|
|
||||||
c.WIP = false;
|
c.WIP = false;
|
||||||
|
|
||||||
await c.save();
|
await c.save();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const models = require("../models")
|
const models = require("../models")
|
||||||
|
const utils = require("./utils")
|
||||||
|
|
||||||
module.exports = socket => {
|
module.exports = socket => {
|
||||||
return async () => {
|
return async () => {
|
||||||
|
@ -12,20 +13,7 @@ module.exports = socket => {
|
||||||
order: ["number"],
|
order: ["number"],
|
||||||
include: [models.Dish, models.Ingredient, models.Sauce, models.Drink, models.Dessert, "client", "pc", "sandwich"]
|
include: [models.Dish, models.Ingredient, models.Sauce, models.Drink, models.Dessert, "client", "pc", "sandwich"]
|
||||||
})) {
|
})) {
|
||||||
commands.push({
|
commands.push(utils.commandExport(c));
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
socket.emit("list command", commands);
|
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