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,
allowNull: false,
defaultValue: false
},
give: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
}
}, {
sequelize,

View file

@ -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;

View file

@ -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;

View file

@ -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")