2023-05-26 15:43:14 -05:00
|
|
|
import { Injectable } from '@nestjs/common'
|
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm'
|
|
|
|
|
import { Repository } from 'typeorm'
|
2023-06-29 10:32:09 +02:00
|
|
|
|
2023-05-26 15:43:14 -05:00
|
|
|
import dayjs from '../common/dayjs'
|
2023-06-29 10:32:09 +02:00
|
|
|
import { Reservation } from './entity'
|
2023-05-26 15:43:14 -05:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class ReservationsService {
|
|
|
|
|
constructor(
|
|
|
|
|
@InjectRepository(Reservation)
|
|
|
|
|
private reservationsRepository: Repository<Reservation>,
|
|
|
|
|
) {}
|
|
|
|
|
|
2023-07-29 15:23:04 +02:00
|
|
|
async getAll() {
|
|
|
|
|
return await this.reservationsRepository.find()
|
2023-05-26 15:43:14 -05:00
|
|
|
}
|
|
|
|
|
|
2023-07-29 15:23:04 +02:00
|
|
|
async getById(id: string) {
|
|
|
|
|
return await this.reservationsRepository.findOneBy({ id })
|
2023-05-26 15:43:14 -05:00
|
|
|
}
|
|
|
|
|
|
2023-07-29 15:23:04 +02:00
|
|
|
async getByDate(date = dayjs()) {
|
|
|
|
|
return await this.reservationsRepository
|
2023-06-27 16:06:19 +02:00
|
|
|
.createQueryBuilder()
|
2023-05-26 15:43:14 -05:00
|
|
|
.where(`DATE(dateRangeStart, '-7 day') = DATE(:date)`, { date })
|
|
|
|
|
.getMany()
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-29 15:23:04 +02:00
|
|
|
async getByDateOnWaitingList(date = dayjs()) {
|
|
|
|
|
return await this.reservationsRepository
|
2023-07-29 10:49:44 +02:00
|
|
|
.createQueryBuilder()
|
|
|
|
|
.where(`DATE(dateRangeStart, '-7 day') = DATE(:date)`, { date })
|
|
|
|
|
.andWhere('waitListed = true')
|
|
|
|
|
.getMany()
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-29 15:23:04 +02:00
|
|
|
async create(reservation: Reservation) {
|
|
|
|
|
return await this.reservationsRepository.save(reservation)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async update(reservationId: string, update: Partial<Reservation>) {
|
|
|
|
|
return await this.reservationsRepository.update(reservationId, update)
|
2023-05-26 15:43:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async deleteById(id: string) {
|
2023-07-29 15:23:04 +02:00
|
|
|
return await this.reservationsRepository.delete({ id })
|
2023-05-26 15:43:14 -05:00
|
|
|
}
|
|
|
|
|
}
|