actualiazar reportes microservicios
This commit is contained in:
parent
e2ab17004e
commit
7a82efdf42
|
@ -245,4 +245,30 @@ export class AppController {
|
||||||
) {
|
) {
|
||||||
return this.appService.findComment(paramComment);
|
return this.appService.findComment(paramComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// #==== API Report
|
||||||
|
|
||||||
|
@Post('report/createReport')
|
||||||
|
createReport(
|
||||||
|
@Body('action') action: string,
|
||||||
|
@Body('description') description: string,
|
||||||
|
@Body('date_entry') date_entry: Date,
|
||||||
|
@Body('user_id') user_id: string,
|
||||||
|
) {
|
||||||
|
return this.appService.createReport(action, description, date_entry, user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('report/allReports')
|
||||||
|
allReports() {
|
||||||
|
return this.appService.allReports();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('report/find/:id')
|
||||||
|
findReport(
|
||||||
|
@Param('id') paramReport: string
|
||||||
|
) {
|
||||||
|
return this.appService.findReport(paramReport);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -13,7 +13,7 @@ export class AppService {
|
||||||
@Inject('SERVICIO_PAGOS') private readonly clientPaymentApp: ClientProxy,
|
@Inject('SERVICIO_PAGOS') private readonly clientPaymentApp: ClientProxy,
|
||||||
@Inject('SERVICIO_RESERVACIONES') private readonly clientReservationApp: ClientProxy,
|
@Inject('SERVICIO_RESERVACIONES') private readonly clientReservationApp: ClientProxy,
|
||||||
@Inject('SERVICIO_POSTS') private readonly clientPostApp: ClientProxy,
|
@Inject('SERVICIO_POSTS') private readonly clientPostApp: ClientProxy,
|
||||||
|
@Inject('SERVICIO_REPORTES') private readonly clientReportApp: ClientProxy,
|
||||||
@Inject('SERVICIO_NOTIFICACIONES') private readonly clientNotificationtApp: ClientProxy,
|
@Inject('SERVICIO_NOTIFICACIONES') private readonly clientNotificationtApp: ClientProxy,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
@ -341,4 +341,42 @@ export class AppService {
|
||||||
map((message: string) => ({ message })),
|
map((message: string) => ({ message })),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====================== REPORTS ===============================
|
||||||
|
|
||||||
|
//Report parameter from API
|
||||||
|
createReport(action: string, description: string, date_entry: Date,
|
||||||
|
user_id: string) {
|
||||||
|
const pattern = { cmd: 'createReport' };
|
||||||
|
const payload = {
|
||||||
|
action: action, description: description, date_entry: date_entry,
|
||||||
|
user_id: user_id
|
||||||
|
};
|
||||||
|
return this.clientReportApp
|
||||||
|
.send<string>(pattern, payload)
|
||||||
|
.pipe(
|
||||||
|
map((message: string) => ({ message })),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
allReports() {
|
||||||
|
const pattern = { cmd: 'findAllReports' };
|
||||||
|
const payload = {};
|
||||||
|
return this.clientReportApp
|
||||||
|
.send<string>(pattern, payload)
|
||||||
|
.pipe(
|
||||||
|
map((message: string) => ({ message })),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//GET parameter from API
|
||||||
|
findReport(paramReportId: string) {
|
||||||
|
const pattern = { cmd: 'findOneReport' };
|
||||||
|
const payload = { id: paramReportId };
|
||||||
|
return this.clientReportApp
|
||||||
|
.send<string>(pattern, payload)
|
||||||
|
.pipe(
|
||||||
|
map((message: string) => ({ message })),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -17,16 +17,6 @@ import { ClientsModule, Transport } from "@nestjs/microservices";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]),
|
]),
|
||||||
ClientsModule.register([
|
|
||||||
{
|
|
||||||
name: "SERVICIO_PAGOS",
|
|
||||||
transport: Transport.TCP,
|
|
||||||
options: {
|
|
||||||
host: "127.0.0.1",
|
|
||||||
port: 3005
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]),
|
|
||||||
MongooseModule.forRoot(`mongodb+srv://proyecto_4:proyecto_4@proyecto4.yv4fb.mongodb.net/servicio_reportes?retryWrites=true&w=majority`),
|
MongooseModule.forRoot(`mongodb+srv://proyecto_4:proyecto_4@proyecto4.yv4fb.mongodb.net/servicio_reportes?retryWrites=true&w=majority`),
|
||||||
ReportsModule],
|
ReportsModule],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
|
|
|
@ -1,8 +1,18 @@
|
||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from "@nestjs/core";
|
||||||
import { AppModule } from './app.module';
|
import { Transport } from "@nestjs/microservices";
|
||||||
|
import { AppModule } from "./app.module";
|
||||||
|
import { Logger } from "@nestjs/common";
|
||||||
|
|
||||||
|
const logger = new Logger();
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.createMicroservice(AppModule, {
|
||||||
await app.listen(3000);
|
transport: Transport.TCP,
|
||||||
|
options: {
|
||||||
|
host: "127.0.0.1",
|
||||||
|
port: 3008
|
||||||
|
}
|
||||||
|
});
|
||||||
|
app.listen().then(() => logger.log("Microservice Reportes is listening" ));
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { Controller } from '@nestjs/common';
|
||||||
|
import { MessagePattern, Payload } from '@nestjs/microservices';
|
||||||
|
import { ReportsService } from './reports.service';
|
||||||
|
import { Report, ReportDocument } from '../schemas/report.schema';
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
export class ReportsController {
|
||||||
|
constructor(private readonly reportsService: ReportsService) {}
|
||||||
|
|
||||||
|
|
||||||
|
@MessagePattern({ cmd: 'createReport' })
|
||||||
|
create(@Payload() report: ReportDocument) {
|
||||||
|
return this.reportsService.create(report);
|
||||||
|
}
|
||||||
|
|
||||||
|
@MessagePattern({ cmd: 'findAllReports' })
|
||||||
|
findAll() {
|
||||||
|
return this.reportsService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@MessagePattern({ cmd: 'findOneReport' })
|
||||||
|
findOne(@Payload() id: string) {
|
||||||
|
let _id = id['id'];
|
||||||
|
return this.reportsService.findOne(_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@MessagePattern({ cmd: 'updateReport' })
|
||||||
|
update(@Payload() report: ReportDocument) {
|
||||||
|
return this.reportsService.update(report.id, report);
|
||||||
|
}
|
||||||
|
|
||||||
|
@MessagePattern({ cmd: 'removeReport' })
|
||||||
|
remove(@Payload() id: string) {
|
||||||
|
let _id = id['id'];
|
||||||
|
return this.reportsService.remove(_id);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ReportsService } from './reports.service';
|
||||||
|
import { ReportsController } from './reports.controller';
|
||||||
|
import { MongooseModule } from '@nestjs/mongoose';
|
||||||
|
import { Report, ReportSchema } from '../schemas/report.schema';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
MongooseModule.forFeature([{ name: Report.name, schema:ReportSchema }]),
|
||||||
|
],
|
||||||
|
controllers: [ReportsController],
|
||||||
|
providers: [ReportsService]
|
||||||
|
})
|
||||||
|
export class ReportsModule {}
|
|
@ -0,0 +1,41 @@
|
||||||
|
import { Injectable, Inject } from '@nestjs/common';
|
||||||
|
import { ClientProxy } from "@nestjs/microservices";
|
||||||
|
import { Model } from 'mongoose';
|
||||||
|
import { InjectModel } from '@nestjs/mongoose';
|
||||||
|
import { Report, ReportDocument } from '../schemas/report.schema';
|
||||||
|
import { map } from "rxjs/operators";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ReportsService {
|
||||||
|
constructor(
|
||||||
|
@InjectModel(Report.name) private readonly reportModel: Model<ReportDocument>,
|
||||||
|
|
||||||
|
//
|
||||||
|
) { }
|
||||||
|
|
||||||
|
async create(report: ReportDocument): Promise<Report> {
|
||||||
|
return this.reportModel.create(report);
|
||||||
|
}
|
||||||
|
|
||||||
|
async findAll(): Promise<Report[]> {
|
||||||
|
return this.reportModel
|
||||||
|
.find()
|
||||||
|
.setOptions({ sanitizeFilter: true })
|
||||||
|
.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
async findOne(id: string): Promise<Report> {
|
||||||
|
return this.reportModel.findOne({ _id: id }).exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async update(id: string, report: ReportDocument) {
|
||||||
|
return this.reportModel.findOneAndUpdate({ _id: id }, report, {
|
||||||
|
new: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async remove(id: string) {
|
||||||
|
return this.reportModel.findByIdAndRemove({ _id: id }).exec();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
||||||
|
import { Document, ObjectId } from 'mongoose';
|
||||||
|
|
||||||
|
|
||||||
|
export type ReportDocument = Report & Document;
|
||||||
|
|
||||||
|
@Schema({ collection: 'reports' })
|
||||||
|
export class Report {
|
||||||
|
|
||||||
|
@Prop()
|
||||||
|
action: string;
|
||||||
|
|
||||||
|
@Prop()
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
@Prop()
|
||||||
|
date_entry: Date;
|
||||||
|
|
||||||
|
@Prop()
|
||||||
|
user_id: string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const ReportSchema = SchemaFactory.createForClass(Report);
|
Loading…
Reference in New Issue