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

33 lines
837 B
JavaScript
Raw Normal View History

2020-06-26 16:59:54 +02:00
let express = require("express");
let router = express.Router();
let models = require("../models");
2020-06-26 16:59:54 +02:00
router.get("/", async (req, res) => {
2020-08-24 23:23:46 +02:00
let now = new Date();
let [firstDate, lastDate] = [await models.Data.findByPk("firstDate"),
await models.Data.findByPk("lastDate")];
2020-08-24 23:23:46 +02:00
if (firstDate && lastDate && firstDate.value && lastDate.value) {
lastDate = lastDate.value;
2020-08-24 23:23:46 +02:00
firstDate = new Date(firstDate.value);
2020-08-24 23:23:46 +02:00
if (firstDate.getTime() < now.getTime())
firstDate = now;
} else
firstDate = now;
firstDate = firstDate.toISOString().substring(0, 10);
res.render("index", {
title: "SOD - Home",
departments: await models.Department.findAll(),
sandwiches: await models.Sandwich.findAll(),
date: {
firstDate: firstDate,
lastDate: lastDate
2020-08-24 23:23:46 +02:00
}
});
2020-06-26 16:59:54 +02:00
});
module.exports = router;