Archived
1
0
Fork 0

Add sandwiches to routes

This commit is contained in:
Ethanell 2020-08-16 13:26:58 +02:00
parent fe7adb5457
commit ef4b589a0c
4 changed files with 39 additions and 0 deletions

2
app.js
View file

@ -6,6 +6,7 @@ let logger = require("morgan");
let indexRouter = require("./routes/index");
let commandRouter = require("./routes/command");
let ordersRouter = require("./routes/orders");
let sandwichesRouter = require("./routes/sandwiches");
let app = express();
@ -22,6 +23,7 @@ app.use(express.static(path.join(__dirname, "public")));
app.use("/", indexRouter);
app.use("/command", commandRouter);
app.use("/orders", ordersRouter);
app.use("/sandwiches", sandwichesRouter);
// catch 404 and forward to error handler
app.use((req, res) => {

View file

@ -0,0 +1,4 @@
const date = document.getElementById("date");
date.addEventListener("change", () => window.location.href = "?date="+date.value);

20
routes/sandwiches.js Normal file
View file

@ -0,0 +1,20 @@
let express = require("express");
let router = express.Router();
let models = require("../models");
let sequelize = require("sequelize")
router.get("/", async (req, res) => {
let date = req.query.date ? req.query.date : (new Date()).toISOString().substring(0,10);
res.render("sandwiches", {
title: "SOD",
sandwiches: await models.SandwichCommand.findAll({
attributes: ["SandwichName", [sequelize.fn("COUNT", sequelize.col("SandwichName")), "number"]],
where: {date: date},
group: "SandwichName"
}),
date: date});
});
module.exports = router;

13
views/sandwiches.pug Normal file
View file

@ -0,0 +1,13 @@
extends layout
block content
div#date-selector.card
label(for="date") Date
input#date(type="date" value=date)
div.card
h1 Sandwiches
each sandwich in sandwiches
div.sandwich
h2 #{sandwich.SandwichName}: #{sandwich.dataValues.number}
script(src="javascripts/sandwiches.js")