diff --git a/app.js b/app.js index 4e7c41d..ad78c94 100644 --- a/app.js +++ b/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) => { diff --git a/public/javascripts/sandwiches.js b/public/javascripts/sandwiches.js new file mode 100644 index 0000000..c14d5ea --- /dev/null +++ b/public/javascripts/sandwiches.js @@ -0,0 +1,4 @@ +const date = document.getElementById("date"); + + +date.addEventListener("change", () => window.location.href = "?date="+date.value); diff --git a/routes/sandwiches.js b/routes/sandwiches.js new file mode 100644 index 0000000..a567464 --- /dev/null +++ b/routes/sandwiches.js @@ -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; diff --git a/views/sandwiches.pug b/views/sandwiches.pug new file mode 100644 index 0000000..75cb72a --- /dev/null +++ b/views/sandwiches.pug @@ -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")