diff --git a/server/src/booking/booking.service.ts b/server/src/booking/booking.service.ts index ef9229e..1c3d21a 100644 --- a/server/src/booking/booking.service.ts +++ b/server/src/booking/booking.service.ts @@ -4,9 +4,9 @@ import { Model } from 'mongoose'; import { CreateBookingDto } from './dto/create-booking.dto'; import { UpdateBookingDto } from './dto/update-booking.dto'; import { Booking, BookingDocument } from './entities/booking.entity'; -import { ShowTimesService } from 'src/show-times/show-times.service'; -import { PaypalService } from 'src/paypal/paypal.service'; -import { MoviesService } from 'src/movies/movies.service'; +import { ShowTimesService } from '../show-times/show-times.service'; +import { PaypalService } from '../paypal/paypal.service'; +import { MoviesService } from '../movies/movies.service'; @Injectable() export class BookingService { @@ -74,6 +74,25 @@ export class BookingService { return bookings; } + async findAllForUser(filter = {}): Promise { + const bookings = await this.bookingModel + .find( + filter, + Object.keys(this.bookingModel.schema.obj) + .map((key) => key) + .join(' '), + ) + .populate('userId') + .populate('movieId') + .populate('showTimeId') + .exec(); + + if (bookings.length === 0) { + throw new NotFoundException('No booking found matching the criteria'); + } + return bookings; + } + async findOne(filter: any): Promise { const booking = await this.bookingModel .findOne(