Started working on the assignments page

This commit is contained in:
Tiago Ribeiro
2024-10-02 19:20:05 +01:00
parent 564e6438cb
commit 3d4a604aa2
25 changed files with 2225 additions and 688 deletions

View File

@@ -23,6 +23,10 @@ export const getAssignments = async () => {
return await db.collection("assignments").find<Assignment>({}).toArray();
};
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")

View File

@@ -84,6 +84,12 @@ export const getAllAssignersByCorporate = async (corporateID: string, type: Type
return [...linkedTeachers.users.map((x) => x.id), ...linkedCorporates.users.map((x) => x.id)];
};
export const getGroupsForEntities = async (ids: string[]) =>
await db
.collection("groups")
.find<Group>({entity: {$in: ids}})
.toArray();
export const getGroupsForUser = async (admin?: string, participant?: string) => {
if (admin && participant) return await db.collection("groups").find<Group>({admin, participant}).toArray();

View File

@@ -44,10 +44,7 @@ export const convertBase64 = (file: File) => {
});
};
export const mapBy = <T>(obj: T[], key: keyof T) => {
if (!obj) return undefined;
return obj.map((i) => i[key]);
};
export const mapBy = <T>(obj: T[] | undefined, key: keyof T) => (obj || []).map((i) => i[key]);
export const filterBy = <T>(obj: T[], key: keyof T, value: any) => obj.filter((i) => i[key] === value);
export const serialize = <T>(obj: T): T => JSON.parse(JSON.stringify(obj));