fixes schemas de reservaciones

This commit is contained in:
Mariela 2022-07-01 14:01:21 -06:00
parent 9ebe0be4d0
commit c54fc6880b
6 changed files with 133 additions and 23 deletions

View File

@ -170,4 +170,31 @@ export class AppController {
) {
return this.appService.findPayment(paramPaymentDNI);
}
// #==== API Payment
//#API userService - create user
@Post('reservation/createReservation')
createReservation(
@Body('start_time') start_time: string,
@Body('finish_time') finish_time: string,
@Body('status') status: string,
@Body('date_entry') date_entry: Date,
@Body('user_id') user_id: string,
@Body('common_area_id') common_area_id: string,
) {
return this.appService.createReservation(start_time, finish_time, status,
date_entry, user_id, common_area_id);
}
@Get('reservation/allReservations')
allReservations() {
return this.appService.allReservations();
}
@Get('reservation/find/:id')
findReservation(
@Param('id') paramReservation: string
) {
return this.appService.findReservation(paramReservation);
}
}

View File

@ -226,4 +226,44 @@ export class AppService {
}
// ====================== RESERVATIONS ===============================
//POST parameter from API
createReservation(start_time: string, finish_time: string, status: string,
date_entry: Date, user_id: string, common_area_id: string) {
const pattern = { cmd: 'createReservation' };
const payload = {
start_time: start_time, finish_time: finish_time, status: status,
date_entry: date_entry, user_id: user_id, common_area_id: common_area_id
};
return this.clientReservationApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
allReservations() {
const pattern = { cmd: 'findAllReservations' };
const payload = {};
return this.clientReservationApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
//GET parameter from API
findReservation(paramReservationId: string) {
const pattern = { cmd: 'findOneReservation' };
const payload = { id: paramReservationId };
return this.clientReservationApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
}

View File

@ -3,7 +3,6 @@ import { MessagePattern, Payload } from '@nestjs/microservices';
import { ReservationsService } from './reservations.service';
import { Reservation, ReservationDocument } from '../schemas/reservation.schema';
@Controller()
export class ReservationsController {
constructor(private readonly reservationsService: ReservationsService) { }
@ -15,12 +14,15 @@ export class ReservationsController {
@MessagePattern({ cmd: 'findAllReservations' })
findAll() {
console.log(this.reservationsService.findAll());
return this.reservationsService.findAll();
}
@MessagePattern({ cmd: 'findOneReservation' })
findOne(@Payload() id: number) {
return this.reservationsService.findOne(id);
findOne(@Payload() id: string) {
let _id = id['id'];
return this.reservationsService.findOne(_id);
}
@MessagePattern({ cmd: 'updateReservation' })
@ -29,7 +31,8 @@ export class ReservationsController {
}
@MessagePattern({ cmd: 'removeReservation' })
remove(@Payload() id: number) {
return this.reservationsService.remove(id);
remove(@Payload() id: string) {
let _id = id['id'];
return this.reservationsService.remove(_id);
}
}

View File

@ -1,8 +1,14 @@
import { Module } from '@nestjs/common';
import { ReservationsService } from './reservations.service';
import { MongooseModule } from '@nestjs/mongoose';
import { ReservationsController } from './reservations.controller';
import { Reservation, ReservationSchema} from '../schemas/reservation.schema';
@Module({
imports: [
MongooseModule.forFeature([{ name: Reservation.name, schema: ReservationSchema }]),
],
controllers: [ReservationsController],
providers: [ReservationsService]
})

View File

@ -1,25 +1,42 @@
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 {
create(Reservation: ReservationDocument) {
return 'This action adds a new reservation';
constructor(
@InjectModel(Reservation.name) private readonly reservationModel: Model<ReservationDocument>,
) {}
create(reservation: ReservationDocument) {
console.log(reservation);
return this.reservationModel.create(reservation);
}
findAll() {
return `This action returns all reservations`;
async findAll(): Promise<Reservation[]> {
return this.reservationModel
.find()
.setOptions({ sanitizeFilter: true })
.exec();
}
findOne(id: number) {
return `This action returns a #${id} reservation`;
async findOne(id: string): Promise<Reservation> {
return this.reservationModel.findOne({ _id: id }).exec();
}
update(id: number, Reservation: ReservationDocument) {
return `This action updates a #${id} reservation`;
async findOneByDNI(dni: string): Promise<Reservation> {
return this.reservationModel.findOne({ dni: dni }).exec();
}
remove(id: number) {
return `This action removes a #${id} reservation`;
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();
}
}

View File

@ -1,14 +1,31 @@
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
import { Document, ObjectId } from 'mongoose';
export type ReservationDocument = Reservation & Document;
@Schema({ collection: 'reservations' })
export class Reservation {
@Prop()
start_time: string;
@Prop()
finish_time: string;
@Prop()
status: string;
@Prop()
date_entry: Date;
@Prop()
common_area_id: string;
@Prop()
user_id: string
}