Updated the pagination on the useUsers and migrading the grading

This commit is contained in:
Tiago Ribeiro
2024-09-07 16:53:58 +01:00
parent 417c9176fe
commit 56f374bbfe
5 changed files with 45 additions and 41 deletions

View File

@@ -44,13 +44,18 @@ export async function getSpecificUsers(ids: string[]) {
.toArray();
}
export async function getLinkedUsers(userID?: string, userType?: Type, type?: Type, firstID?: string, lastID?: string, size?: number) {
export async function getLinkedUsers(userID?: string, userType?: Type, type?: Type, page?: number, size?: number) {
const filters = {
...(!!type ? {type} : {}),
};
if (!userID || userType === "admin" || userType === "developer") {
const users = await db.collection("users").find<User>(filters).toArray();
const users = await db
.collection("users")
.find<User>(filters)
.skip(page && size ? page * size : 0)
.limit(size || 0)
.toArray();
const total = await db.collection("users").countDocuments(filters);
return {users, total};
}
@@ -71,6 +76,8 @@ export async function getLinkedUsers(userID?: string, userType?: Type, type?: Ty
const users = await db
.collection("users")
.find<User>({...filters, id: {$in: participants}})
.skip(page && size ? page * size : 0)
.limit(size || 0)
.toArray();
const total = await db.collection("users").countDocuments({...filters, id: {$in: participants}});