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/sandwiches.js

31 lines
947 B
JavaScript
Raw Normal View History

2020-08-16 13:26:58 +02:00
let express = require("express");
let router = express.Router();
let sessionCheck = require("../middlewares/sessionCheck");
2020-08-16 13:26:58 +02:00
let models = require("../models");
let sequelize = require("sequelize");
2020-08-16 13:26:58 +02:00
router.get("/", sessionCheck(1), async (req, res) => {
2020-08-16 13:26:58 +02:00
let date = req.query.date ? req.query.date : (new Date()).toISOString().substring(0,10);
res.render("sandwiches", {
2020-08-17 19:13:00 +02:00
title: "SOD - Sandwiches",
sandwiches: await models.Sandwich.findAll({
attributes: ["name", [sequelize.fn("COUNT", sequelize.col("name")), "number"]],
include: [{
attributes: [],
model: models.Order,
where: {paid: true},
through: {
attributes: [],
where: {date: date}
},
required: true
}],
group: "name"
2020-08-16 13:26:58 +02:00
}),
date: date});
});
module.exports = router;