update microservice-notificaciones

agregar conexión con api gateway y generar recursos de microservicio
This commit is contained in:
Mariela 2022-07-01 03:59:39 -06:00
parent 98f5d28169
commit 73f8ae04df
17 changed files with 332 additions and 47 deletions

View File

@ -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], controllers: [AppController],
providers: [AppService], providers: [AppService],

View File

@ -11,6 +11,8 @@ export class AppService {
@Inject('SERVICIO_AREAS_COMUNES') private readonly clientCommonAreaApp: ClientProxy, @Inject('SERVICIO_AREAS_COMUNES') private readonly clientCommonAreaApp: ClientProxy,
@Inject('SERVICIO_INVITADOS') private readonly clientGuestApp: ClientProxy, @Inject('SERVICIO_INVITADOS') private readonly clientGuestApp: ClientProxy,
@Inject('SERVICIO_PAGOS') private readonly clientPaymentApp: ClientProxy, @Inject('SERVICIO_PAGOS') private readonly clientPaymentApp: ClientProxy,
@Inject('SERVICIO_NOTIFICACIONES') private readonly clientNotificationtApp: ClientProxy,
) { } ) { }
// ====================== USERS =============================== // ====================== USERS ===============================

View File

@ -11,10 +11,14 @@
"dependencies": { "dependencies": {
"@nestjs/common": "^8.0.0", "@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0", "@nestjs/core": "^8.0.0",
"@nestjs/mapped-types": "*",
"@nestjs/microservices": "^8.4.7",
"@nestjs/platform-express": "^8.0.0", "@nestjs/platform-express": "^8.0.0",
"@nestjs/swagger": "^5.2.1",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rxjs": "^7.2.0" "rxjs": "^7.2.0",
"swagger-ui-express": "^4.4.0"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^8.0.0", "@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": { "node_modules/@nestjs/platform-express": {
"version": "8.4.7", "version": "8.4.7",
"resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-8.4.7.tgz", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-8.4.7.tgz",
@ -1617,6 +1697,31 @@
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true "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": { "node_modules/@nestjs/testing": {
"version": "8.4.7", "version": "8.4.7",
"resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-8.4.7.tgz", "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-8.4.7.tgz",
@ -6210,8 +6315,7 @@
"node_modules/lodash": { "node_modules/lodash": {
"version": "4.17.21", "version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
"dev": true
}, },
"node_modules/lodash.memoize": { "node_modules/lodash.memoize": {
"version": "4.1.2", "version": "4.1.2",
@ -7751,6 +7855,25 @@
"url": "https://github.com/sponsors/ljharb" "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": { "node_modules/symbol-observable": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz",
@ -9803,6 +9926,21 @@
"uuid": "8.3.2" "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": { "@nestjs/platform-express": {
"version": "8.4.7", "version": "8.4.7",
"resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-8.4.7.tgz", "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": { "@nestjs/testing": {
"version": "8.4.7", "version": "8.4.7",
"resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-8.4.7.tgz", "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-8.4.7.tgz",
@ -13376,8 +13524,7 @@
"lodash": { "lodash": {
"version": "4.17.21", "version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
"dev": true
}, },
"lodash.memoize": { "lodash.memoize": {
"version": "4.1.2", "version": "4.1.2",
@ -14513,6 +14660,19 @@
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
"dev": true "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": { "symbol-observable": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz",

View File

@ -23,10 +23,14 @@
"dependencies": { "dependencies": {
"@nestjs/common": "^8.0.0", "@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0", "@nestjs/core": "^8.0.0",
"@nestjs/mapped-types": "*",
"@nestjs/microservices": "^8.4.7",
"@nestjs/platform-express": "^8.0.0", "@nestjs/platform-express": "^8.0.0",
"@nestjs/swagger": "^5.2.1",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rxjs": "^7.2.0" "rxjs": "^7.2.0",
"swagger-ui-express": "^4.4.0"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^8.0.0", "@nestjs/cli": "^8.0.0",

View File

@ -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>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});

View File

@ -1,12 +1,11 @@
import { Controller, Get } from '@nestjs/common'; import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller() @Controller()
export class AppController { export class AppController {
constructor(private readonly appService: AppService) {} constructor() {}
@Get() @Get()
getHello(): string { getHello(): string {
return this.appService.getHello(); return "hola";
} }
} }

View File

@ -1,10 +1,23 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { AppController } from './app.controller'; import { AppController } from './app.controller';
import { AppService } from './app.service'; import { NotificationsModule } from './notifications/notifications.module';
import { ClientsModule, Transport } from "@nestjs/microservices";
@Module({ @Module({
imports: [], imports: [
ClientsModule.register([
{
name: "SERVICIO_NOTIFICACIONES",
transport: Transport.TCP,
options: {
host: "127.0.0.1",
port: 3009
}
}
]),
NotificationsModule],
controllers: [AppController], controllers: [AppController],
providers: [AppService], providers: [],
}) })
export class AppModule {} export class AppModule {}

View File

@ -1,8 +0,0 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}

View File

@ -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: 3009
}
});
app.listen().then(() => logger.log("Microservice Notificaciones is listening" ));
} }
bootstrap(); bootstrap();

View File

@ -0,0 +1 @@
export class CreateNotificationDto {}

View File

@ -0,0 +1,6 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateNotificationDto } from './create-notification.dto';
export class UpdateNotificationDto extends PartialType(CreateNotificationDto) {
id: number;
}

View File

@ -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>(NotificationsController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@ -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);
}
}

View File

@ -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 {}

View File

@ -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>(NotificationsService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

View File

@ -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`;
}
}

View File

@ -0,0 +1 @@
export class Notification {}