diff --git a/models/order.js b/models/order.js index 08d36cc..5c2944f 100644 --- a/models/order.js +++ b/models/order.js @@ -33,6 +33,11 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false + }, + give: { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: false } }, { sequelize, diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 13c6561..40864b9 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -178,6 +178,7 @@ p.before-link a::before { } .sandwich { + display: flex; margin-left: 1em; } @@ -242,6 +243,11 @@ p.before-link a::before { width: 100%; } +.give { + height: min-content; + width: min-content; +} + @media (hover: none) and (pointer: coarse) { body { font-size: xx-large; diff --git a/routes/orders.js b/routes/orders.js index fa2d2d8..468d5bb 100644 --- a/routes/orders.js +++ b/routes/orders.js @@ -2,6 +2,7 @@ let express = require("express"); let router = express.Router(); let sessionCheck = require("../middlewares/sessionCheck"); let models = require("../models"); +let error = require("./utils/error"); router.get("/", sessionCheck(2), async (req, res) => { @@ -9,7 +10,7 @@ router.get("/", sessionCheck(2), async (req, res) => { let orders = {}; for (let o of await models.Order.findAll({ - where: {paid: true}, + where: {paid: true, give: false}, include: [{ model: models.Sandwich, through: { @@ -29,6 +30,18 @@ router.get("/", sessionCheck(2), async (req, res) => { orders[o.DepartmentName][name][o.id] = o.Sandwiches; } res.render("orders", {title: "SOD - Orders", orders: orders, date: date}); +}).post("/give", sessionCheck(2), async (req, res) => { + if (!req.body.id) + return error(req, res, "Missing arg !", 400); + + let order = await models.Order.findByPk(req.body.id, {where: {paid: true, give: false}}); + if (!order) + return error(req, res, "Invalid command id !", 400); + + order.give = true; + await order.save(); + + res.redirect("/orders") }); module.exports = router; diff --git a/views/orders.pug b/views/orders.pug index 421f454..95c5a19 100644 --- a/views/orders.pug +++ b/views/orders.pug @@ -17,6 +17,9 @@ block content h4 #{__("order")} N°#{id} each sandwich in order div.sandwich + form.give(method="POST" action="/orders/give") + input(type="hidden" name="id" value=id) + input.give(type="submit" value="v") h4= sandwich.name script(src="/javascripts/orders.js")