diff --git a/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index 6ef0c9fc..1133b4d0 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -57,6 +57,7 @@ export class CommunitiesController { @MessagePattern({ cmd: 'saveTenant' }) saveTenant(@Payload() body: string) { + let id = body['_id']; let tenant_id = body['tenant_id']; let number_house = body['number_house']; diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index 90c47cee..48ad87b8 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -6,6 +6,7 @@ import { RpcException, ClientProxy } from '@nestjs/microservices'; import { from, lastValueFrom, map, scan, mergeMap } from 'rxjs'; import { Admin } from 'src/schemas/admin.entity'; import { appendFileSync } from 'fs'; +import { Tenant, TenantSchema } from 'src/schemas/tenant.schema'; @Injectable() export class CommunitiesService { @@ -80,21 +81,37 @@ export class CommunitiesService { } - async saveTenant(id: string, number_house: string, tenant_id: string) { - + async saveTenant(id: string, number_house: string, ptenant_id: string) { let community = await this.findOne(id); + console.log(ptenant_id) + await community.houses.map(house => { - if(house.number_house == number_house){ - house.tenants.tenant_id = tenant_id + if (house.number_house == number_house) { + if (house.tenants) { + console.log(house.tenants.tenant_id + '1') + + house.tenants.tenant_id = ptenant_id + console.log(house.tenants.tenant_id + '1') + console.log(house.tenants + '1') + } else { + let tenant = new Tenant() + + tenant.tenant_id = ptenant_id; + console.log(tenant) + + house.tenants = tenant; + console.log(house.tenants + '2') + + } + console.log(house.tenants + '3') + house.state = "ocupada" } return house; }) - console.log(community.houses) - - return await this.communityModel.findOneAndUpdate({ _id: id }, community, { + return await this.communityModel.findOneAndUpdate({ _id: id }, community, { new: true, }); } @@ -105,10 +122,10 @@ export class CommunitiesService { let community = await this.findOne(id); await community.houses.map(house => { - if(house.number_house == number_house && - house.tenants.tenant_id == tenant_id){ - house.tenants = null; - house.state = "desocupada" + if (house.number_house == number_house && + house.tenants.tenant_id == tenant_id) { + house.tenants = null; + house.state = "desocupada" } return house; @@ -116,7 +133,7 @@ export class CommunitiesService { console.log(community.houses) - return await this.communityModel.findOneAndUpdate({ _id: id }, community, { + return await this.communityModel.findOneAndUpdate({ _id: id }, community, { new: true, }); } diff --git a/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs b/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs index 3915f374..4669d4a8 100644 --- a/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs +++ b/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs @@ -393,7 +393,7 @@ {{date_entry}}
-

Fue asignado en la comunidad {{community_name}} en la vivienda #{{number_house}}

+

Fue asignado en la comunidad {{community_name}} en la vivienda # {{number_house}}

diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index cedf2263..06f9cd88 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -133,7 +133,7 @@ export class UsersController { @MessagePattern({ cmd: 'deleteTenant' }) deleteTenant(@Payload() user: any) { - return this.userService.deleteTenant(user['id']); + return this.userService.deleteTenant(user['_id']); } @MessagePattern({ cmd: 'changeStatus' }) diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 41257a2e..8061479e 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -28,9 +28,12 @@ export class UsersService { let password = user.password; let passwordEncriptada = Md5.init(user.password); user.password = passwordEncriptada; - this.userModel.create(user) + let userCreated = await this.userModel.create(user); + console.log(await userCreated); + let callback = await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']); - await this.saveTenantNumHouse(user.community_id, user.number_house, user._id); + const finalValue = await lastValueFrom(callback); + const response = await finalValue['response']; let community = await this.findCommunity(user.community_id); user.community_id = community['name']; @@ -39,7 +42,7 @@ export class UsersService { const payload = { email: user['email'], password: password, name: user['name'], date_entry: user['date_entry'], community_name: community['name'], - number_house:['number_house'] + number_house: user['number_house'] }; return this.clientNotificationtApp diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 72c61df1..94e4ab4e 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -137,11 +137,9 @@ const Inquilinos = () => { }) .then(() => { if (_tenant.status === '1') { - _tenant.status = '0' - _tenant.status_text = 'Inactivo' - } else if (_tenant.status === '0') { - _tenant.status = '1' _tenant.status_text = 'Activo' + } else if (_tenant.status === '0') { + _tenant.status_text = 'Inactivo' } _tenants.push(_tenant) toast.current.show({