import { Injectable } from '@nestjs/common'; import { Reservation, ReservationDocument, } from '../schemas/reservation.schema'; import { Model } from 'mongoose'; import { InjectModel } from '@nestjs/mongoose'; @Injectable() export class ReservationsService { constructor( @InjectModel(Reservation.name) private readonly reservationModel: Model, ) {} create(reservation: ReservationDocument) { console.log(reservation); return this.reservationModel.create(reservation); } async findAll(): Promise { return this.reservationModel .find() .setOptions({ sanitizeFilter: true }) .exec(); } async findOne(id: string): Promise { return this.reservationModel.findOne({ _id: id }).exec(); } async findOneByDNI(dni: string): Promise { return this.reservationModel.findOne({ dni: dni }).exec(); } async update(id: string, reservation: ReservationDocument) { return this.reservationModel.findOneAndUpdate({ _id: id }, reservation, { new: true, }); } async remove(id: string) { return this.reservationModel.findByIdAndRemove({ _id: id }).exec(); } }