35 lines
1018 B
TypeScript
35 lines
1018 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { Booking } from './entities/booking.entity';
|
|
import { CreateBookingDto } from './dto/create-booking.dto';
|
|
|
|
@Injectable()
|
|
export class BookingsService {
|
|
constructor(
|
|
@InjectRepository(Booking)
|
|
private readonly bookingRepository: Repository<Booking>,
|
|
) {}
|
|
|
|
async create(dto: CreateBookingDto): Promise<Booking> {
|
|
const booking = this.bookingRepository.create(dto);
|
|
return this.bookingRepository.save(booking);
|
|
}
|
|
|
|
async findByClub(clubId: string): Promise<Booking[]> {
|
|
return this.bookingRepository.find({
|
|
where: { clubId },
|
|
relations: ['user', 'drink'],
|
|
order: { createdAt: 'DESC' },
|
|
});
|
|
}
|
|
|
|
async findByUserAndClub(userId: string, clubId: string): Promise<Booking[]> {
|
|
return this.bookingRepository.find({
|
|
where: { userId, clubId },
|
|
relations: ['drink'],
|
|
order: { createdAt: 'DESC' },
|
|
});
|
|
}
|
|
}
|