mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-17 03:05:13 +00:00
task: add space filter to bookings (#471)
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { IsNotEmpty, Matches } from 'class-validator';
|
import { IsNotEmpty, IsOptional, IsUUID, Matches } from 'class-validator';
|
||||||
|
|
||||||
export class BookingRequestDto {
|
export class BookingRequestDto {
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
@ -11,4 +11,13 @@ export class BookingRequestDto {
|
|||||||
message: 'Date must be in MM/YYYY format',
|
message: 'Date must be in MM/YYYY format',
|
||||||
})
|
})
|
||||||
month: string;
|
month: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'Space UUID',
|
||||||
|
example: '550e8400-e29b-41d4-a716-446655440000',
|
||||||
|
required: false,
|
||||||
|
})
|
||||||
|
@IsOptional()
|
||||||
|
@IsUUID('4')
|
||||||
|
space?: string;
|
||||||
}
|
}
|
||||||
|
@ -50,13 +50,16 @@ export class BookingService {
|
|||||||
return this.createBookings(space, userUuid, dto);
|
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 [monthNumber, year] = month.split('/').map(Number);
|
||||||
const fromDate = new Date(year, monthNumber - 1, 1);
|
const fromDate = new Date(year, monthNumber - 1, 1);
|
||||||
const toDate = new Date(year, monthNumber, 0, 23, 59, 59);
|
const toDate = new Date(year, monthNumber, 0, 23, 59, 59);
|
||||||
return this.bookingEntityRepository.find({
|
return this.bookingEntityRepository.find({
|
||||||
where: {
|
where: {
|
||||||
space: { community: { project: { uuid: project } } },
|
space: {
|
||||||
|
community: { project: { uuid: project } },
|
||||||
|
uuid: space ? space : undefined,
|
||||||
|
},
|
||||||
date: Between(fromDate, toDate),
|
date: Between(fromDate, toDate),
|
||||||
},
|
},
|
||||||
relations: ['space', 'user', 'user.inviteUser'],
|
relations: ['space', 'user', 'user.inviteUser'],
|
||||||
|
Reference in New Issue
Block a user