Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
SOD/routes/commands.js

30 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-08-16 12:48:43 +02:00
let express = require("express");
let router = express.Router();
let sessionCheck = require("../middlewares/sessionCheck");
2020-08-16 12:48:43 +02:00
let models = require("../models");
router.get("/", sessionCheck(2), async (req, res) => {
2020-08-16 12:48:43 +02:00
let date = req.query.date ? req.query.date : (new Date()).toISOString().substring(0,10);
let commands = {};
for (let i of await models.SandwichCommand.findAll({where: {date: date}})) {
i.Command = await models.Command.findByPk(i.CommandId);
i.Sandwich = await models.Sandwich.findByPk(i.SandwichName);
let name = i.Command.firstName + " " + i.Command.lastName;
if (!(i.Command.DepartmentName in commands))
commands[i.Command.DepartmentName] = {};
if (!(name in commands[i.Command.DepartmentName]))
commands[i.Command.DepartmentName][name] = {};
if (!(i.Command.id in commands[i.Command.DepartmentName][name]))
commands[i.Command.DepartmentName][name][i.Command.id] = []
commands[i.Command.DepartmentName][name][i.Command.id].push(i);
}
2020-08-17 19:13:00 +02:00
res.render("commands", {title: "SOD - Commands", user: req.session.user, commands: commands, date: date});
2020-08-16 12:48:43 +02:00
});
module.exports = router;