Skip to content
Snippets Groups Projects
Commit e883c7c9 authored by michael.minelli's avatar michael.minelli
Browse files

EnonceManager => Add function to verify access possibility

parent f31d3eea
No related branches found
No related tags found
No related merge requests found
import { Prisma } from '@prisma/client';
import { Enonce } from '../types/DatabaseTypes';
import { Enonce, User } from '../types/DatabaseTypes';
import db from '../helpers/DatabaseHelper';
class EnonceManager {
private static _instance: EnonceManager;
private constructor() { }
public static get instance(): EnonceManager {
if ( !EnonceManager._instance ) {
EnonceManager._instance = new EnonceManager();
async isUserAllowedToAccessEnonce(enonce: Enonce, user: User): Promise<boolean> {
if ( !enonce.staff ) {
enonce.staff = await db.enonce.findUnique({
where: {
name: enonce.name
}
return EnonceManager._instance;
}).staff();
}
return enonce.staff.findIndex(staff => staff.id === user.id) !== -1;
}
async getByName(name: string, include: Prisma.EnonceInclude | undefined = undefined): Promise<Enonce | undefined> {
......@@ -38,4 +37,4 @@ class EnonceManager {
}
export default EnonceManager.instance;
export default new EnonceManager();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment