2022-07-01 10:15:02 +00:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-07-25 04:38:48 +00:00
|
|
|
import {
|
|
|
|
Reservation,
|
|
|
|
ReservationDocument,
|
|
|
|
} from '../schemas/reservation.schema';
|
2022-07-01 20:01:21 +00:00
|
|
|
import { Model } from 'mongoose';
|
|
|
|
import { InjectModel } from '@nestjs/mongoose';
|
2022-07-01 10:15:02 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ReservationsService {
|
2022-07-01 20:01:21 +00:00
|
|
|
constructor(
|
2022-07-25 04:38:48 +00:00
|
|
|
@InjectModel(Reservation.name)
|
|
|
|
private readonly reservationModel: Model<ReservationDocument>,
|
2022-07-01 20:01:21 +00:00
|
|
|
) {}
|
|
|
|
|
|
|
|
create(reservation: ReservationDocument) {
|
|
|
|
console.log(reservation);
|
|
|
|
|
|
|
|
return this.reservationModel.create(reservation);
|
|
|
|
}
|
|
|
|
|
2022-07-25 04:38:48 +00:00
|
|
|
async findAll(): Promise<Reservation[]> {
|
2022-07-01 20:01:21 +00:00
|
|
|
return this.reservationModel
|
2022-07-25 04:38:48 +00:00
|
|
|
.find()
|
|
|
|
.setOptions({ sanitizeFilter: true })
|
2022-07-01 20:01:21 +00:00
|
|
|
.exec();
|
2022-07-01 10:15:02 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 20:01:21 +00:00
|
|
|
async findOne(id: string): Promise<Reservation> {
|
|
|
|
return this.reservationModel.findOne({ _id: id }).exec();
|
2022-07-01 10:15:02 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 20:01:21 +00:00
|
|
|
async findOneByDNI(dni: string): Promise<Reservation> {
|
|
|
|
return this.reservationModel.findOne({ dni: dni }).exec();
|
2022-07-01 10:15:02 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 20:01:21 +00:00
|
|
|
async update(id: string, reservation: ReservationDocument) {
|
|
|
|
return this.reservationModel.findOneAndUpdate({ _id: id }, reservation, {
|
|
|
|
new: true,
|
|
|
|
});
|
2022-07-01 10:15:02 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 20:01:21 +00:00
|
|
|
async remove(id: string) {
|
2022-07-31 23:11:23 +00:00
|
|
|
return this.reservationModel.findOneAndUpdate({ _id: id }, {status: '-1'}, {
|
|
|
|
new: true,
|
|
|
|
});
|
2022-07-01 10:15:02 +00:00
|
|
|
}
|
|
|
|
}
|