From 2df92e1135d6ee29b9a86e16577945f33bf9c651 Mon Sep 17 00:00:00 2001 From: Traym17 <51390112+Traym17@users.noreply.github.com> Date: Thu, 14 Jul 2022 21:16:02 -0600 Subject: [PATCH] Lista con el nombre de la comunidad Listado con el nombre de la comunidad en la tabla de administradores de comunidades --- api-gateway/src/app.controller.ts | 12 +++++++ api-gateway/src/app.service.ts | 20 +++++++++++ .../src/communities/communities.controller.ts | 6 ++++ .../src/communities/communities.service.ts | 3 ++ .../src/users/users.controller.ts | 6 ++++ servicio-usuarios/src/users/users.service.ts | 7 ++++ .../components/AdministradoresComunidad.js | 33 ++++++++++++------- 7 files changed, 76 insertions(+), 11 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index b2536033..f3b09baf 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -57,6 +57,11 @@ export class AppController { return this.appService.allUsersAdminSistema(); } + @Get('user/findAdminComunidad') + allUsersAdminComunidad() { + return this.appService.allUsersAdminComunidad(); + } + @Get('user/find/:dni') findUser( @Param('dni') paramUserDNI: string @@ -97,6 +102,13 @@ export class AppController { return this.appService.findCommunity(paramCommunityId); } + @Get('community/findCommunityName/:id') + findCommunityName( + @Param('id') paramCommunityId: string + ) { + return this.appService.findCommunityName(paramCommunityId); + } + // #==== API Common Areas @Post('commonArea/createCommonArea') diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index bb8385a5..4ede2579 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -70,6 +70,16 @@ export class AppService { ); } + allUsersAdminComunidad() { + const pattern = { cmd: 'findAdminComunidad' }; + const payload = {}; + return this.clientUserApp + .send(pattern, payload) + .pipe( + map((message: string) => ({ message })), + ); + } + //GET parameter from API findUser(paramUserDNI: string) { const pattern = { cmd: 'findUserDNI' }; @@ -129,6 +139,16 @@ export class AppService { ); } + findCommunityName(paramCommunityId: string) { + const pattern = { cmd: 'findCommunityName' }; + const payload = { id: paramCommunityId }; + return this.clientCommunityApp + .send(pattern, payload) + .pipe( + map((message: string) => ({ message })), + ); + } + // ====================== COMMON AREAS =============================== diff --git a/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index 15a950d8..457f4de6 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -23,6 +23,12 @@ export class CommunitiesController { return this.communitiesService.findOne(_id); } + @MessagePattern({cmd: 'findCommunityName'}) + findOneName(@Payload() id: string) { + let _id = id['_id']; + return this.communitiesService.findOneName(_id); + } + @MessagePattern({cmd: 'updateCommunity'}) update(@Payload() community: CommunityDocument) { return this.communitiesService.update(community.id, community); diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index 5c446a38..58b83794 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -24,6 +24,9 @@ export class CommunitiesService { findOne(id: string): Promise { return this.communityModel.findOne({ _id: id }).exec(); } + findOneName(id: string): Promise { + return this.communityModel.findOne({ _id: "62be68215692582bbfd77134" }).exec(); + } update(id: string, community: CommunityDocument) { return this.communityModel.findOneAndUpdate({ _id: id }, community, { diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index 43e23dd7..d65748ce 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -52,4 +52,10 @@ export class UsersController { allUsersAdminSistema() { return this.userService.allUsersAdminSistema(); } + + //buscar solo admins de comunidad + @MessagePattern({ cmd: 'findAdminComunidad' }) + allUsersAdminComunidad() { + return this.userService.allUsersAdminComunidad(); + } } diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index dabd96f7..b7071691 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -69,4 +69,11 @@ export class UsersService { async allUsersAdminSistema(): Promise { return this.userModel.find({ user_type: 1 }).exec(); } + + //find admin de comunidad + async allUsersAdminComunidad(): Promise { + return this.userModel.find({ user_type: 2 }).exec(); + } + + } diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index ddf095c1..22eb4cc8 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -6,16 +6,26 @@ import { Column } from 'primereact/column'; const AdministradoresComunidad = () => { - const [pokemones,setPokemones]=useState([]); - const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/findAdminSistema/'); - async function fetchP(){ - let nombres=await fetch(urlFetch, {method:'GET'}); - let pokemonesRes= await nombres.json(); - setPokemones(pokemonesRes.message); - console.log(pokemones); + const [listaAdmins,setListaAdmins]=useState([]); + const [listaAdminComunidad,setListaAdminComunidad]=useState([]); + + async function listaAdmin(){ + let nombres=await fetch('http://localhost:4000/user/findAdminComunidad/', {method:'GET'}); + let nombresRes= await nombres.json(); + setListaAdmins(nombresRes.message); } + + async function listaComunidades(nombre){ + let nombres=await fetch('http://localhost:4000/community/findCommunityName/'+nombre, {method:'GET'}); + let nombresRes= await nombres.json(); + setListaAdminComunidad(nombresRes.message); + } + listaAdmins.map(function(administrador){ + listaComunidades(administrador.community_id); + administrador.community_id=listaAdminComunidad.name; + }) useEffect(()=>{ - fetchP(); + listaAdmin(); },[]) return ( @@ -23,12 +33,13 @@ const AdministradoresComunidad = () => {
Administradores de comunidad
- + - + - + +