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
+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;
}