From c89e501005afa2c7118bd8b6b0fe4cbf22c5ee4f Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 12:57:33 -0600 Subject: [PATCH] agregar funciones de edici[on de agregar inquilino --- api-gateway/src/app.controller.ts | 29 +++++++++++++++++++ .../src/communities/communities.service.ts | 23 +++++++++++++++ servicio-usuarios/src/users/users.service.ts | 12 ++++++++ web-ui/web-react/src/components/Inquilinos.js | 10 ++++++- 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 67adc7db..2975a60a 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -82,6 +82,35 @@ export class AppController { ); } + + @Post('user/createTenant') + createTenant( + @Body('dni') dni: string, + @Body('name') name: string, + @Body('last_name') last_name: string, + @Body('email') email: string, + @Body('phone') phone: number, + @Body('user_type') user_type: string, + @Body('status') status: string, + @Body('date_entry') date_entry: Date, + @Body('community_id') community_id: string, + @Body('number_house') number_house: string, + ) { + return this.appService.createTenant( + dni, + name, + last_name, + email, + phone, + user_type, + status, + date_entry, + community_id, + number_house, + ); + } + + @Put('user/updateGuard/:id') updateGuard( @Param('id') id: string, diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index c494222b..90c47cee 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -87,6 +87,29 @@ export class CommunitiesService { await community.houses.map(house => { if(house.number_house == number_house){ house.tenants.tenant_id = tenant_id + house.state = "ocupada" + } + return house; + }) + + console.log(community.houses) + + return await this.communityModel.findOneAndUpdate({ _id: id }, community, { + new: true, + }); + } + + + async deleteTenant(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){ + house.tenants = null; + house.state = "desocupada" + } return house; }) diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index d9b442fc..41257a2e 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -268,5 +268,17 @@ export class UsersService { map((response: string) => ({ response })) ) } + + + async deleteTenantNumHouse(community_id: string, number_house:string, tenant_id: string) { + const pattern = { cmd: 'deleteTenant' } + 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 8a21fc72..72c61df1 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -122,7 +122,7 @@ const Inquilinos = () => { _tenant.password = _tenant.email; console.log(`Registrando nuevo inquilino: ${_tenant}`) - fetch(`http://localhost:4000/user/createUser`, { + fetch(`http://localhost:4000/user/createTenant`, { cache: 'no-cache', method: 'POST', body: JSON.stringify(_tenant), @@ -136,6 +136,13 @@ const Inquilinos = () => { else return response.json() }) .then(() => { + if (_tenant.status === '1') { + _tenant.status = '0' + _tenant.status_text = 'Inactivo' + } else if (_tenant.status === '0') { + _tenant.status = '1' + _tenant.status_text = 'Activo' + } _tenants.push(_tenant) toast.current.show({ severity: 'success', @@ -143,6 +150,7 @@ const Inquilinos = () => { detail: 'Inquilino creado', life: 3000, }) + setTenants(_tenants) setTenant(emptyTenant) setHouseNumber('')