From 9c0c14a34b24e33afa4e595709ae1cc69b1d2b0e Mon Sep 17 00:00:00 2001 From: flifloo Date: Sat, 15 Aug 2020 12:55:21 +0200 Subject: [PATCH] Link database on index page generation for sandwichs & sandwichs --- routes/index.js | 8 +++++--- views/index.pug | 16 +++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/routes/index.js b/routes/index.js index e260bad..06782a0 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,9 +1,11 @@ let express = require("express"); let router = express.Router(); +let models = require("../models"); -/* GET home page. */ -router.get("/", (req, res) => { - res.render("index", { title: "SOD" }); +router.get("/", async (req, res) => { + let departments = await models.Department.findAll(); + let sandwichs = await models.Sandwich.findAll(); + res.render("index", { title: "SOD", departments: departments, sandwichs: sandwichs }); }); module.exports = router; diff --git a/views/index.pug b/views/index.pug index 6cd81cc..f215b47 100644 --- a/views/index.pug +++ b/views/index.pug @@ -6,14 +6,11 @@ block content p Welcome to Sandwiches Order Doua form#command(action="/command" method="POST") div.field - label(for="department") Department: + label(for="sandwich") Department: input#department(type="list" list="department-list" name="department" required) datalist#department-list - option(value="Info") - option(value="Bio") - option(value="Chimi") - option(value="GC") - option(value="GEA") + each department in departments + option(value=department.name) div.field label(for="firstname") First name: @@ -39,13 +36,14 @@ block content input#send(type="submit" value="Pay") datalist#sandwich-list - option(value="Jambon beurre") + each sandwich in sandwichs + option(value=sandwich.name) datalist#date-list option(value="14/08/2020") div#more - a(href="#about") About - a(href="#contact") Contact + a About + a Contact div#dark.hide div#about.card.hide