fixes schemas de reservaciones
This commit is contained in:
parent
9ebe0be4d0
commit
c54fc6880b
|
@ -170,4 +170,31 @@ export class AppController {
|
||||||
) {
|
) {
|
||||||
return this.appService.findPayment(paramPaymentDNI);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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 })),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,35 +1,38 @@
|
||||||
import { Controller } from '@nestjs/common';
|
import { Controller } from '@nestjs/common';
|
||||||
import { MessagePattern, Payload } from '@nestjs/microservices';
|
import { MessagePattern, Payload } from '@nestjs/microservices';
|
||||||
import { ReservationsService } from './reservations.service';
|
import { ReservationsService } from './reservations.service';
|
||||||
import { Reservation, ReservationDocument} from '../schemas/reservation.schema';
|
import { Reservation, ReservationDocument } from '../schemas/reservation.schema';
|
||||||
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class ReservationsController {
|
export class ReservationsController {
|
||||||
constructor(private readonly reservationsService: ReservationsService) {}
|
constructor(private readonly reservationsService: ReservationsService) { }
|
||||||
|
|
||||||
@MessagePattern({cmd:'createReservation'})
|
@MessagePattern({ cmd: 'createReservation' })
|
||||||
create(@Payload() reservation: ReservationDocument) {
|
create(@Payload() reservation: ReservationDocument) {
|
||||||
return this.reservationsService.create(reservation);
|
return this.reservationsService.create(reservation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern({cmd: 'findAllReservations'})
|
@MessagePattern({ cmd: 'findAllReservations' })
|
||||||
findAll() {
|
findAll() {
|
||||||
|
console.log(this.reservationsService.findAll());
|
||||||
|
|
||||||
return this.reservationsService.findAll();
|
return this.reservationsService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern({cmd: 'findOneReservation'})
|
@MessagePattern({ cmd: 'findOneReservation' })
|
||||||
findOne(@Payload() id: number) {
|
findOne(@Payload() id: string) {
|
||||||
return this.reservationsService.findOne(id);
|
let _id = id['id'];
|
||||||
|
return this.reservationsService.findOne(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern({cmd: 'updateReservation'})
|
@MessagePattern({ cmd: 'updateReservation' })
|
||||||
update(@Payload() reservation: ReservationDocument) {
|
update(@Payload() reservation: ReservationDocument) {
|
||||||
return this.reservationsService.update(reservation.id, reservation);
|
return this.reservationsService.update(reservation.id, reservation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern({cmd: 'removeReservation'})
|
@MessagePattern({ cmd: 'removeReservation' })
|
||||||
remove(@Payload() id: number) {
|
remove(@Payload() id: string) {
|
||||||
return this.reservationsService.remove(id);
|
let _id = id['id'];
|
||||||
|
return this.reservationsService.remove(_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { ReservationsService } from './reservations.service';
|
import { ReservationsService } from './reservations.service';
|
||||||
|
import { MongooseModule } from '@nestjs/mongoose';
|
||||||
|
|
||||||
import { ReservationsController } from './reservations.controller';
|
import { ReservationsController } from './reservations.controller';
|
||||||
|
import { Reservation, ReservationSchema} from '../schemas/reservation.schema';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
imports: [
|
||||||
|
MongooseModule.forFeature([{ name: Reservation.name, schema: ReservationSchema }]),
|
||||||
|
],
|
||||||
controllers: [ReservationsController],
|
controllers: [ReservationsController],
|
||||||
providers: [ReservationsService]
|
providers: [ReservationsService]
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,25 +1,42 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Reservation, ReservationDocument} from '../schemas/reservation.schema';
|
import { Reservation, ReservationDocument} from '../schemas/reservation.schema';
|
||||||
|
import { Model } from 'mongoose';
|
||||||
|
import { InjectModel } from '@nestjs/mongoose';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ReservationsService {
|
export class ReservationsService {
|
||||||
create(Reservation: ReservationDocument) {
|
constructor(
|
||||||
return 'This action adds a new reservation';
|
@InjectModel(Reservation.name) private readonly reservationModel: Model<ReservationDocument>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
create(reservation: ReservationDocument) {
|
||||||
|
console.log(reservation);
|
||||||
|
|
||||||
|
return this.reservationModel.create(reservation);
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll() {
|
async findAll(): Promise<Reservation[]> {
|
||||||
return `This action returns all reservations`;
|
return this.reservationModel
|
||||||
|
.find()
|
||||||
|
.setOptions({ sanitizeFilter: true })
|
||||||
|
.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(id: number) {
|
async findOne(id: string): Promise<Reservation> {
|
||||||
return `This action returns a #${id} reservation`;
|
return this.reservationModel.findOne({ _id: id }).exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
update(id: number, Reservation: ReservationDocument) {
|
async findOneByDNI(dni: string): Promise<Reservation> {
|
||||||
return `This action updates a #${id} reservation`;
|
return this.reservationModel.findOne({ dni: dni }).exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(id: number) {
|
async update(id: string, reservation: ReservationDocument) {
|
||||||
return `This action removes a #${id} reservation`;
|
return this.reservationModel.findOneAndUpdate({ _id: id }, reservation, {
|
||||||
|
new: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async remove(id: string) {
|
||||||
|
return this.reservationModel.findByIdAndRemove({ _id: id }).exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,31 @@
|
||||||
|
|
||||||
|
|
||||||
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
||||||
import { Document } from 'mongoose';
|
import { Document, ObjectId } from 'mongoose';
|
||||||
|
|
||||||
|
|
||||||
export type ReservationDocument = Reservation & Document;
|
export type ReservationDocument = Reservation & Document;
|
||||||
|
|
||||||
|
@Schema({ collection: 'reservations' })
|
||||||
export class Reservation {
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue