Merge pull request #105 from DeimosPr4/UH-registroGuardaSeguridad

Registro y listado de los guardas de seguridad
This commit is contained in:
Eduardo Quiros 2022-07-21 23:12:24 -06:00 committed by GitHub
commit d82457f9c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 229 additions and 12 deletions

View File

@ -12,6 +12,8 @@
"@nestjs/core": "^8.0.0", "@nestjs/core": "^8.0.0",
"@nestjs/microservices": "^8.4.7", "@nestjs/microservices": "^8.4.7",
"@nestjs/platform-express": "^8.0.0", "@nestjs/platform-express": "^8.0.0",
"@types/cors": "^2.8.12",
"cors": "^2.8.5",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rxjs": "^7.2.0" "rxjs": "^7.2.0"
@ -1882,6 +1884,11 @@
"integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==",
"dev": true "dev": true
}, },
"node_modules/@types/cors": {
"version": "2.8.12",
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz",
"integrity": "sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw=="
},
"node_modules/@types/eslint": { "node_modules/@types/eslint": {
"version": "8.4.3", "version": "8.4.3",
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.3.tgz", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.3.tgz",
@ -10108,6 +10115,11 @@
"integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==",
"dev": true "dev": true
}, },
"@types/cors": {
"version": "2.8.12",
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz",
"integrity": "sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw=="
},
"@types/eslint": { "@types/eslint": {
"version": "8.4.3", "version": "8.4.3",
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.3.tgz", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.3.tgz",

View File

@ -25,6 +25,8 @@
"@nestjs/core": "^8.0.0", "@nestjs/core": "^8.0.0",
"@nestjs/microservices": "^8.4.7", "@nestjs/microservices": "^8.4.7",
"@nestjs/platform-express": "^8.0.0", "@nestjs/platform-express": "^8.0.0",
"@types/cors": "^2.8.12",
"cors": "^2.8.5",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rxjs": "^7.2.0" "rxjs": "^7.2.0"

View File

@ -1,10 +1,8 @@
import { Controller, Get, Post, Body, Param } from '@nestjs/common'; import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import { AppService } from "./app.service"; import { AppService } from "./app.service";
@Controller() @Controller()
export class AppController { export class AppController {
constructor(private readonly appService: AppService) { } constructor(private readonly appService: AppService) { }
// #==== API Users // #==== API Users
@Post('user/createAdminSystem') @Post('user/createAdminSystem')
createAdminSystem( createAdminSystem(
@ -22,6 +20,24 @@ export class AppController {
user_type, status, date_entry); user_type, status, date_entry);
} }
@Post('user/createGuard')
createGuard(
//Nombre, Apellidos, Correo electrónico, Cédula, Teléfono, Contraseña
@Body('dni') dni: string,
@Body('name') name: string,
@Body('last_name') last_name: string,
@Body('email') email: string,
@Body('phone') phone: number,
@Body('password') password: string,
@Body('user_type') user_type: string,
@Body('status') status: string,
@Body('date_entry') date_entry: Date,
@Body('community_id') community_id:string
) {
return this.appService.createGuard(dni, name, last_name, email, phone, password,
user_type, status, date_entry,community_id);
}
@Post('user/createUser') @Post('user/createUser')
createUser( createUser(
@Body('dni') dni: string, @Body('dni') dni: string,
@ -61,6 +77,12 @@ export class AppController {
allUsersAdminComunidad() { allUsersAdminComunidad() {
return this.appService.allUsersAdminComunidad(); return this.appService.allUsersAdminComunidad();
} }
@Get('user/findGuards/:community')
findGuardsCommunity(
@Param('community_id') community_id: string
) {
return this.appService.findGuardsCommunity(community_id);
}
@Get('user/find/:dni') @Get('user/find/:dni')
findUser( findUser(

View File

@ -50,12 +50,13 @@ export class AppService {
); );
} }
testSendMail(dni: string, name: string, last_name: string, email: string, phone: number createGuard(dni: string, name: string, last_name: string, email: string, phone: number
, password: string, user_type: string, status: string, date_entry: Date) { , password: string, user_type: string, status: string, date_entry: Date, community_id: string) {
const pattern = { cmd: 'testSendMail' }; const pattern = { cmd: 'createGuard' };
const payload = { const payload = {
dni: dni, name: name, last_name: last_name, email: email, phone: phone, dni: dni, name: name, last_name: last_name, email: email, phone: phone,
password: password, user_type: user_type, status: status, date_entry: date_entry password: password, user_type: user_type, status: status, date_entry: date_entry, community_id
}; };
return this.clientUserApp return this.clientUserApp
.send<string>(pattern, payload) .send<string>(pattern, payload)
@ -105,6 +106,16 @@ export class AppService {
); );
} }
findGuardsCommunity(community_id: string) {
const pattern = { cmd: 'findGuardsCommunity' };
const payload = { community_id: community_id };
return this.clientUserApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
inicioSesion(pEmail: string, pPassword: string) { inicioSesion(pEmail: string, pPassword: string) {
const pattern = { cmd: 'loginUser' }; const pattern = { cmd: 'loginUser' };
const payload = { email: pEmail, password: pPassword}; const payload = { email: pEmail, password: pPassword};

View File

@ -5,7 +5,6 @@
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "servicio-comunidad-viviendas",
"version": "0.0.1", "version": "0.0.1",
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {

View File

@ -17,6 +17,7 @@
"@nestjs/platform-express": "^8.0.0", "@nestjs/platform-express": "^8.0.0",
"@nestjs/swagger": "^5.2.1", "@nestjs/swagger": "^5.2.1",
"buffer": "^5.7.1", "buffer": "^5.7.1",
"cors": "^2.8.5",
"crypto-browserify": "^3.12.0", "crypto-browserify": "^3.12.0",
"md5-typescript": "^1.0.5", "md5-typescript": "^1.0.5",
"mongoose": "^6.4.1", "mongoose": "^6.4.1",

View File

@ -29,6 +29,7 @@
"@nestjs/platform-express": "^8.0.0", "@nestjs/platform-express": "^8.0.0",
"@nestjs/swagger": "^5.2.1", "@nestjs/swagger": "^5.2.1",
"buffer": "^5.7.1", "buffer": "^5.7.1",
"cors": "^2.8.5",
"crypto-browserify": "^3.12.0", "crypto-browserify": "^3.12.0",
"md5-typescript": "^1.0.5", "md5-typescript": "^1.0.5",
"mongoose": "^6.4.1", "mongoose": "^6.4.1",

View File

@ -17,6 +17,10 @@ export class UsersController {
return this.userService.create(user); return this.userService.create(user);
} }
@MessagePattern({ cmd: 'createGuard' })
createGuard(@Payload() user: UserDocument) {
return this.userService.create(user);
}
@MessagePattern({ cmd: 'findAllUsers' }) @MessagePattern({ cmd: 'findAllUsers' })
@ -30,6 +34,13 @@ export class UsersController {
return this.userService.findOneByDNI(dni); return this.userService.findOneByDNI(dni);
} }
@MessagePattern({ cmd: 'findGuardsCommunity' })
findGuardsCommunity(@Payload() community_id: string) {
let pcommunity_id = community_id['community_id'];
return this.userService.findGuardsCommunity(pcommunity_id);
}
@MessagePattern({ cmd: 'updateUser' }) @MessagePattern({ cmd: 'updateUser' })
update(@Payload() user: UserDocument) { update(@Payload() user: UserDocument) {
return this.userService.update(user.id, user); return this.userService.update(user.id, user);

View File

@ -77,6 +77,16 @@ export class UsersService {
return this.userModel.find({ user_type: 1 }).exec(); return this.userModel.find({ user_type: 1 }).exec();
} }
//find admin del sistema
async findGuardsCommunity(pcommunity_id: string): Promise<User[]> {
return this.userModel.find({ user_type: 4 }).exec();
}
//find admin de comunidad
async allUsersAdminComunidad(): Promise<User[]> {
return this.userModel.find({ user_type: 2 }).exec();
}
//find admin de comunidad //find admin de comunidad
async allUsersAdminComunidad(): Promise<User[]> { async allUsersAdminComunidad(): Promise<User[]> {
return this.userModel.find({ user_type: 2 }).exec(); return this.userModel.find({ user_type: 2 }).exec();
@ -105,4 +115,5 @@ export class UsersService {
return this.userModel.findOne({ community_id: community_id, user_type: user_type }).exec(); return this.userModel.findOne({ community_id: community_id, user_type: user_type }).exec();
} }
} }

View File

@ -17,6 +17,7 @@
"axios": "^0.19.0", "axios": "^0.19.0",
"chart.js": "3.3.2", "chart.js": "3.3.2",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"cors": "^2.8.5",
"primeflex": "3.1.0", "primeflex": "3.1.0",
"primeicons": "^5.0.0", "primeicons": "^5.0.0",
"primereact": "7.2.0", "primereact": "7.2.0",
@ -5183,6 +5184,18 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
}, },
"node_modules/cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/cosmiconfig": { "node_modules/cosmiconfig": {
"version": "5.2.1", "version": "5.2.1",
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.2.1.tgz", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.2.1.tgz",
@ -21869,6 +21882,15 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
}, },
"cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"requires": {
"object-assign": "^4",
"vary": "^1"
}
},
"cosmiconfig": { "cosmiconfig": {
"version": "5.2.1", "version": "5.2.1",
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.2.1.tgz", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.2.1.tgz",

View File

@ -12,12 +12,15 @@
"@fullcalendar/core": "^5.7.2", "@fullcalendar/core": "^5.7.2",
"@fullcalendar/daygrid": "^5.7.2", "@fullcalendar/daygrid": "^5.7.2",
"@fullcalendar/interaction": "^5.7.2", "@fullcalendar/interaction": "^5.7.2",
"@fullcalendar/timegrid": "^5.7.2",
"@fullcalendar/react": "^5.7.0", "@fullcalendar/react": "^5.7.0",
"@fullcalendar/timegrid": "^5.7.2",
"axios": "^0.19.0",
"chart.js": "3.3.2", "chart.js": "3.3.2",
"primereact": "7.2.0", "classnames": "^2.2.6",
"cors": "^2.8.5",
"primeflex": "3.1.0", "primeflex": "3.1.0",
"primeicons": "^5.0.0", "primeicons": "^5.0.0",
"primereact": "7.2.0",
"prismjs": "1.9.0", "prismjs": "1.9.0",
"react": "^17.0.1", "react": "^17.0.1",
"react-app-polyfill": "^1.0.6", "react-app-polyfill": "^1.0.6",
@ -25,9 +28,7 @@
"react-router-dom": "^5.2.0", "react-router-dom": "^5.2.0",
"react-scripts": "3.4.1", "react-scripts": "3.4.1",
"react-transition-group": "^4.4.1", "react-transition-group": "^4.4.1",
"sass": "^1.32.8", "sass": "^1.32.8"
"axios": "^0.19.0",
"classnames": "^2.2.6"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",

View File

@ -30,6 +30,7 @@ import BlocksDemo from './templates/BlocksDemo';
import IconsDemo from './templates/IconsDemo'; import IconsDemo from './templates/IconsDemo';
import AdministradoresSistema from './components/AdministradoresSistema'; import AdministradoresSistema from './components/AdministradoresSistema';
import AdministradoresComunidad from './components/AdministradoresComunidad'; import AdministradoresComunidad from './components/AdministradoresComunidad';
import GuardasSeguridad from './components/GuardasSeguridad';
import Communities from './components/ComunidadViviendas'; import Communities from './components/ComunidadViviendas';
import Crud from './pages/Crud'; import Crud from './pages/Crud';
@ -166,6 +167,7 @@ const App = () => {
{label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/'}, {label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/'},
{label: 'Administradores del sistema', icon: 'pi pi-fw pi-id-card', to: '/administradoresSistema'}, {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: 'Administradores de comunidad', icon: 'pi pi-fw pi-id-card', to: '/administradoresComunidad'},
{label: 'Guardas de seguridad', icon: 'pi pi-fw pi-id-card', to: '/guardasSeguridad'},
{label: 'Comunidadades', icon: 'pi pi-fw pi-id-card', to: '/comunidadesViviendas'}, {label: 'Comunidadades', icon: 'pi pi-fw pi-id-card', to: '/comunidadesViviendas'},
{label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn'} {label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn'}
] ]
@ -322,6 +324,7 @@ const App = () => {
<Route path="/documentation" component={Documentation} /> <Route path="/documentation" component={Documentation} />
<Route path="/administradoresSistema" component={AdministradoresSistema} /> <Route path="/administradoresSistema" component={AdministradoresSistema} />
<Route path="/administradoresComunidad" component={AdministradoresComunidad} /> <Route path="/administradoresComunidad" component={AdministradoresComunidad} />
<Route path="/guardasSeguridad" component={GuardasSeguridad} />
<Route path="/comunidadesViviendas" component={Communities} /> <Route path="/comunidadesViviendas" component={Communities} />
<Route path="/logIn" component={LogIn} /> <Route path="/logIn" component={LogIn} />
</div> </div>

View File

@ -0,0 +1,121 @@
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 GuardasSeguridad = () => {
const [pokemones,setPokemones]=useState([]);
const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/findGuards/62be68215692582bbfd77134');
async function fetchP(){
let nombres=await fetch(urlFetch, {method:'GET'});
let pokemonesRes= await nombres.json();
setPokemones(pokemonesRes.message);
console.log(pokemones);
}
useEffect(()=>{
fetchP();
},[])
function registrarGuarda() {
var data = {
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: "4", //4 es guarda
status: "1",
community_id:"62be68215692582bbfd77134"
};
var data2={
dni: "98765",
name: "Danielito",
last_name: "Rodriguez",
email: "danirodriguez@gmail.com",
phone: 84664515,
password: "1203",
user_type: "2",
status: "4",
community_id:"62be68215692582bbfd77134"
}
console.log(data2);
fetch('http://localhost:4000/user/createGuard', {
cache: 'no-cache',
method: 'POST',
mode:'cors',
body: JSON.stringify(data2),
headers: {
'Content-Type': 'application/json'
}
})
.then(
function (response) {
if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status);
else
return response.json();
}
)
.then(
function (response) {
fetchP();
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
}
return (
<div className="grid">
<div className="col-12">
<div className="card">
<h5>Guardas de seguridad</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 guarda de seguridad</h5>
<div className="p-fluid formgrid grid">
<div className="field col-12 md:col-6">
<label htmlFor="nombre">Nombre</label>
<InputText id="nombre" type="text" />
</div>
<div className="field col-12 md:col-6">
<label htmlFor="apellidos">Apellidos</label>
<InputText id="apellidos" type="text" />
</div>
<div className="field col-12 md:col-6">
<label htmlFor="correo_electronico">Correo electrónico</label>
<InputText id="correo_electronico" type="text" />
</div>
<div className="field col-12 md:col-6">
<label htmlFor="identificacion">Identificación</label>
<InputText id="identificacion" type="text" />
</div>
<div className="field col-12">
<label htmlFor="telefono">Teléfono</label>
<InputText id="telefono" type="number" rows="4" />
</div>
<Button label="Registrar" onClick={registrarGuarda}></Button>
</div>
</div>
</div>
</div>
)
}
export default React.memo(GuardasSeguridad);