Add sandwiches to routes
This commit is contained in:
parent
fe7adb5457
commit
ef4b589a0c
4 changed files with 39 additions and 0 deletions
2
app.js
2
app.js
|
@ -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) => {
|
||||
|
|
4
public/javascripts/sandwiches.js
Normal file
4
public/javascripts/sandwiches.js
Normal 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
20
routes/sandwiches.js
Normal 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
13
views/sandwiches.pug
Normal 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")
|
Reference in a new issue