From 2cea9bc217d2fd378c65dbf55760cf69288a9fde Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 12:35:40 -0600 Subject: [PATCH] asignar numero de vivienda --- api-gateway/src/app.service.ts | 31 +++++++++++++++++++ .../src/users/users.controller.ts | 6 ++++ servicio-usuarios/src/users/users.service.ts | 26 ++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 99ec6d7a..be6a794c 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -56,6 +56,37 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + createTenant( + dni: string, + name: string, + last_name: string, + email: string, + phone: number, + user_type: string, + status: string, + date_entry: Date, + community_id: string, + number_house: string, + ) { + const pattern = { cmd: 'createTenant' }; + const payload = { + dni: dni, + name: name, + last_name: last_name, + email: email, + phone: phone, + password: this.generatePassword(), + user_type: user_type, + status: status, + date_entry: date_entry, + community_id: community_id, + number_house: number_house, + }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + updateUser( _id: string, dni: string, diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index 05c13169..cedf2263 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -29,6 +29,12 @@ export class UsersController { return this.userService.createAdminCommunity(user); } + @MessagePattern({ cmd: 'createTenant' }) + createTenant(@Payload() user: UserDocument) { + return this.userService.createTenant(user); + } + + @MessagePattern({ cmd: 'findAllUsers' }) findAll() { return this.userService.findAll(); diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 255d2504..d9b442fc 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -24,6 +24,32 @@ export class UsersService { } + async createTenant(user: UserDocument) { + let password = user.password; + let passwordEncriptada = Md5.init(user.password); + user.password = passwordEncriptada; + this.userModel.create(user) + + await this.saveTenantNumHouse(user.community_id, user.number_house, user._id); + + let community = await this.findCommunity(user.community_id); + user.community_id = community['name']; + + const pattern = { cmd: 'emailCreateUserTenant' }; + const payload = { + email: user['email'], password: password, name: user['name'], + date_entry: user['date_entry'], community_name: community['name'], + number_house:['number_house'] + }; + + return this.clientNotificationtApp + .send(pattern, payload) + .pipe( + map((message: string) => ({ message })), + ); + } + + async createAdminCommunity(user: UserDocument) { let password = user.password; let passwordEncriptada = Md5.init(user.password);