diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 28a68842..f3b09baf 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -52,6 +52,16 @@ export class AppController { return this.appService.inicioSesion(pEmail,pPassword); } + @Get('user/findAdminSistema') + allUsersAdminSistema() { + return this.appService.allUsersAdminSistema(); + } + + @Get('user/findAdminComunidad') + allUsersAdminComunidad() { + return this.appService.allUsersAdminComunidad(); + } + @Get('user/find/:dni') findUser( @Param('dni') paramUserDNI: string @@ -92,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 4e59d974..4ede2579 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -60,6 +60,26 @@ export class AppService { ); } + allUsersAdminSistema() { + const pattern = { cmd: 'findAdminSistema' }; + const payload = {}; + return this.clientUserApp + .send(pattern, payload) + .pipe( + map((message: string) => ({ message })), + ); + } + + 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' }; @@ -119,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/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/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 24ca5c01..d65748ce 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -46,4 +46,16 @@ 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(); + } + + //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 aae09cd1..b7071691 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,16 @@ export class UsersService { return userReturn; } + + //find admin del sistema + 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/App.js b/web-ui/web-react/src/App.js index 7e3f23c4..83530986 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -28,7 +28,8 @@ 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 AdministradoresComunidad from './components/AdministradoresComunidad'; import Crud from './pages/Crud'; import EmptyPage from './pages/EmptyPage'; @@ -162,7 +163,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: '/administradoresComunidad'}, {label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn'} ] }, @@ -316,7 +318,8 @@ 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..22eb4cc8 --- /dev/null +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -0,0 +1,52 @@ +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 [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(()=>{ + listaAdmin(); + },[]) + + return ( +
+
+
+
Administradores de comunidad
+ + + + + + + + +
+
+
+ + + ) +} + +export default React.memo(AdministradoresComunidad); \ No newline at end of file diff --git a/web-ui/web-react/src/components/FormAdminSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js similarity index 51% rename from web-ui/web-react/src/components/FormAdminSistema.js rename to web-ui/web-react/src/components/AdministradoresSistema.js index c112cbe9..02ad4fb9 100644 --- a/web-ui/web-react/src/components/FormAdminSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -1,21 +1,36 @@ -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 AdministradoresSistema = () => { + + 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(); + },[]) 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 +41,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 +49,7 @@ const FormAdminSistema = () => { ) .then( function (response) { - console.log(response); + fetchP(); } ) .catch( @@ -44,6 +59,18 @@ const FormAdminSistema = () => { return (
+
+
+
Administradores del sistema
+ + + + + + + +
+
Registro de un administrador del sistema
@@ -66,14 +93,16 @@ const FormAdminSistema = () => {
- +
+ + ) } -export default React.memo(FormAdminSistema); +export default React.memo(AdministradoresSistema); \ No newline at end of file