Continued creating the entity system

This commit is contained in:
Tiago Ribeiro
2024-10-01 17:39:43 +01:00
parent bae02e5192
commit 564e6438cb
37 changed files with 2522 additions and 130 deletions

14
src/utils/roles.be.ts Normal file
View File

@@ -0,0 +1,14 @@
import {Role} from "@/interfaces/entity";
import client from "@/lib/mongodb";
const db = client.db(process.env.MONGODB_DB);
export const getRolesByEntities = async (entityIDs: string[]) =>
await db
.collection("roles")
.find<Role>({entityID: {$in: entityIDs}})
.toArray();
export const getRolesByEntity = async (entityID: string) => await db.collection("roles").find<Role>({entityID}).toArray();
export const getRole = async (id: string) => (await db.collection("roles").findOne<Role>({id})) ?? undefined;