Archived
1
0
Fork 0

Allow to make order given to clear orders list

This commit is contained in:
Ethanell 2020-09-11 13:38:09 +02:00
parent 59005d8d6e
commit 185aefbd82
4 changed files with 28 additions and 1 deletions

View file

@ -33,6 +33,11 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.BOOLEAN, type: DataTypes.BOOLEAN,
allowNull: false, allowNull: false,
defaultValue: false defaultValue: false
},
give: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
} }
}, { }, {
sequelize, sequelize,

View file

@ -178,6 +178,7 @@ p.before-link a::before {
} }
.sandwich { .sandwich {
display: flex;
margin-left: 1em; margin-left: 1em;
} }
@ -242,6 +243,11 @@ p.before-link a::before {
width: 100%; width: 100%;
} }
.give {
height: min-content;
width: min-content;
}
@media (hover: none) and (pointer: coarse) { @media (hover: none) and (pointer: coarse) {
body { body {
font-size: xx-large; font-size: xx-large;

View file

@ -2,6 +2,7 @@ let express = require("express");
let router = express.Router(); let router = express.Router();
let sessionCheck = require("../middlewares/sessionCheck"); let sessionCheck = require("../middlewares/sessionCheck");
let models = require("../models"); let models = require("../models");
let error = require("./utils/error");
router.get("/", sessionCheck(2), async (req, res) => { router.get("/", sessionCheck(2), async (req, res) => {
@ -9,7 +10,7 @@ router.get("/", sessionCheck(2), async (req, res) => {
let orders = {}; let orders = {};
for (let o of await models.Order.findAll({ for (let o of await models.Order.findAll({
where: {paid: true}, where: {paid: true, give: false},
include: [{ include: [{
model: models.Sandwich, model: models.Sandwich,
through: { through: {
@ -29,6 +30,18 @@ router.get("/", sessionCheck(2), async (req, res) => {
orders[o.DepartmentName][name][o.id] = o.Sandwiches; orders[o.DepartmentName][name][o.id] = o.Sandwiches;
} }
res.render("orders", {title: "SOD - Orders", orders: orders, date: date}); 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; module.exports = router;

View file

@ -17,6 +17,9 @@ block content
h4 #{__("order")} N°#{id} h4 #{__("order")} N°#{id}
each sandwich in order each sandwich in order
div.sandwich 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 h4= sandwich.name
script(src="/javascripts/orders.js") script(src="/javascripts/orders.js")