katoikia-app/servicio-reservaciones/src/reservations/reservations.service.ts

47 lines
1.2 KiB
TypeScript

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<ReservationDocument>,
) {}
create(reservation: ReservationDocument) {
console.log(reservation);
return this.reservationModel.create(reservation);
}
async findAll(): Promise<Reservation[]> {
return this.reservationModel
.find()
.setOptions({ sanitizeFilter: true })
.exec();
}
async findOne(id: string): Promise<Reservation> {
return this.reservationModel.findOne({ _id: id }).exec();
}
async findOneByDNI(dni: string): Promise<Reservation> {
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();
}
}