This commit is contained in:
2026-06-28 20:32:52 +03:30
parent 7a5b3f0bea
commit bf35179d55
45 changed files with 1555 additions and 46 deletions
@@ -0,0 +1,30 @@
import { Injectable } from '@nestjs/common';
import { AuthUser } from '../../auth/interfaces/auth-user.interface';
import { Customer } from '../../customers/entities/customer.entity';
import { UserRole } from '../../users/enums/user-role.enum';
import { AuthorizationService } from '../authorization.service';
@Injectable()
export class CustomerPolicy {
constructor(private readonly authorizationService: AuthorizationService) {}
canRead(user: AuthUser, customer: Customer): boolean {
if (this.authorizationService.isAdmin(user)) {
return true;
}
if (user.role === UserRole.CUSTOMER) {
return customer.userId === user.id;
}
return false;
}
canUpdate(user: AuthUser, customer: Customer): boolean {
if (this.authorizationService.isAdmin(user)) {
return true;
}
if (user.role === UserRole.CUSTOMER) {
return customer.userId === user.id;
}
return false;
}
}
@@ -0,0 +1,43 @@
import { Injectable } from '@nestjs/common';
import { AuthUser } from '../../auth/interfaces/auth-user.interface';
import { Salon } from '../../salons/entities/salon.entity';
import { UserRole } from '../../users/enums/user-role.enum';
import { AuthorizationService } from '../authorization.service';
@Injectable()
export class SalonPolicy {
constructor(private readonly authorizationService: AuthorizationService) {}
canRead(user: AuthUser, salon: Salon): boolean {
if (this.authorizationService.isAdmin(user)) {
return true;
}
if (user.role === UserRole.SALON) {
return salon.ownerId === user.id;
}
if (user.role === UserRole.CUSTOMER) {
return true;
}
return false;
}
canUpdate(user: AuthUser, salon: Salon): boolean {
if (this.authorizationService.isAdmin(user)) {
return true;
}
if (user.role === UserRole.SALON) {
return salon.ownerId === user.id;
}
return false;
}
canDelete(user: AuthUser, salon: Salon): boolean {
if (this.authorizationService.isAdmin(user)) {
return true;
}
if (user.role === UserRole.SALON) {
return salon.ownerId === user.id;
}
return false;
}
}