reserves module

This commit is contained in:
2026-06-29 08:39:34 +03:30
parent 127c1eaf78
commit d8086cab17
15 changed files with 871 additions and 0 deletions
@@ -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);
}
}