✨ Return history of future substitutions
This commit is contained in:
@ -90,29 +90,32 @@ export async function getHistory(req, res) {
|
|||||||
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 = new Date(req.query.from).setUTCHours(0, 0, 0, 0);
|
||||||
to = new Date(req.query.to).setUTCHours(0, 0, 0, 0);
|
to = new Date(req.query.to).setUTCHours(0, 0, 0, 0);
|
||||||
} else {
|
} else if (req.query.date) {
|
||||||
date = new Date(req.query.date || new Date()).setUTCHours(0, 0, 0, 0);
|
date = new Date(req.query.date).setUTCHours(0, 0, 0, 0);
|
||||||
console.log(date);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const prismaOptions = {
|
const prismaOptions = {
|
||||||
where: {},
|
where: {
|
||||||
|
substitution: {},
|
||||||
|
},
|
||||||
include: {
|
include: {
|
||||||
substitution: true,
|
substitution: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (requestedClass) {
|
if (requestedClass) {
|
||||||
prismaOptions.where.class = { has: requestedClass };
|
prismaOptions.where.substitution.class = { has: requestedClass };
|
||||||
}
|
}
|
||||||
if (from && to) {
|
if (from && to) {
|
||||||
prismaOptions.where.substitution = {
|
prismaOptions.where.substitution.date = {
|
||||||
date: {
|
gte: new Date(from),
|
||||||
gte: new Date(from),
|
lte: new Date(to),
|
||||||
lte: new Date(to),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
} else if (date) {
|
||||||
|
prismaOptions.where.substitution.date = new Date(date);
|
||||||
} else {
|
} else {
|
||||||
prismaOptions.where.substitution = { date: new Date(date) };
|
prismaOptions.where.substitution.date = {
|
||||||
|
gte: new Date(new Date().setUTCHours(0, 0, 0, 0)),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawChanges = await prisma.substitutionChange.findMany(prismaOptions);
|
const rawChanges = await prisma.substitutionChange.findMany(prismaOptions);
|
||||||
|
Reference in New Issue
Block a user