reserves module
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthUser } from '../../auth/interfaces/auth-user.interface';
|
||||
import { UserRole } from '../../users/enums/user-role.enum';
|
||||
import { Reserve } from '../../reserves/entities/reserve.entity';
|
||||
import { AuthorizationService } from '../authorization.service';
|
||||
|
||||
@Injectable()
|
||||
export class ReservePolicy {
|
||||
constructor(private readonly authorizationService: AuthorizationService) {}
|
||||
|
||||
canCreate(user: AuthUser, reserve: Pick<Reserve, 'salon' | 'customer'>): boolean {
|
||||
if (this.authorizationService.isAdmin(user)) {
|
||||
return true;
|
||||
}
|
||||
if (user.role === UserRole.SALON) {
|
||||
return reserve.salon.ownerId === user.id;
|
||||
}
|
||||
if (user.role === UserRole.CUSTOMER) {
|
||||
return reserve.customer.userId === user.id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
canRead(user: AuthUser, reserve: Reserve): boolean {
|
||||
if (this.authorizationService.isAdmin(user)) {
|
||||
return true;
|
||||
}
|
||||
if (user.role === UserRole.SALON) {
|
||||
return reserve.salon.ownerId === user.id;
|
||||
}
|
||||
if (user.role === UserRole.CUSTOMER) {
|
||||
return reserve.customer.userId === user.id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
canUpdate(user: AuthUser, reserve: Reserve): boolean {
|
||||
return this.canRead(user, reserve);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user