edit one business

This commit is contained in:
2026-05-31 16:39:55 +03:30
parent 390df394e9
commit a4e9761825
2 changed files with 24 additions and 13 deletions
+4 -2
View File
@@ -40,13 +40,15 @@ export class BookingsController {
@ApiQuery({ name: 'customerId', required: false }) @ApiQuery({ name: 'customerId', required: false })
@ApiQuery({ name: 'businessId', required: false }) @ApiQuery({ name: 'businessId', required: false })
@ApiQuery({ name: 'status', required: false, enum: BookingStatus }) @ApiQuery({ name: 'status', required: false, enum: BookingStatus })
@ApiQuery({ name: 'scope', required: false, enum: ['mine'] })
findAll( findAll(
@Query('customerId') customerId?: string, @Query('customerId') customerId?: string,
@Query('businessId') businessId?: string, @Query('businessId') businessId?: string,
@Query('status') status?: BookingStatus, @Query('status') status?: BookingStatus,
@Query('scope') scope?: 'mine',
@CurrentUser() user?: AuthUser, @CurrentUser() user?: AuthUser,
): Promise<BookingEntity[]> { ): Promise<BookingEntity[]> {
return this.service.findAll({ customerId, businessId, status }, user); return this.service.findAll({ customerId, businessId, status, scope }, user);
} }
@Get(':id') @Get(':id')
@@ -61,7 +63,7 @@ export class BookingsController {
@Post() @Post()
@UseGuards(JwtAuthGuard, RolesGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN, UserRole.CUSTOMER) @Roles(UserRole.ADMIN, UserRole.BUSINESS_OWNER, UserRole.CUSTOMER)
create( create(
@Body() payload: CreateBookingDto, @Body() payload: CreateBookingDto,
@CurrentUser() user: AuthUser, @CurrentUser() user: AuthUser,
+20 -11
View File
@@ -28,6 +28,7 @@ type FindAllFilters = {
customerId?: string; customerId?: string;
businessId?: string; businessId?: string;
status?: BookingStatus; status?: BookingStatus;
scope?: 'mine';
}; };
@Injectable() @Injectable()
@@ -69,9 +70,20 @@ export class BookingsService {
actorCustomerId: actor.id, actorCustomerId: actor.id,
}); });
} else if (actor?.role === UserRole.BUSINESS_OWNER) { } else if (actor?.role === UserRole.BUSINESS_OWNER) {
qb.andWhere('business.ownerId = :actorOwnerId', { qb.andWhere(
actorOwnerId: actor.id, '(business.ownerId = :actorOwnerId OR b.customerId = :actorCustomerId)',
}); { actorOwnerId: actor.id, actorCustomerId: actor.id },
);
} else if (actor?.role === UserRole.ADMIN) {
if (filters.scope === 'mine') {
qb.andWhere('b.customerId = :actorCustomerId', {
actorCustomerId: actor.id,
});
} else if (filters.customerId) {
qb.andWhere('b.customerId = :customerId', {
customerId: filters.customerId,
});
}
} else if (filters.customerId) { } else if (filters.customerId) {
qb.andWhere('b.customerId = :customerId', { qb.andWhere('b.customerId = :customerId', {
customerId: filters.customerId, customerId: filters.customerId,
@@ -106,11 +118,8 @@ export class BookingsService {
} }
async create(dto: CreateBookingDto, actor?: AuthUser): Promise<BookingEntity> { async create(dto: CreateBookingDto, actor?: AuthUser): Promise<BookingEntity> {
if ( if (actor && dto.customerId !== actor.id) {
actor?.role === UserRole.CUSTOMER && throw new ForbiddenException('You can only book for yourself');
dto.customerId !== actor.id
) {
throw new ForbiddenException('Customers can only book for themselves');
} }
const customer = await this.userRepo.findOne({ const customer = await this.userRepo.findOne({
@@ -452,7 +461,7 @@ export class BookingsService {
if ( if (
actor.role === UserRole.BUSINESS_OWNER && actor.role === UserRole.BUSINESS_OWNER &&
row.business?.ownerId === actor.id (row.business?.ownerId === actor.id || row.customerId === actor.id)
) { ) {
return; return;
} }
@@ -471,7 +480,7 @@ export class BookingsService {
if ( if (
actor.role === UserRole.BUSINESS_OWNER && actor.role === UserRole.BUSINESS_OWNER &&
row.business?.ownerId === actor.id (row.business?.ownerId === actor.id || row.customerId === actor.id)
) { ) {
return; return;
} }
@@ -486,7 +495,7 @@ export class BookingsService {
if ( if (
actor.role === UserRole.BUSINESS_OWNER && actor.role === UserRole.BUSINESS_OWNER &&
row.business?.ownerId === actor.id (row.business?.ownerId === actor.id || row.customerId === actor.id)
) { ) {
return; return;
} }