From 73f8ae04df34ce6486f9201069beded615a7bc4d Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 1 Jul 2022 03:59:39 -0600 Subject: [PATCH] update microservice-notificaciones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit agregar conexión con api gateway y generar recursos de microservicio --- api-gateway/src/app.module.ts | 11 ++ api-gateway/src/app.service.ts | 2 + servicio-notificaciones/package-lock.json | 170 +++++++++++++++++- servicio-notificaciones/package.json | 6 +- .../src/app.controller.spec.ts | 22 --- servicio-notificaciones/src/app.controller.ts | 5 +- servicio-notificaciones/src/app.module.ts | 19 +- servicio-notificaciones/src/app.service.ts | 8 - servicio-notificaciones/src/main.ts | 20 ++- .../dto/create-notification.dto.ts | 1 + .../dto/update-notification.dto.ts | 6 + .../notifications.controller.spec.ts | 20 +++ .../notifications/notifications.controller.ts | 35 ++++ .../src/notifications/notifications.module.ts | 9 + .../notifications.service.spec.ts | 18 ++ .../notifications/notifications.service.ts | 26 +++ .../schemas/notification.schemas.ts | 1 + 17 files changed, 332 insertions(+), 47 deletions(-) delete mode 100644 servicio-notificaciones/src/app.controller.spec.ts delete mode 100644 servicio-notificaciones/src/app.service.ts create mode 100644 servicio-notificaciones/src/notifications/dto/create-notification.dto.ts create mode 100644 servicio-notificaciones/src/notifications/dto/update-notification.dto.ts create mode 100644 servicio-notificaciones/src/notifications/notifications.controller.spec.ts create mode 100644 servicio-notificaciones/src/notifications/notifications.controller.ts create mode 100644 servicio-notificaciones/src/notifications/notifications.module.ts create mode 100644 servicio-notificaciones/src/notifications/notifications.service.spec.ts create mode 100644 servicio-notificaciones/src/notifications/notifications.service.ts create mode 100644 servicio-notificaciones/src/notifications/schemas/notification.schemas.ts diff --git a/api-gateway/src/app.module.ts b/api-gateway/src/app.module.ts index 865408d1..9d48d0d8 100644 --- a/api-gateway/src/app.module.ts +++ b/api-gateway/src/app.module.ts @@ -55,6 +55,17 @@ import { AppService } from './app.service'; } } ]), + + ClientsModule.register([ + { + name: "SERVICIO_NOTIFICACIONES", + transport: Transport.TCP, + options: { + host: "127.0.0.1", + port: 3009 + } + } + ]), ], controllers: [AppController], providers: [AppService], diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index f8053bf4..777cddb5 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -11,6 +11,8 @@ export class AppService { @Inject('SERVICIO_AREAS_COMUNES') private readonly clientCommonAreaApp: ClientProxy, @Inject('SERVICIO_INVITADOS') private readonly clientGuestApp: ClientProxy, @Inject('SERVICIO_PAGOS') private readonly clientPaymentApp: ClientProxy, + + @Inject('SERVICIO_NOTIFICACIONES') private readonly clientNotificationtApp: ClientProxy, ) { } // ====================== USERS =============================== diff --git a/servicio-notificaciones/package-lock.json b/servicio-notificaciones/package-lock.json index 8832d062..3b47b59c 100644 --- a/servicio-notificaciones/package-lock.json +++ b/servicio-notificaciones/package-lock.json @@ -11,10 +11,14 @@ "dependencies": { "@nestjs/common": "^8.0.0", "@nestjs/core": "^8.0.0", + "@nestjs/mapped-types": "*", + "@nestjs/microservices": "^8.4.7", "@nestjs/platform-express": "^8.0.0", + "@nestjs/swagger": "^5.2.1", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "rxjs": "^7.2.0" + "rxjs": "^7.2.0", + "swagger-ui-express": "^4.4.0" }, "devDependencies": { "@nestjs/cli": "^8.0.0", @@ -1518,6 +1522,82 @@ } } }, + "node_modules/@nestjs/mapped-types": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-1.0.1.tgz", + "integrity": "sha512-NFvofzSinp00j5rzUd4tf+xi9od6383iY0JP7o0Bnu1fuItAUkWBgc4EKuIQ3D+c2QI3i9pG1kDWAeY27EMGtg==", + "peerDependencies": { + "@nestjs/common": "^7.0.8 || ^8.0.0", + "class-transformer": "^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0", + "class-validator": "^0.11.1 || ^0.12.0 || ^0.13.0", + "reflect-metadata": "^0.1.12" + }, + "peerDependenciesMeta": { + "class-transformer": { + "optional": true + }, + "class-validator": { + "optional": true + } + } + }, + "node_modules/@nestjs/microservices": { + "version": "8.4.7", + "resolved": "https://registry.npmjs.org/@nestjs/microservices/-/microservices-8.4.7.tgz", + "integrity": "sha512-JZX29tBWbbPa+Q06QcCbwKTyEsOFHAPrxgfEkRNwoaiEqqCsITT9w2n5bcz3vlUurdpy5dIgX3/almbitghbKg==", + "dependencies": { + "iterare": "1.2.1", + "tslib": "2.4.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "@grpc/grpc-js": "*", + "@nestjs/common": "^8.0.0", + "@nestjs/core": "^8.0.0", + "@nestjs/websockets": "^8.0.0", + "amqp-connection-manager": "*", + "amqplib": "*", + "cache-manager": "*", + "kafkajs": "*", + "mqtt": "*", + "nats": "*", + "redis": "*", + "reflect-metadata": "^0.1.12", + "rxjs": "^7.1.0" + }, + "peerDependenciesMeta": { + "@grpc/grpc-js": { + "optional": true + }, + "@nestjs/websockets": { + "optional": true + }, + "amqp-connection-manager": { + "optional": true + }, + "amqplib": { + "optional": true + }, + "cache-manager": { + "optional": true + }, + "kafkajs": { + "optional": true + }, + "mqtt": { + "optional": true + }, + "nats": { + "optional": true + }, + "redis": { + "optional": true + } + } + }, "node_modules/@nestjs/platform-express": { "version": "8.4.7", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-8.4.7.tgz", @@ -1617,6 +1697,31 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, + "node_modules/@nestjs/swagger": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-5.2.1.tgz", + "integrity": "sha512-7dNa08WCnTsW/oAk3Ujde+z64JMfNm19DhpXasFR8oJp/9pggYAbYU927HpA+GJsSFJX6adjIRZsCKUqaGWznw==", + "dependencies": { + "@nestjs/mapped-types": "1.0.1", + "lodash": "4.17.21", + "path-to-regexp": "3.2.0" + }, + "peerDependencies": { + "@nestjs/common": "^8.0.0", + "@nestjs/core": "^8.0.0", + "fastify-swagger": "*", + "reflect-metadata": "^0.1.12", + "swagger-ui-express": "*" + }, + "peerDependenciesMeta": { + "fastify-swagger": { + "optional": true + }, + "swagger-ui-express": { + "optional": true + } + } + }, "node_modules/@nestjs/testing": { "version": "8.4.7", "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-8.4.7.tgz", @@ -6210,8 +6315,7 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash.memoize": { "version": "4.1.2", @@ -7751,6 +7855,25 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/swagger-ui-dist": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-4.12.0.tgz", + "integrity": "sha512-B0Iy2ueXtbByE6OOyHTi3lFQkpPi/L7kFOKFeKTr44za7dJIELa9kzaca6GkndCgpK1QTjArnoXG+aUy0XQp1w==" + }, + "node_modules/swagger-ui-express": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-4.4.0.tgz", + "integrity": "sha512-1CzRkHG386VQMVZK406jcpgnW2a9A5A/NiAjKhsFTQqUBWRF+uGbXTU/mA7WSV3mTzyOQDvjBdWP/c2qd5lqKw==", + "dependencies": { + "swagger-ui-dist": ">=4.11.0" + }, + "engines": { + "node": ">= v0.10.32" + }, + "peerDependencies": { + "express": ">=4.0.0" + } + }, "node_modules/symbol-observable": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz", @@ -9803,6 +9926,21 @@ "uuid": "8.3.2" } }, + "@nestjs/mapped-types": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-1.0.1.tgz", + "integrity": "sha512-NFvofzSinp00j5rzUd4tf+xi9od6383iY0JP7o0Bnu1fuItAUkWBgc4EKuIQ3D+c2QI3i9pG1kDWAeY27EMGtg==", + "requires": {} + }, + "@nestjs/microservices": { + "version": "8.4.7", + "resolved": "https://registry.npmjs.org/@nestjs/microservices/-/microservices-8.4.7.tgz", + "integrity": "sha512-JZX29tBWbbPa+Q06QcCbwKTyEsOFHAPrxgfEkRNwoaiEqqCsITT9w2n5bcz3vlUurdpy5dIgX3/almbitghbKg==", + "requires": { + "iterare": "1.2.1", + "tslib": "2.4.0" + } + }, "@nestjs/platform-express": { "version": "8.4.7", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-8.4.7.tgz", @@ -9872,6 +10010,16 @@ } } }, + "@nestjs/swagger": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-5.2.1.tgz", + "integrity": "sha512-7dNa08WCnTsW/oAk3Ujde+z64JMfNm19DhpXasFR8oJp/9pggYAbYU927HpA+GJsSFJX6adjIRZsCKUqaGWznw==", + "requires": { + "@nestjs/mapped-types": "1.0.1", + "lodash": "4.17.21", + "path-to-regexp": "3.2.0" + } + }, "@nestjs/testing": { "version": "8.4.7", "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-8.4.7.tgz", @@ -13376,8 +13524,7 @@ "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "lodash.memoize": { "version": "4.1.2", @@ -14513,6 +14660,19 @@ "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", "dev": true }, + "swagger-ui-dist": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-4.12.0.tgz", + "integrity": "sha512-B0Iy2ueXtbByE6OOyHTi3lFQkpPi/L7kFOKFeKTr44za7dJIELa9kzaca6GkndCgpK1QTjArnoXG+aUy0XQp1w==" + }, + "swagger-ui-express": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-4.4.0.tgz", + "integrity": "sha512-1CzRkHG386VQMVZK406jcpgnW2a9A5A/NiAjKhsFTQqUBWRF+uGbXTU/mA7WSV3mTzyOQDvjBdWP/c2qd5lqKw==", + "requires": { + "swagger-ui-dist": ">=4.11.0" + } + }, "symbol-observable": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz", diff --git a/servicio-notificaciones/package.json b/servicio-notificaciones/package.json index b62ab613..bd1a9175 100644 --- a/servicio-notificaciones/package.json +++ b/servicio-notificaciones/package.json @@ -23,10 +23,14 @@ "dependencies": { "@nestjs/common": "^8.0.0", "@nestjs/core": "^8.0.0", + "@nestjs/mapped-types": "*", + "@nestjs/microservices": "^8.4.7", "@nestjs/platform-express": "^8.0.0", + "@nestjs/swagger": "^5.2.1", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "rxjs": "^7.2.0" + "rxjs": "^7.2.0", + "swagger-ui-express": "^4.4.0" }, "devDependencies": { "@nestjs/cli": "^8.0.0", diff --git a/servicio-notificaciones/src/app.controller.spec.ts b/servicio-notificaciones/src/app.controller.spec.ts deleted file mode 100644 index d22f3890..00000000 --- a/servicio-notificaciones/src/app.controller.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; - -describe('AppController', () => { - let appController: AppController; - - beforeEach(async () => { - const app: TestingModule = await Test.createTestingModule({ - controllers: [AppController], - providers: [AppService], - }).compile(); - - appController = app.get(AppController); - }); - - describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); - }); - }); -}); diff --git a/servicio-notificaciones/src/app.controller.ts b/servicio-notificaciones/src/app.controller.ts index cce879ee..a361ad7e 100644 --- a/servicio-notificaciones/src/app.controller.ts +++ b/servicio-notificaciones/src/app.controller.ts @@ -1,12 +1,11 @@ import { Controller, Get } from '@nestjs/common'; -import { AppService } from './app.service'; @Controller() export class AppController { - constructor(private readonly appService: AppService) {} + constructor() {} @Get() getHello(): string { - return this.appService.getHello(); + return "hola"; } } diff --git a/servicio-notificaciones/src/app.module.ts b/servicio-notificaciones/src/app.module.ts index 86628031..bb34cfc8 100644 --- a/servicio-notificaciones/src/app.module.ts +++ b/servicio-notificaciones/src/app.module.ts @@ -1,10 +1,23 @@ import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; -import { AppService } from './app.service'; +import { NotificationsModule } from './notifications/notifications.module'; +import { ClientsModule, Transport } from "@nestjs/microservices"; + @Module({ - imports: [], + imports: [ + ClientsModule.register([ + { + name: "SERVICIO_NOTIFICACIONES", + transport: Transport.TCP, + options: { + host: "127.0.0.1", + port: 3009 + } + } + ]), + NotificationsModule], controllers: [AppController], - providers: [AppService], + providers: [], }) export class AppModule {} diff --git a/servicio-notificaciones/src/app.service.ts b/servicio-notificaciones/src/app.service.ts deleted file mode 100644 index 927d7cca..00000000 --- a/servicio-notificaciones/src/app.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -@Injectable() -export class AppService { - getHello(): string { - return 'Hello World!'; - } -} diff --git a/servicio-notificaciones/src/main.ts b/servicio-notificaciones/src/main.ts index 13cad38c..86642811 100644 --- a/servicio-notificaciones/src/main.ts +++ b/servicio-notificaciones/src/main.ts @@ -1,8 +1,18 @@ -import { NestFactory } from '@nestjs/core'; -import { AppModule } from './app.module'; +import { NestFactory } from "@nestjs/core"; +import { Transport } from "@nestjs/microservices"; +import { AppModule } from "./app.module"; +import { Logger } from "@nestjs/common"; + +const logger = new Logger(); async function bootstrap() { - const app = await NestFactory.create(AppModule); - await app.listen(3000); + const app = await NestFactory.createMicroservice(AppModule, { + transport: Transport.TCP, + options: { + host: "127.0.0.1", + port: 3009 + } + }); + app.listen().then(() => logger.log("Microservice Notificaciones is listening" )); } -bootstrap(); +bootstrap(); \ No newline at end of file diff --git a/servicio-notificaciones/src/notifications/dto/create-notification.dto.ts b/servicio-notificaciones/src/notifications/dto/create-notification.dto.ts new file mode 100644 index 00000000..98ca4791 --- /dev/null +++ b/servicio-notificaciones/src/notifications/dto/create-notification.dto.ts @@ -0,0 +1 @@ +export class CreateNotificationDto {} diff --git a/servicio-notificaciones/src/notifications/dto/update-notification.dto.ts b/servicio-notificaciones/src/notifications/dto/update-notification.dto.ts new file mode 100644 index 00000000..f639cde4 --- /dev/null +++ b/servicio-notificaciones/src/notifications/dto/update-notification.dto.ts @@ -0,0 +1,6 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateNotificationDto } from './create-notification.dto'; + +export class UpdateNotificationDto extends PartialType(CreateNotificationDto) { + id: number; +} diff --git a/servicio-notificaciones/src/notifications/notifications.controller.spec.ts b/servicio-notificaciones/src/notifications/notifications.controller.spec.ts new file mode 100644 index 00000000..9aa4a006 --- /dev/null +++ b/servicio-notificaciones/src/notifications/notifications.controller.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { NotificationsController } from './notifications.controller'; +import { NotificationsService } from './notifications.service'; + +describe('NotificationsController', () => { + let controller: NotificationsController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [NotificationsController], + providers: [NotificationsService], + }).compile(); + + controller = module.get(NotificationsController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/servicio-notificaciones/src/notifications/notifications.controller.ts b/servicio-notificaciones/src/notifications/notifications.controller.ts new file mode 100644 index 00000000..063bf4fd --- /dev/null +++ b/servicio-notificaciones/src/notifications/notifications.controller.ts @@ -0,0 +1,35 @@ +import { Controller } from '@nestjs/common'; +import { MessagePattern, Payload } from '@nestjs/microservices'; +import { NotificationsService } from './notifications.service'; +import { CreateNotificationDto } from './dto/create-notification.dto'; +import { UpdateNotificationDto } from './dto/update-notification.dto'; + +@Controller() +export class NotificationsController { + constructor(private readonly notificationsService: NotificationsService) {} + + @MessagePattern({cmd: 'createNotification'}) + create(@Payload() createNotificationDto: CreateNotificationDto) { + return this.notificationsService.create(createNotificationDto); + } + + @MessagePattern({cmd: 'findAllNotifications'}) + findAll() { + return this.notificationsService.findAll(); + } + + @MessagePattern({cmd: 'findOneNotification'}) + findOne(@Payload() id: number) { + return this.notificationsService.findOne(id); + } + + @MessagePattern({cmd: 'updateNotification'}) + update(@Payload() updateNotificationDto: UpdateNotificationDto) { + return this.notificationsService.update(updateNotificationDto.id, updateNotificationDto); + } + + @MessagePattern({cmd: 'removeNotification'}) + remove(@Payload() id: number) { + return this.notificationsService.remove(id); + } +} diff --git a/servicio-notificaciones/src/notifications/notifications.module.ts b/servicio-notificaciones/src/notifications/notifications.module.ts new file mode 100644 index 00000000..d7449eda --- /dev/null +++ b/servicio-notificaciones/src/notifications/notifications.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { NotificationsService } from './notifications.service'; +import { NotificationsController } from './notifications.controller'; + +@Module({ + controllers: [NotificationsController], + providers: [NotificationsService] +}) +export class NotificationsModule {} diff --git a/servicio-notificaciones/src/notifications/notifications.service.spec.ts b/servicio-notificaciones/src/notifications/notifications.service.spec.ts new file mode 100644 index 00000000..47119104 --- /dev/null +++ b/servicio-notificaciones/src/notifications/notifications.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { NotificationsService } from './notifications.service'; + +describe('NotificationsService', () => { + let service: NotificationsService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [NotificationsService], + }).compile(); + + service = module.get(NotificationsService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/servicio-notificaciones/src/notifications/notifications.service.ts b/servicio-notificaciones/src/notifications/notifications.service.ts new file mode 100644 index 00000000..41219fe1 --- /dev/null +++ b/servicio-notificaciones/src/notifications/notifications.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@nestjs/common'; +import { CreateNotificationDto } from './dto/create-notification.dto'; +import { UpdateNotificationDto } from './dto/update-notification.dto'; + +@Injectable() +export class NotificationsService { + create(createNotificationDto: CreateNotificationDto) { + return 'This action adds a new notification'; + } + + findAll() { + return `This action returns all notifications`; + } + + findOne(id: number) { + return `This action returns a #${id} notification`; + } + + update(id: number, updateNotificationDto: UpdateNotificationDto) { + return `This action updates a #${id} notification`; + } + + remove(id: number) { + return `This action removes a #${id} notification`; + } +} diff --git a/servicio-notificaciones/src/notifications/schemas/notification.schemas.ts b/servicio-notificaciones/src/notifications/schemas/notification.schemas.ts new file mode 100644 index 00000000..b79d7d57 --- /dev/null +++ b/servicio-notificaciones/src/notifications/schemas/notification.schemas.ts @@ -0,0 +1 @@ +export class Notification {}