31 lines
906 B
TypeScript
31 lines
906 B
TypeScript
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 SubscriptionPolicy {
|
|
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;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
canPurchase(user: AuthUser, salon: Salon): boolean {
|
|
if (this.authorizationService.isAdmin(user)) {
|
|
return true;
|
|
}
|
|
if (user.role === UserRole.SALON) {
|
|
return salon.ownerId === user.id;
|
|
}
|
|
return false;
|
|
}
|
|
}
|