Correcion del listado

Correccion del listado de administradores
This commit is contained in:
Traym17 2022-07-14 18:46:07 -06:00
parent 460f6c3bd8
commit 24bb8cef32
2 changed files with 51 additions and 16 deletions

View File

@ -1,8 +1,9 @@
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
const cors= require('cors');
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
await app.listen(3000); await app.listen(4000);
app.use(cors());
} }
bootstrap(); bootstrap();

View File

@ -1,21 +1,41 @@
import React, { useState } from 'react'; import React, { useEffect, useState } from 'react';
import { InputText } from 'primereact/inputtext'; import { InputText } from 'primereact/inputtext';
import { Button } from 'primereact/button'; import { Button } from 'primereact/button';
import { DataTable } from 'primereact/datatable';
import { Column } from 'primereact/column';
const FormAdminSistema = () => { 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() { function registrarAdmin() {
var data = { var data = {
dni: "12687", dni: document.getElementById('identificacion').value,
name: "hola", name: document.getElementById('nombre').value,
last_name: "buuu", last_name: document.getElementById('apellidos').value,
email: "tmora4c@ucenfotec.ac.cr", email: document.getElementById('correo_electronico').value,
phone: 84664515, phone: document.getElementById('telefono').value,
password: "1203", password: document.getElementById('correo_electronico').value,
user_type: "1", user_type: "1", //1 es admin
status: "2" status: "1"
}; };
console.log(data); // console.log(data);
fetch('http://localhost:4000/user/createAdminSystem/', { fetch('http://localhost:4000/user/createAdminSystem/', {
cache: 'no-cache', cache: 'no-cache',
method: 'POST', method: 'POST',
@ -26,7 +46,7 @@ const FormAdminSistema = () => {
}) })
.then( .then(
function (response) { function (response) {
if (response.status != 200) if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status); console.log('Ocurrió un error con el servicio: ' + response.status);
else else
return response.json(); return response.json();
@ -34,7 +54,7 @@ const FormAdminSistema = () => {
) )
.then( .then(
function (response) { function (response) {
console.log(response); fetchP();
} }
) )
.catch( .catch(
@ -44,6 +64,18 @@ const FormAdminSistema = () => {
return ( return (
<div className="grid"> <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="col-12">
<div className="card"> <div className="card">
<h5>Registro de un administrador del sistema</h5> <h5>Registro de un administrador del sistema</h5>
@ -66,13 +98,15 @@ const FormAdminSistema = () => {
</div> </div>
<div className="field col-12"> <div className="field col-12">
<label htmlFor="telefono">Teléfono</label> <label htmlFor="telefono">Teléfono</label>
<InputText id="telefono" type="text" rows="4" /> <InputText id="telefono" type="number" rows="4" />
</div> </div>
<Button label="Registrar" onClick={registrarAdmin}></Button> <Button label="Registrar" onClick={registrarAdmin}></Button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
) )
} }