customers

This commit is contained in:
2026-07-07 20:35:14 +03:30
parent 94367752a2
commit 9fdc81bff1
11 changed files with 720 additions and 3 deletions
+9 -1
View File
@@ -1,5 +1,6 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { SalonCustomer } from '../customers/entities/salon-customer.entity';
import { Reserve } from '../reserves/entities/reserve.entity';
import { AuthorizationService } from './authorization.service';
import { Permission } from './entities/permission.entity';
@@ -13,7 +14,14 @@ import { StylistPolicy } from './policies/stylist.policy';
import { SubscriptionPolicy } from './policies/subscription.policy';
@Module({
imports: [TypeOrmModule.forFeature([Permission, UserPermission, Reserve])],
imports: [
TypeOrmModule.forFeature([
Permission,
UserPermission,
Reserve,
SalonCustomer,
]),
],
providers: [
AuthorizationService,
SalonPolicy,
+19 -1
View File
@@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AuthUser } from '../../auth/interfaces/auth-user.interface';
import { Customer } from '../../customers/entities/customer.entity';
import { SalonCustomer } from '../../customers/entities/salon-customer.entity';
import { Reserve } from '../../reserves/entities/reserve.entity';
import { UserRole } from '../../users/enums/user-role.enum';
import { AuthorizationService } from '../authorization.service';
@@ -13,6 +14,8 @@ export class CustomerPolicy {
private readonly authorizationService: AuthorizationService,
@InjectRepository(Reserve)
private readonly reservesRepository: Repository<Reserve>,
@InjectRepository(SalonCustomer)
private readonly salonCustomersRepository: Repository<SalonCustomer>,
) {}
async canRead(user: AuthUser, customer: Customer): Promise<boolean> {
@@ -23,7 +26,10 @@ export class CustomerPolicy {
return customer.userId === user.id;
}
if (user.role === UserRole.SALON) {
return this.hasReserveAtSalon(customer.id, user.id);
return (
(await this.hasReserveAtSalon(customer.id, user.id)) ||
(await this.hasLinkAtSalon(customer.id, user.id))
);
}
return false;
}
@@ -49,4 +55,16 @@ export class CustomerPolicy {
},
});
}
private async hasLinkAtSalon(
customerId: string,
salonOwnerId: string,
): Promise<boolean> {
return this.salonCustomersRepository.exists({
where: {
customerId,
salon: { ownerId: salonOwnerId },
},
});
}
}