task: add space filter to bookings (#471)

This commit is contained in:
ZaydSkaff
2025-07-15 13:31:56 +03:00
committed by GitHub
parent e5970c02c1
commit 036c8bea17
2 changed files with 15 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, Matches } from 'class-validator';
import { IsNotEmpty, IsOptional, IsUUID, Matches } from 'class-validator';
export class BookingRequestDto {
@ApiProperty({
@ -11,4 +11,13 @@ export class BookingRequestDto {
message: 'Date must be in MM/YYYY format',
})
month: string;
@ApiProperty({
description: 'Space UUID',
example: '550e8400-e29b-41d4-a716-446655440000',
required: false,
})
@IsOptional()
@IsUUID('4')
space?: string;
}

View File

@ -50,13 +50,16 @@ export class BookingService {
return this.createBookings(space, userUuid, dto);
}
async findAll({ month }: BookingRequestDto, project: string) {
async findAll({ month, space }: BookingRequestDto, project: string) {
const [monthNumber, year] = month.split('/').map(Number);
const fromDate = new Date(year, monthNumber - 1, 1);
const toDate = new Date(year, monthNumber, 0, 23, 59, 59);
return this.bookingEntityRepository.find({
where: {
space: { community: { project: { uuid: project } } },
space: {
community: { project: { uuid: project } },
uuid: space ? space : undefined,
},
date: Between(fromDate, toDate),
},
relations: ['space', 'user', 'user.inviteUser'],