Created a new system for the Groups that will persist after having entities

This commit is contained in:
Tiago Ribeiro
2024-09-25 16:18:43 +01:00
parent 8c392f8b49
commit dd94228672
18 changed files with 823 additions and 136 deletions

View File

@@ -8,11 +8,14 @@ import client from "@/lib/mongodb";
const db = client.db(process.env.MONGODB_DB);
export async function getUsers() {
return await db.collection("users").find<User>({}, { projection: { _id: 0 } }).toArray();
return await db
.collection("users")
.find<User>({}, {projection: {_id: 0}})
.toArray();
}
export async function getUser(id: string): Promise<User | undefined> {
const user = await db.collection("users").findOne<User>({id: id}, { projection: { _id: 0 } });
const user = await db.collection("users").findOne<User>({id: id}, {projection: {_id: 0}});
return !!user ? user : undefined;
}
@@ -21,7 +24,7 @@ export async function getSpecificUsers(ids: string[]) {
return await db
.collection("users")
.find<User>({id: {$in: ids}}, { projection: { _id: 0 } })
.find<User>({id: {$in: ids}}, {projection: {_id: 0}})
.toArray();
}
@@ -46,6 +49,7 @@ export async function getLinkedUsers(
.skip(page && size ? page * size : 0)
.limit(size || 0)
.toArray();
const total = await db.collection("users").countDocuments(filters);
return {users, total};
}