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: 'businessId', required: false })
@ApiQuery({ name: 'status', required: false, enum: BookingStatus })
@ApiQuery({ name: 'scope', required: false, enum: ['mine'] })
findAll(
@Query('customerId') customerId?: string,
@Query('businessId') businessId?: string,
@Query('status') status?: BookingStatus,
@Query('scope') scope?: 'mine',
@CurrentUser() user?: AuthUser,
): Promise<BookingEntity[]> {
return this.service.findAll({ customerId, businessId, status }, user);
return this.service.findAll({ customerId, businessId, status, scope }, user);
}
@Get(':id')
@@ -61,7 +63,7 @@ export class BookingsController {
@Post()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN, UserRole.CUSTOMER)
@Roles(UserRole.ADMIN, UserRole.BUSINESS_OWNER, UserRole.CUSTOMER)
create(
@Body() payload: CreateBookingDto,
@CurrentUser() user: AuthUser,
+20 -11
View File
@@ -28,6 +28,7 @@ type FindAllFilters = {
customerId?: string;
businessId?: string;
status?: BookingStatus;
scope?: 'mine';
};
@Injectable()
@@ -69,9 +70,20 @@ export class BookingsService {
actorCustomerId: actor.id,
});
} else if (actor?.role === UserRole.BUSINESS_OWNER) {
qb.andWhere('business.ownerId = :actorOwnerId', {
actorOwnerId: actor.id,
});
qb.andWhere(
'(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) {
qb.andWhere('b.customerId = :customerId', {
customerId: filters.customerId,
@@ -106,11 +118,8 @@ export class BookingsService {
}
async create(dto: CreateBookingDto, actor?: AuthUser): Promise<BookingEntity> {
if (
actor?.role === UserRole.CUSTOMER &&
dto.customerId !== actor.id
) {
throw new ForbiddenException('Customers can only book for themselves');
if (actor && dto.customerId !== actor.id) {
throw new ForbiddenException('You can only book for yourself');
}
const customer = await this.userRepo.findOne({
@@ -452,7 +461,7 @@ export class BookingsService {
if (
actor.role === UserRole.BUSINESS_OWNER &&
row.business?.ownerId === actor.id
(row.business?.ownerId === actor.id || row.customerId === actor.id)
) {
return;
}
@@ -471,7 +480,7 @@ export class BookingsService {
if (
actor.role === UserRole.BUSINESS_OWNER &&
row.business?.ownerId === actor.id
(row.business?.ownerId === actor.id || row.customerId === actor.id)
) {
return;
}
@@ -486,7 +495,7 @@ export class BookingsService {
if (
actor.role === UserRole.BUSINESS_OWNER &&
row.business?.ownerId === actor.id
(row.business?.ownerId === actor.id || row.customerId === actor.id)
) {
return;
}