ENCOA-316 ENCOA-317:

Refactor components to remove Layout wrapper and pass it in the App component , implemented a skeleton feedback while loading page and improved API calls related to Dashboard/User Profile
This commit is contained in:
José Marques Lima
2025-01-25 19:38:29 +00:00
parent 4d788e13b4
commit 37216e2a5a
56 changed files with 4440 additions and 2979 deletions

View File

@@ -27,13 +27,72 @@ export const getAssignment = async (id: string) => {
return await db.collection("assignments").findOne<Assignment>({ id });
};
export const getAssignmentsByAssignee = async (id: string, filter?: { [key in keyof Partial<Assignment>]: any }) => {
return await db
.collection("assignments")
.find<Assignment>({ assignees: id, ...(!filter ? {} : filter) })
export const getAssignmentsByAssignee = async (id: string, filter?: {}, projection?: {}, sort?: {}) => {
return await db.collection("assignments")
.aggregate([
{ $match: { assignees: id, ...(!filter ? {} : filter) } },
...(sort ? [{ $sort: sort }] : []),
...(projection ? [{ $project: projection }] : []),
])
.toArray();
};
export const getAssignmentsForStudent = async (id: string, currentDate: string) => {
return await db.collection("assignments")
.aggregate([{
$match: {
assignees: id, archived: { $ne: true },
endDate: { $gte: currentDate },
$or: [
{ autoStart: true, startDate: { $lt: currentDate } },
{ start: true },
],
}
},
{ $sort: { startDate: 1 } },
{
$project: {
id: 1,
name: 1,
startDate: 1,
endDate: 1,
exams: {
$sortArray: {
input: {
$filter: {
input: "$exams",
as: "exam",
cond: { $eq: ["$$exam.assignee", id] },
},
},
sortBy: { module: 1 },
},
},
hasResults: {
$cond: {
if: {
$gt: [
{
$size: {
$filter: {
input: "$results",
as: "result",
cond: { $eq: ["$$result.userId", id] },
},
},
},
0,
],
},
then: true,
else: false,
},
}
}
}
]).toArray()
};
export const getAssignmentsByAssignerBetweenDates = async (id: string, startDate: Date, endDate: Date) => {
return await db.collection("assignments").find<Assignment>({ assigner: id }).toArray();
};