Did the same to all of the dashboards

This commit is contained in:
Tiago Ribeiro
2024-09-06 15:35:26 +01:00
parent de35e1a8b7
commit 4530e4079f
12 changed files with 237 additions and 241 deletions

View File

@@ -53,8 +53,15 @@ export async function getSpecificUsers(ids: string[]) {
}
export async function getLinkedUsers(userID?: string, userType?: Type, type?: Type, page?: number, size?: number) {
const q = [
...(!!type ? [where("type", "==", type)] : []),
orderBy(documentId()),
...(page !== undefined && !!size ? [startAt(page * size)] : []),
...(page !== undefined && !!size ? [limit(page + 1 * size)] : []),
];
if (!userID || userType === "admin" || userType === "developer") {
const snapshot = await getDocs(collection(db, "users"));
const snapshot = await getDocs(query(collection(db, "users"), ...q));
const users = snapshot.docs.map((doc) => ({
id: doc.id,
...doc.data(),
@@ -73,15 +80,7 @@ export async function getLinkedUsers(userID?: string, userType?: Type, type?: Ty
...(userType === "teacher" ? belongingGroups.flatMap((x) => x.participants) : []),
]);
const q = [
where(documentId(), "in", participants),
...(!!type ? [where("type", "==", type)] : []),
orderBy(documentId()),
...(page !== undefined && !!size ? [startAt(page * size)] : []),
...(page !== undefined && !!size ? [limit(page + 1 * size)] : []),
];
const snapshot = await getDocs(query(collection(db, "users"), ...q));
const snapshot = await getDocs(query(collection(db, "users"), ...[where(documentId(), "in", participants), ...q]));
const users = snapshot.docs.map((doc) => ({
id: doc.id,
...doc.data(),