From 24bb8cef327670a91a0a31375bdef35903320f32 Mon Sep 17 00:00:00 2001 From: Traym17 <51390112+Traym17@users.noreply.github.com> Date: Thu, 14 Jul 2022 18:46:07 -0600 Subject: [PATCH 1/5] Correcion del listado Correccion del listado de administradores --- api-gateway/src/main.ts | 5 +- .../src/components/FormAdminSistema.js | 62 ++++++++++++++----- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/api-gateway/src/main.ts b/api-gateway/src/main.ts index 13cad38c..3bea0f30 100644 --- a/api-gateway/src/main.ts +++ b/api-gateway/src/main.ts @@ -1,8 +1,9 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; - +const cors= require('cors'); async function bootstrap() { const app = await NestFactory.create(AppModule); - await app.listen(3000); + await app.listen(4000); + app.use(cors()); } bootstrap(); diff --git a/web-ui/web-react/src/components/FormAdminSistema.js b/web-ui/web-react/src/components/FormAdminSistema.js index c112cbe9..3a3efdb0 100644 --- a/web-ui/web-react/src/components/FormAdminSistema.js +++ b/web-ui/web-react/src/components/FormAdminSistema.js @@ -1,21 +1,41 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { InputText } from 'primereact/inputtext'; import { Button } from 'primereact/button'; +import { DataTable } from 'primereact/datatable'; +import { Column } from 'primereact/column'; const FormAdminSistema = () => { + const [pokemones,setPokemones]=useState([]); + const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/allUsers'); + async function fetchP(){ + let nombres=await fetch(urlFetch, {method:'GET'}); + let pokemonesRes= await nombres.json(); + setPokemones(pokemonesRes.message); + console.log(pokemones); + } + useEffect(()=>{ + fetchP(); + },[]) + + + + + + function registrarAdmin() { var data = { - dni: "12687", - name: "hola", - last_name: "buuu", - email: "tmora4c@ucenfotec.ac.cr", - phone: 84664515, - password: "1203", - user_type: "1", - status: "2" + dni: document.getElementById('identificacion').value, + name: document.getElementById('nombre').value, + last_name: document.getElementById('apellidos').value, + email: document.getElementById('correo_electronico').value, + phone: document.getElementById('telefono').value, + password: document.getElementById('correo_electronico').value, + user_type: "1", //1 es admin + status: "1" }; - console.log(data); + // console.log(data); + fetch('http://localhost:4000/user/createAdminSystem/', { cache: 'no-cache', method: 'POST', @@ -26,7 +46,7 @@ const FormAdminSistema = () => { }) .then( function (response) { - if (response.status != 200) + if (response.status != 201) console.log('Ocurrió un error con el servicio: ' + response.status); else return response.json(); @@ -34,7 +54,7 @@ const FormAdminSistema = () => { ) .then( function (response) { - console.log(response); + fetchP(); } ) .catch( @@ -44,6 +64,18 @@ const FormAdminSistema = () => { return (
+
+
+
Administradores del sistema
+ + + + + + + +
+
Registro de un administrador del sistema
@@ -66,14 +98,16 @@ const FormAdminSistema = () => {
- +
+ + ) } -export default React.memo(FormAdminSistema); +export default React.memo(FormAdminSistema); \ No newline at end of file From 9abdd27b41f1b169113b955f4190c49999fd6b1d Mon Sep 17 00:00:00 2001 From: Traym17 <51390112+Traym17@users.noreply.github.com> Date: Thu, 14 Jul 2022 19:01:02 -0600 Subject: [PATCH 2/5] Filtro del listado Cambio en el servicio del get de los usuarios --- api-gateway/src/app.controller.ts | 5 +++++ api-gateway/src/app.service.ts | 10 ++++++++++ servicio-usuarios/src/users/users.controller.ts | 6 ++++++ servicio-usuarios/src/users/users.service.ts | 6 +++++- web-ui/web-react/src/components/FormAdminSistema.js | 2 +- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 28a68842..b2536033 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -52,6 +52,11 @@ export class AppController { return this.appService.inicioSesion(pEmail,pPassword); } + @Get('user/findAdminSistema') + allUsersAdminSistema() { + return this.appService.allUsersAdminSistema(); + } + @Get('user/find/:dni') findUser( @Param('dni') paramUserDNI: string diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 4e59d974..bb8385a5 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -60,6 +60,16 @@ export class AppService { ); } + allUsersAdminSistema() { + const pattern = { cmd: 'findAdminSistema' }; + const payload = {}; + return this.clientUserApp + .send(pattern, payload) + .pipe( + map((message: string) => ({ message })), + ); + } + //GET parameter from API findUser(paramUserDNI: string) { const pattern = { cmd: 'findUserDNI' }; diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index 24ca5c01..43e23dd7 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -46,4 +46,10 @@ export class UsersController { let ppassword= body['password']; return this.userService.findLogin(pemail,ppassword); } + + //buscar solo admins del sistema + @MessagePattern({ cmd: 'findAdminSistema' }) + allUsersAdminSistema() { + return this.userService.allUsersAdminSistema(); + } } diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index aae09cd1..dabd96f7 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -22,7 +22,6 @@ export class UsersService { .setOptions({ sanitizeFilter: true }) .exec(); } - async findOne(id: string): Promise { return this.userModel.findOne({ _id: id }).exec(); } @@ -65,4 +64,9 @@ export class UsersService { return userReturn; } + + //find admin del sistema + async allUsersAdminSistema(): Promise { + return this.userModel.find({ user_type: 1 }).exec(); + } } diff --git a/web-ui/web-react/src/components/FormAdminSistema.js b/web-ui/web-react/src/components/FormAdminSistema.js index 3a3efdb0..8e71860f 100644 --- a/web-ui/web-react/src/components/FormAdminSistema.js +++ b/web-ui/web-react/src/components/FormAdminSistema.js @@ -7,7 +7,7 @@ import { Column } from 'primereact/column'; const FormAdminSistema = () => { const [pokemones,setPokemones]=useState([]); - const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/allUsers'); + const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/findAdminSistema/'); async function fetchP(){ let nombres=await fetch(urlFetch, {method:'GET'}); let pokemonesRes= await nombres.json(); From bf91f1e4b8aa528087f8c6a8c023258cc29161e0 Mon Sep 17 00:00:00 2001 From: Traym17 <51390112+Traym17@users.noreply.github.com> Date: Thu, 14 Jul 2022 19:04:30 -0600 Subject: [PATCH 3/5] =?UTF-8?q?Pesta=C3=B1a=20nueva?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creacion de la pestaña de la sección de listar admin de comunidad --- web-ui/web-react/src/App.js | 7 ++++--- .../{FormAdminSistema.js => AdministradoresSistema.js} | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) rename web-ui/web-react/src/components/{FormAdminSistema.js => AdministradoresSistema.js} (98%) diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index 7e3f23c4..2f009e72 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -28,7 +28,7 @@ import TreeDemo from './templates/TreeDemo'; import InvalidStateDemo from './templates/InvalidStateDemo'; import BlocksDemo from './templates/BlocksDemo'; import IconsDemo from './templates/IconsDemo'; -import FormAdminSistema from './components/FormAdminSistema'; +import AdministradoresSistema from './components/AdministradoresSistema'; import Crud from './pages/Crud'; import EmptyPage from './pages/EmptyPage'; @@ -162,7 +162,8 @@ const App = () => { label: 'Home', items: [ {label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/'}, - {label: 'Registro admin sistema', icon: 'pi pi-fw pi-id-card', to: '/formAdminSistema'}, + {label: 'Administradores del sistema', icon: 'pi pi-fw pi-id-card', to: '/administradoresSistema'}, + {label: 'Administradores de comunidad', icon: 'pi pi-fw pi-id-card', to: '/administradoresSistema'}, {label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn'} ] }, @@ -316,7 +317,7 @@ const App = () => { - + diff --git a/web-ui/web-react/src/components/FormAdminSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js similarity index 98% rename from web-ui/web-react/src/components/FormAdminSistema.js rename to web-ui/web-react/src/components/AdministradoresSistema.js index 8e71860f..aefddc85 100644 --- a/web-ui/web-react/src/components/FormAdminSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -4,7 +4,7 @@ import { Button } from 'primereact/button'; import { DataTable } from 'primereact/datatable'; import { Column } from 'primereact/column'; -const FormAdminSistema = () => { +const AdministradoresSistema = () => { const [pokemones,setPokemones]=useState([]); const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/findAdminSistema/'); @@ -110,4 +110,4 @@ const FormAdminSistema = () => { ) } -export default React.memo(FormAdminSistema); \ No newline at end of file +export default React.memo(AdministradoresSistema); \ No newline at end of file From d6e468ca03e9bd4b96401a1621887d075b574475 Mon Sep 17 00:00:00 2001 From: Traym17 <51390112+Traym17@users.noreply.github.com> Date: Thu, 14 Jul 2022 19:08:04 -0600 Subject: [PATCH 4/5] =?UTF-8?q?Creaci=C3=B3n=20del=20componente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creación del componente de lista para listar los admins de comunidad --- web-ui/web-react/src/App.js | 4 +- .../components/AdministradoresComunidad.js | 41 +++++++++++++++++++ .../src/components/AdministradoresSistema.js | 5 --- 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 web-ui/web-react/src/components/AdministradoresComunidad.js diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index 2f009e72..83530986 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -29,6 +29,7 @@ import InvalidStateDemo from './templates/InvalidStateDemo'; import BlocksDemo from './templates/BlocksDemo'; import IconsDemo from './templates/IconsDemo'; import AdministradoresSistema from './components/AdministradoresSistema'; +import AdministradoresComunidad from './components/AdministradoresComunidad'; import Crud from './pages/Crud'; import EmptyPage from './pages/EmptyPage'; @@ -163,7 +164,7 @@ const App = () => { items: [ {label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/'}, {label: 'Administradores del sistema', icon: 'pi pi-fw pi-id-card', to: '/administradoresSistema'}, - {label: 'Administradores de comunidad', icon: 'pi pi-fw pi-id-card', to: '/administradoresSistema'}, + {label: 'Administradores de comunidad', icon: 'pi pi-fw pi-id-card', to: '/administradoresComunidad'}, {label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn'} ] }, @@ -318,6 +319,7 @@ const App = () => { + diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js new file mode 100644 index 00000000..ddf095c1 --- /dev/null +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -0,0 +1,41 @@ +import React, { useEffect, useState } from 'react'; +import { InputText } from 'primereact/inputtext'; +import { Button } from 'primereact/button'; +import { DataTable } from 'primereact/datatable'; +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); + } + useEffect(()=>{ + fetchP(); + },[]) + + return ( +
+
+
+
Administradores de comunidad
+ + + + + + + +
+
+
+ + + ) +} + +export default React.memo(AdministradoresComunidad); \ No newline at end of file diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index aefddc85..02ad4fb9 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -18,11 +18,6 @@ const AdministradoresSistema = () => { fetchP(); },[]) - - - - - function registrarAdmin() { var data = { dni: document.getElementById('identificacion').value, 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 5/5] 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
- + - + - + +