Merge pull request #97 from DeimosPr4/UH-listarAdminComunidades

Listado de los administradores de las comunidades
This commit is contained in:
Eduardo Quiros 2022-07-14 21:20:00 -06:00 committed by GitHub
commit 2f5dca589f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 185 additions and 21 deletions

View File

@ -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')

View File

@ -60,6 +60,26 @@ export class AppService {
);
}
allUsersAdminSistema() {
const pattern = { cmd: 'findAdminSistema' };
const payload = {};
return this.clientUserApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
allUsersAdminComunidad() {
const pattern = { cmd: 'findAdminComunidad' };
const payload = {};
return this.clientUserApp
.send<string>(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<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
// ====================== COMMON AREAS ===============================

View File

@ -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();

View File

@ -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);

View File

@ -24,6 +24,9 @@ export class CommunitiesService {
findOne(id: string): Promise<Community> {
return this.communityModel.findOne({ _id: id }).exec();
}
findOneName(id: string): Promise<Community> {
return this.communityModel.findOne({ _id: "62be68215692582bbfd77134" }).exec();
}
update(id: string, community: CommunityDocument) {
return this.communityModel.findOneAndUpdate({ _id: id }, community, {

View File

@ -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();
}
}

View File

@ -22,7 +22,6 @@ export class UsersService {
.setOptions({ sanitizeFilter: true })
.exec();
}
async findOne(id: string): Promise<User> {
return this.userModel.findOne({ _id: id }).exec();
}
@ -65,4 +64,16 @@ export class UsersService {
return userReturn;
}
//find admin del sistema
async allUsersAdminSistema(): Promise<User[]> {
return this.userModel.find({ user_type: 1 }).exec();
}
//find admin de comunidad
async allUsersAdminComunidad(): Promise<User[]> {
return this.userModel.find({ user_type: 2 }).exec();
}
}

View File

@ -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 = () => {
<Route path="/crud" component={Crud} />
<Route path="/empty" component={EmptyPage} />
<Route path="/documentation" component={Documentation} />
<Route path="/formAdminSistema" component={FormAdminSistema} />
<Route path="/administradoresSistema" component={AdministradoresSistema} />
<Route path="/administradoresComunidad" component={AdministradoresComunidad} />
<Route path="/logIn" component={LogIn} />
</div>

View File

@ -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 (
<div className="grid">
<div className="col-12">
<div className="card">
<h5>Administradores de comunidad</h5>
<DataTable value={listaAdmins} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="last_name" header="Apellidos" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="dni" header="Identificación" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="email" header="Correo electrónico" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="phone" header="Telefóno" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
<Column field="community_id" header="Comunidad" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
</DataTable>
</div>
</div>
</div>
)
}
export default React.memo(AdministradoresComunidad);

View File

@ -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 (
<div className="grid">
<div className="col-12">
<div className="card">
<h5>Administradores del sistema</h5>
<DataTable value={pokemones} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="last_name" header="Apellidos" style={{ flexGrow: 1, flexBasis: '160px' }} alignFrozen="left"></Column>
<Column field="dni" header="Identificación" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="email" header="Correo electrónico" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="phone" header="Telefóno" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
</DataTable>
</div>
</div>
<div className="col-12">
<div className="card">
<h5>Registro de un administrador del sistema</h5>
@ -66,14 +93,16 @@ const FormAdminSistema = () => {
</div>
<div className="field col-12">
<label htmlFor="telefono">Teléfono</label>
<InputText id="telefono" type="text" rows="4" />
<InputText id="telefono" type="number" rows="4" />
</div>
<Button label="Registrar" onClick={registrarAdmin}></Button>
</div>
</div>
</div>
</div>
)
}
export default React.memo(FormAdminSistema);
export default React.memo(AdministradoresSistema);