Creación servicio de registrar guardas
This commit is contained in:
		
							parent
							
								
									2f5dca589f
								
							
						
					
					
						commit
						9683bd4883
					
				| 
						 | 
				
			
			@ -22,6 +22,23 @@ export class AppController {
 | 
			
		|||
      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,
 | 
			
		||||
  ) {
 | 
			
		||||
    return this.appService.createGuard(dni, name, last_name, email, phone, password,
 | 
			
		||||
      user_type, status, date_entry);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Post('user/createUser')
 | 
			
		||||
  createUser(
 | 
			
		||||
    @Body('dni') dni: string,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -50,6 +50,20 @@ export class AppService {
 | 
			
		|||
      );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  createGuard(dni: string, name: string, last_name: string, email: string, phone: number
 | 
			
		||||
    , password: string, user_type: string, status: string, date_entry: Date) {
 | 
			
		||||
    const pattern = { cmd: 'createGuard' };
 | 
			
		||||
    const payload = {
 | 
			
		||||
      dni: dni, name: name, last_name: last_name, email: email, phone: phone,
 | 
			
		||||
      password: password, user_type: user_type, status: status, date_entry: date_entry
 | 
			
		||||
    };
 | 
			
		||||
    return this.clientUserApp
 | 
			
		||||
      .send<string>(pattern, payload)
 | 
			
		||||
      .pipe(
 | 
			
		||||
        map((message: string) => ({ message })),
 | 
			
		||||
      );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  allUsers() {
 | 
			
		||||
    const pattern = { cmd: 'findAllUsers' };
 | 
			
		||||
    const payload = {};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,11 @@ export class UsersController {
 | 
			
		|||
    return this.userService.create(user);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @MessagePattern({ cmd: 'createGuard' })
 | 
			
		||||
  createGuard(@Payload() user: UserDocument) {
 | 
			
		||||
    return this.userService.create(user);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @MessagePattern({ cmd: 'findAllUsers' })
 | 
			
		||||
  findAll() {
 | 
			
		||||
    return this.userService.findAll();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,6 +30,7 @@ import BlocksDemo from './templates/BlocksDemo';
 | 
			
		|||
import IconsDemo from './templates/IconsDemo';
 | 
			
		||||
import AdministradoresSistema from './components/AdministradoresSistema';
 | 
			
		||||
import AdministradoresComunidad from './components/AdministradoresComunidad';
 | 
			
		||||
import GuardasSeguridad from './components/GuardasSeguridad';
 | 
			
		||||
 | 
			
		||||
import Crud from './pages/Crud';
 | 
			
		||||
import EmptyPage from './pages/EmptyPage';
 | 
			
		||||
| 
						 | 
				
			
			@ -165,6 +166,7 @@ const App = () => {
 | 
			
		|||
                {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: '/administradoresComunidad'}, 
 | 
			
		||||
                {label: 'Guardas de seguridad', icon: 'pi pi-fw pi-id-card', to: '/guardasSeguridad'}, 
 | 
			
		||||
                {label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn'}
 | 
			
		||||
            ]
 | 
			
		||||
        },
 | 
			
		||||
| 
						 | 
				
			
			@ -320,6 +322,7 @@ const App = () => {
 | 
			
		|||
                    <Route path="/documentation" component={Documentation} />
 | 
			
		||||
                    <Route path="/administradoresSistema" component={AdministradoresSistema} />
 | 
			
		||||
                    <Route path="/administradoresComunidad" component={AdministradoresComunidad} />
 | 
			
		||||
                    <Route path="/guardasSeguridad" component={GuardasSeguridad} />
 | 
			
		||||
                    <Route path="/logIn" component={LogIn} />
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,108 @@
 | 
			
		|||
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/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: 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);
 | 
			
		||||
 | 
			
		||||
         fetch('http://localhost:4000/user/createAdminSystem/', {
 | 
			
		||||
            cache: 'no-cache',
 | 
			
		||||
            method: 'POST',
 | 
			
		||||
            body: JSON.stringify(data),
 | 
			
		||||
            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 administrador del sistema</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={registrarAdmin}></Button>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default React.memo(GuardasSeguridad);
 | 
			
		||||
		Loading…
	
		Reference in New Issue