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