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

34 lines
915 B
JavaScript
Raw Permalink 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();
2020-09-30 11:57:28 +02:00
now.setDate(now.getDate()+1);
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({where: {enable: true}}),
sandwiches: await models.Sandwich.findAll({where: {enable: true}}),
2020-08-24 23:23:46 +02:00
date: {
firstDate: firstDate,
lastDate: lastDate
2020-08-24 23:23:46 +02:00
}
});
2020-06-26 16:59:54 +02:00
});
module.exports = router;