diff --git a/src/reserves/dto/find-reserves-query.dto.ts b/src/reserves/dto/find-reserves-query.dto.ts index 0025aa2..06356c7 100644 --- a/src/reserves/dto/find-reserves-query.dto.ts +++ b/src/reserves/dto/find-reserves-query.dto.ts @@ -21,4 +21,16 @@ export class FindReservesQueryDto { @IsOptional() @IsDateString() appointmentDate?: string; + + @IsOptional() + @IsDateString() + appointmentDateFrom?: string; + + @IsOptional() + @IsDateString() + appointmentDateTo?: string; + + @IsOptional() + @IsUUID() + serviceId?: string; } diff --git a/src/reserves/reserves.service.ts b/src/reserves/reserves.service.ts index 2366633..2d24381 100644 --- a/src/reserves/reserves.service.ts +++ b/src/reserves/reserves.service.ts @@ -132,6 +132,34 @@ export class ReservesService { appointmentDate: query.appointmentDate, }); } + if (query.appointmentDateFrom && query.appointmentDateTo) { + qb.andWhere( + 'reserve.appointmentDate BETWEEN :appointmentDateFrom AND :appointmentDateTo', + { + appointmentDateFrom: query.appointmentDateFrom, + appointmentDateTo: query.appointmentDateTo, + }, + ); + } else if (query.appointmentDateFrom) { + qb.andWhere('reserve.appointmentDate >= :appointmentDateFrom', { + appointmentDateFrom: query.appointmentDateFrom, + }); + } else if (query.appointmentDateTo) { + qb.andWhere('reserve.appointmentDate <= :appointmentDateTo', { + appointmentDateTo: query.appointmentDateTo, + }); + } + if (query.serviceId) { + qb.andWhere( + `EXISTS ( + SELECT 1 + FROM reserve_items serviceFilterItem + WHERE serviceFilterItem."reserveId" = reserve.id + AND serviceFilterItem."serviceId" = :serviceId + )`, + { serviceId: query.serviceId }, + ); + } if (!this.authorizationService.isAdmin(user)) { if (user.role === UserRole.SALON) {