♻️ Refactor backend

This commit is contained in:
2022-11-16 19:03:32 +01:00
parent 3666492e90
commit 568bfb9782
5 changed files with 74 additions and 70 deletions

View File

@ -22,7 +22,7 @@ export async function getTimetable(req, res) {
},
});
if (!timetable) {
res.status(400).send({
res.status(404).send({
success: false,
error: "no_timetable",
message: "No timetable was found for this class",
@ -44,7 +44,7 @@ function convertToDate(dateQuery) {
if (dateQuery.match(/^[0-9]+$/) != null) date = parseInt(dateQuery);
else date = dateQuery;
date = new Date(date).setUTCHours(0, 0, 0, 0);
return date;
return new Date(date);
}
// Get substitutions API endpoint (/api/substitutions)
@ -75,11 +75,11 @@ export async function getSubstitutions(req, res) {
// Choose which date to use in database query
if (from && to) {
prismaOptions.where.date = {
gte: new Date(from),
lte: new Date(to),
gte: from,
lte: to,
};
} else if (date) {
prismaOptions.where.date = new Date(date);
prismaOptions.where.date = date;
} else {
// Default to all substitutions for today and in the future
prismaOptions.where.date = {
@ -140,11 +140,11 @@ export async function getHistory(req, res) {
// Choose which date to use in database query
if (from && to) {
prismaOptions.where.substitution.date = {
gte: new Date(from),
lte: new Date(to),
gte: from,
lte: to,
};
} else if (date) {
prismaOptions.where.substitution.date = new Date(date);
prismaOptions.where.substitution.date = date;
} else {
// Default to history of all substitutions for today and in the future
prismaOptions.where.substitution.date = {
@ -173,7 +173,7 @@ export async function getHistory(req, res) {
// Get classes API endpoints (/api/classes)
// Get all available classes where timetable and
// substitutions can be requested for
export async function getClasses(req, res) {
export async function getClasses(_req, res) {
const classes = await prisma.class.findMany({
select: {
name: true,