diff --git a/servicio-comunidad-viviendas/src/schemas/house.schema.ts b/servicio-comunidad-viviendas/src/schemas/house.schema.ts index 75aeda0f..d85c31c6 100644 --- a/servicio-comunidad-viviendas/src/schemas/house.schema.ts +++ b/servicio-comunidad-viviendas/src/schemas/house.schema.ts @@ -7,7 +7,7 @@ import { Tenant, TenantSchema } from './tenant.schema'; @Schema() export class House extends Document { @Prop({ default: ' ' }) - number: string; + number_house: string; @Prop({ default: 'desocupada' }) state: string; diff --git a/servicio-usuarios/src/schemas/user.schema.ts b/servicio-usuarios/src/schemas/user.schema.ts index 02d1cf81..f09a3231 100644 --- a/servicio-usuarios/src/schemas/user.schema.ts +++ b/servicio-usuarios/src/schemas/user.schema.ts @@ -36,6 +36,9 @@ export class User { @Prop() community_id?: string; + + @Prop() + number_house?: string; } export const UserSchema = SchemaFactory.createForClass(User); diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 6ff98cf6..1054116f 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -127,13 +127,28 @@ export class UsersService { //find inquilinos - async findTenantsCommunity(pcommunity_id: string): Promise { - let houses = await this.findCommunityHouses(pcommunity_id); + async findTenantsCommunity(pcommunity_id: string) { + //let tenants = await this.findCommunityTenants(pcommunity_id); - return this.userModel.find({ community_id: pcommunity_id, user_type: 4 }).exec() - .then(); + + + return await this.userModel.find({ community_id: pcommunity_id, user_type: 4 }) + .then(async (users) => { + if (users) { + await Promise.all( + users.map(async (u) => { + //buscar al usuario con el id de la comunidad anexado + let number_house = await this.findNumHouseTenant(pcommunity_id, u['_id']); + u['number_house'] = number_house; + return u; + }), + ) + } + return users; + }) } + async testSendMail(user: UserDocument) { let passwordEncriptada = Md5.init(user.password); user.password = passwordEncriptada; @@ -179,7 +194,7 @@ export class UsersService { }); } - async findCommunityHouses(community_id: string) { + async findNumHouseTenant(community_id: string, tenant_id: string) { const pattern = { cmd: 'findOneCommunity' } const payload = { _id: community_id } @@ -190,8 +205,15 @@ export class UsersService { ) const finalValue = await lastValueFrom(callback); const response = finalValue['response']; - console.log(response['houses']); - return response['houses']; + const houses = response['houses']; + let num_house = ""; + await houses.forEach(async house => { + if (tenant_id == house.tenants.tenant_id) { + num_house = house.number_house; + } + }) + return num_house; } + } diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 221a30d5..c47d81c9 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -31,6 +31,7 @@ const Inquilinos = () => { password: '', community_id: '', community_name: '', + number_house: 'Sin nĂºmero de vivienda', user_type: '4', date_entry: new Date(), status: '1' @@ -55,7 +56,15 @@ const Inquilinos = () => { await fetch(`http://localhost:4000/user/findTenants/${cookies.community_id}`, { method: 'GET' }) .then((response) => response.json()) .then(data => data.message) - .then(data => setTenants(data)); + .then(data => { + + data.map((item) => { + if(item.number_house ==""){ + item.number_house = "Sin vivienda asignada"; + } + }) + setTenants(data) + }); } @@ -279,11 +288,7 @@ const Inquilinos = () => { ) - const headerCommuntiy = ( - <> -

Comunidad

- - ) + const headerNumberHouse = ( <> @@ -315,7 +320,7 @@ const Inquilinos = () => { - +