diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index dbcd8b85..2b5fa6e3 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -1,4 +1,5 @@ import { Controller, Get, Post, Put, Body, Param, Delete } from '@nestjs/common'; +import { Console } from 'console'; import { AppService } from './app.service'; @Controller() export class AppController { @@ -305,6 +306,30 @@ export class AppController { return this.appService.updateAdminSystem(_id, dni, name, last_name, email, phone); } + @Put('user/updateTenant/:id') + updateTenant( + @Param('id') id: string, + @Body('dni') dni: string, + @Body('name') name: string, + @Body('last_name') last_name: string, + @Body('email') email: string, + @Body('phone') phone: number, + @Body('community_id') community_id: string, + @Body('number_house') number_house: string, + ) { + + return this.appService.updateTenant( + id, + dni, + name, + last_name, + email, + phone, + community_id, + number_house, + ); + } + // #==== API Communities @Post('community/createCommunity') createCommunity( @@ -369,8 +394,9 @@ export class AppController { saveTenant( @Body('community_id') community_id: string, @Body('number_house') number_house: string, - @Body('tenant_id') tenant_id: string, + @Body('_id') tenant_id: string, ) { + console.log(community_id + ' ' + number_house + ' ' + tenant_id) return this.appService.saveTenant(community_id, number_house, tenant_id); } diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 56eb67e6..1334ab7d 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -175,6 +175,36 @@ export class AppService { .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } + + + async updateTenant( + _id: string, + dni: string, + name: string, + last_name: string, + email: string, + phone: number, + community_id: string, + number_house: string, + ) { + await this.saveTenant(community_id, number_house, _id); + + const pattern = { cmd: 'updateTenant' }; + const payload = { + id: _id, + dni: dni, + name: name, + last_name: last_name, + email: email, + phone: phone, + community_id: community_id, + number_house: number_house, + }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + //POST parameter from API createAdminSystem(dni: string, name: string, last_name: string, email: string, phone: number , user_type: string, status: string, date_entry: Date) { @@ -791,4 +821,19 @@ export class AppService { return pass; } + + + + async saveTenantNumHouse(community_id: string, number_house: string, tenant_id: string) { + + const pattern = { cmd: 'saveTenantNumHouse' } + 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/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index f71e2524..1eb2a027 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -57,7 +57,6 @@ 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 212eeda7..ee3317ca 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -88,7 +88,6 @@ export class CommunitiesService { await community.houses.map(house => { if (house.number_house == number_house) { if (house.tenants) { - house.tenants.tenant_id = ptenant_id } else { let tenant = new Tenant() @@ -109,7 +108,8 @@ export class CommunitiesService { await community.houses.map(house => { if (house.number_house === number_house) { - house.tenants.tenant_id = ""; + if(house.tenants) + house.tenants.tenant_id = ""; house.state = "desocupada" } return house; diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index bea3191e..81a296b6 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -77,14 +77,19 @@ export class UsersController { @MessagePattern({ cmd: 'updateGuard' }) updateGuard(@Payload() guard: UserDocument) { - return this.userService.update(guard.id, guard); + return this.userService.update(guard._id, guard); } - + @MessagePattern({ cmd: 'updateAdminCommunity' }) updateAdminCommunity(@Payload() user: UserDocument) { return this.userService.update(user._id, user); } + @MessagePattern({ cmd: 'updateTenant' }) + updateTenant(@Payload() tenant: UserDocument) { + return this.userService.updateTenant(tenant.id, tenant); + } + @MessagePattern({ cmd: 'removeUser' }) remove(@Payload() id: string) { let dni = id['dni']; diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 5df15e3a..f074c01d 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -29,7 +29,7 @@ export class UsersService { let passwordEncriptada = Md5.init(user.password); user.password = passwordEncriptada; let userCreated = await this.userModel.create(user); - await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']); + await this.saveTenant(user.community_id, user.number_house, userCreated['_id']); let community = await this.findCommunity(user.community_id); user.community_id = community['name']; @@ -117,6 +117,9 @@ export class UsersService { } async update(id: string, user: UserDocument) { + console.log(id) + console.log(user) + return this.userModel.findOneAndUpdate({ _id: id }, user, { new: true, }); @@ -131,6 +134,18 @@ export class UsersService { }); } + async updateTenant(id: string, user: UserDocument) { + await this.saveTenant(user.community_id, user.number_house, user.id); + + return await this.userModel.findOneAndUpdate({ _id: id }, { + name: user['name'], last_name: user['last_name'], + dni: user['dni'], email: user['email'], phone: user['phone'], + number_house: user['number_house'] + }, { + new: true, + }); + } + /* async remove(id: string) { return this.userModel.findByIdAndRemove({ _id: id }).exec(); }*/ @@ -293,7 +308,7 @@ export class UsersService { } - async saveTenantNumHouse(community_id: string, number_house: string, tenant_id: string) { + async saveTenant(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 } diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index 48ea0ccd..efa23d58 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -58,6 +58,7 @@ import { useCookies } from "react-cookie"; import LogInUser from './components/LogInUser'; import Page404 from './components/Page404' import Reservaciones from './components/Reservaciones'; +import PerfilAdminComunidad from './components/PerfilAdminComunidad'; const App = () => { @@ -472,6 +473,7 @@ const App = () => { + ) } else { diff --git a/web-ui/web-react/src/AppTopbar.js b/web-ui/web-react/src/AppTopbar.js index f9226f50..122d6ef7 100644 --- a/web-ui/web-react/src/AppTopbar.js +++ b/web-ui/web-react/src/AppTopbar.js @@ -88,10 +88,11 @@ export const AppTopbar = (props) => { */}