diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 5ebc741f..67adc7db 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -261,7 +261,21 @@ export class AppController { return this.appService.changeStatusCommunity(pId, pStatus); } - + @Get('community/findHousesCommunity/:id') + findHousesCommunity( + @Param('id') community_id: string, + ) { + return this.appService.findHousesCommunity(community_id); + } + + @Post('community/saveTenant') + saveTenant( + @Body('community_id') community_id: string, + @Body('number_house') number_house: string, + @Body('tenant_id') tenant_id: string, + ) { + return this.appService.saveTenant(community_id, number_house, tenant_id); + } // #==== API Common Areas @Post('commonArea/createCommonArea') createCommonArea( diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 9307433c..99ec6d7a 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -1,6 +1,7 @@ import { Injectable, Inject } from '@nestjs/common'; import { ClientProxy } from '@nestjs/microservices'; import { map } from 'rxjs/operators'; +import { lastValueFrom } from 'rxjs'; @Injectable() export class AppService { @@ -337,6 +338,31 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + + async findHousesCommunity(community_id: string) { + const pattern = { cmd: 'findOneCommunity' } + const payload = { _id: community_id } + + let callback = await this.clientCommunityApp + .send(pattern, payload) + .pipe( + map((response: string) => ({ response })) + ) + const finalValue = await lastValueFrom(callback); + const response = finalValue['response']; + const houses = response['houses']; + + return houses; + } + + saveTenant(id: string, number_house: string, tenant_id: string) { + const pattern = { cmd: 'saveTenant' }; + const payload = { _id: id, number_house: number_house, tenant_id: tenant_id }; + return this.clientCommunityApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + // ====================== COMMON AREAS =============================== //POST parameter from API createCommonArea( diff --git a/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index 83335420..6ef0c9fc 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -53,4 +53,13 @@ export class CommunitiesController { let pstatus = body['status']; return this.communitiesService.changeStatus(pid,pstatus); } + + + @MessagePattern({ cmd: 'saveTenant' }) + saveTenant(@Payload() body: string) { + let id = body['_id']; + let tenant_id = body['tenant_id']; + let number_house = body['number_house']; + return this.communitiesService.saveTenant(id, number_house, tenant_id); + } } diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index 8b5ce685..c494222b 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -13,7 +13,7 @@ export class CommunitiesService { @InjectModel(Community.name) private readonly communityModel: Model, @Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy, - ) {} + ) { } async create(community: CommunityDocument): Promise { return this.communityModel.create(community); @@ -56,15 +56,15 @@ export class CommunitiesService { } async remove(id: string) { - return this.communityModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, { new: true, - }); + }); } async changeStatus(id: string, status: string) { - return this.communityModel.findOneAndUpdate({ _id: id }, {status: status}, { + return this.communityModel.findOneAndUpdate({ _id: id }, { status: status }, { new: true, - }); + }); } async findCommunityAdmin(community: string, user_type: string) { @@ -78,4 +78,23 @@ export class CommunitiesService { const finalValue = await lastValueFrom(callback); return finalValue['response']; } + + + async saveTenant(id: string, number_house: string, tenant_id: string) { + + let community = await this.findOne(id); + + await community.houses.map(house => { + if(house.number_house == number_house){ + house.tenants.tenant_id = tenant_id + } + return house; + }) + + console.log(community.houses) + + return await this.communityModel.findOneAndUpdate({ _id: id }, community, { + new: true, + }); + } } diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index d117beeb..255d2504 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -145,7 +145,6 @@ export class UsersService { return await this.userModel.find({ community_id: pcommunity_id, user_type: 4 }) } - async testSendMail(user: UserDocument) { let passwordEncriptada = Md5.init(user.password); user.password = passwordEncriptada; @@ -231,5 +230,17 @@ export class UsersService { new: true, }); } + + + async saveTenantNumHouse(community_id: string, number_house:string, tenant_id: string) { + const pattern = { cmd: 'saveTenant' } + const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id } + + return await this.clientCommunityApp + .send(pattern, payload) + .pipe( + map((response: string) => ({ response })) + ) + } } diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 244196da..8a21fc72 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -93,6 +93,16 @@ const Inquilinos = () => { ) } + + async function getHouses() { + let response = await fetch( + `http://localhost:4000/community/findHousesCommunity/${cookies.community_id}`, + { method: 'GET' }, + ) + let resList = await response.json() + setHousesList(await resList) + } + useEffect(() => { tenantsList() }, [])