🐛 Fix date parameter not accepting unix timestamp
This commit is contained in:
@ -32,6 +32,17 @@ export async function getTimetable(req, res) {
|
|||||||
res.send(timetable.data);
|
res.send(timetable.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function for converting a date string
|
||||||
|
// (eg. "2022-06-02" or "1654128000000") to a
|
||||||
|
// unix timestamp
|
||||||
|
function convertToDate(dateQuery) {
|
||||||
|
var date;
|
||||||
|
if (dateQuery.match(/^[0-9]+$/) != null) date = parseInt(dateQuery);
|
||||||
|
else date = dateQuery;
|
||||||
|
date = new Date(date).setUTCHours(0, 0, 0, 0);
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
// Get substitutions API endpoint (/api/substitutions)
|
// Get substitutions API endpoint (/api/substitutions)
|
||||||
// Returns all known substitutions for requested date / class
|
// Returns all known substitutions for requested date / class
|
||||||
// If no class is supplied, all substitutions are returned
|
// If no class is supplied, all substitutions are returned
|
||||||
@ -40,10 +51,10 @@ export async function getSubstitutions(req, res) {
|
|||||||
var from, to, date;
|
var from, to, date;
|
||||||
// Check if from or to date is set in request
|
// Check if from or to date is set in request
|
||||||
if (req.query.from && req.query.to) {
|
if (req.query.from && req.query.to) {
|
||||||
from = new Date(req.query.from).setUTCHours(0, 0, 0, 0);
|
from = convertToDate(req.query.from);
|
||||||
to = new Date(req.query.to).setUTCHours(0, 0, 0, 0);
|
to = convertToDate(req.query.to);
|
||||||
} else if (req.query.date) {
|
} else if (req.query.date) {
|
||||||
date = new Date(req.query.date).setUTCHours(0, 0, 0, 0);
|
date = convertToDate(req.query.date);
|
||||||
}
|
}
|
||||||
|
|
||||||
const prismaOptions = {
|
const prismaOptions = {
|
||||||
@ -102,10 +113,10 @@ export async function getHistory(req, res) {
|
|||||||
var from, to, date;
|
var from, to, date;
|
||||||
// Check if from or to date is set in request
|
// Check if from or to date is set in request
|
||||||
if (req.query.from && req.query.to) {
|
if (req.query.from && req.query.to) {
|
||||||
from = new Date(req.query.from).setUTCHours(0, 0, 0, 0);
|
from = convertToDate(req.query.from);
|
||||||
to = new Date(req.query.to).setUTCHours(0, 0, 0, 0);
|
to = convertToDate(req.query.to);
|
||||||
} else if (req.query.date) {
|
} else if (req.query.date) {
|
||||||
date = new Date(req.query.date).setUTCHours(0, 0, 0, 0);
|
date = convertToDate(req.query.date);
|
||||||
}
|
}
|
||||||
|
|
||||||
const prismaOptions = {
|
const prismaOptions = {
|
||||||
|
Reference in New Issue
Block a user