funcionalidad eliminar administrador del sistema
This commit is contained in:
parent
d82457f9c3
commit
ed88d5ace0
|
@ -1,4 +1,4 @@
|
||||||
import { Controller, Get, Post, Body, Param } from '@nestjs/common';
|
import { Controller, Get, Post, Body, Param, Delete } from '@nestjs/common';
|
||||||
import { AppService } from "./app.service";
|
import { AppService } from "./app.service";
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AppController {
|
export class AppController {
|
||||||
|
@ -92,6 +92,13 @@ export class AppController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Delete('user/deleteAdminSystem/:id')
|
||||||
|
deleteAdminSystem(
|
||||||
|
@Param('id') id: string,
|
||||||
|
) {
|
||||||
|
return this.appService.deleteAdminSystem(id);
|
||||||
|
}
|
||||||
|
|
||||||
// #==== API Communities
|
// #==== API Communities
|
||||||
@Post('community/createCommunity')
|
@Post('community/createCommunity')
|
||||||
createCommunity(
|
createCommunity(
|
||||||
|
@ -342,21 +349,4 @@ export class AppController {
|
||||||
|
|
||||||
return this.appService.html(email, name);
|
return this.appService.html(email, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #==== API Users
|
|
||||||
@Post('user/testSendMail')
|
|
||||||
testSendMail(
|
|
||||||
@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.testSendMail(dni, name, last_name, email, phone, password,
|
|
||||||
user_type, status, date_entry);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -116,6 +116,17 @@ export class AppService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
deleteAdminSystem(id: string) {
|
||||||
|
const pattern = { cmd: 'deleteAdminSystem' };
|
||||||
|
const payload = { id: 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};
|
||||||
|
|
|
@ -84,6 +84,12 @@ export class UsersController {
|
||||||
return this.userService.findCommunityUser(user["community_id"], user["user_type"]);
|
return this.userService.findCommunityUser(user["community_id"], user["user_type"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MessagePattern({ cmd: 'deleteAdminSystem' })
|
||||||
|
deleteAdminSystem(@Payload() user: any) {
|
||||||
|
console.log("entró")
|
||||||
|
|
||||||
|
return this.userService.deleteAdminSystem(user["id"]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,10 +87,6 @@ export class UsersService {
|
||||||
return this.userModel.find({ user_type: 2 }).exec();
|
return this.userModel.find({ user_type: 2 }).exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
//find admin de comunidad
|
|
||||||
async allUsersAdminComunidad(): Promise<User[]> {
|
|
||||||
return this.userModel.find({ user_type: 2 }).exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
async testSendMail(user: UserDocument) {
|
async testSendMail(user: UserDocument) {
|
||||||
let passwordEncriptada = Md5.init(user.password);
|
let passwordEncriptada = Md5.init(user.password);
|
||||||
|
@ -109,11 +105,12 @@ export class UsersService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async findCommunityUser(community_id: string, user_type: number): Promise<User> {
|
async findCommunityUser(community_id: string, user_type: number): Promise<User> {
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async deleteAdminSystem(id: string) {
|
||||||
|
return this.userModel.deleteOne({_id: id}).exec();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,39 @@
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState, useRef } 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 { DataTable } from 'primereact/datatable';
|
||||||
import { Column } from 'primereact/column';
|
import { Column } from 'primereact/column';
|
||||||
|
import { Toast } from 'primereact/toast';
|
||||||
|
import { Dialog } from 'primereact/dialog';
|
||||||
|
|
||||||
const AdministradoresSistema = () => {
|
const AdministradoresSistema = () => {
|
||||||
|
|
||||||
const [pokemones,setPokemones]=useState([]);
|
const [administrators, setAdministrators] = useState([]);
|
||||||
const [urlFetch, setUrlFetch] = useState('http://localhost:4000/user/findAdminSistema/');
|
const [urlFetch, setUrlFetch] = useState('http://localhost:4000/user/findAdminSistema/');
|
||||||
|
const [sysadmin, setSysAdmin] = useState(emptySysAdmin);
|
||||||
|
|
||||||
|
const [deleteAdminSystemDialog, setDeleteAdminSystemDialog] = useState(false);
|
||||||
|
const [deleteAdminsSystemDialog, setDeleteAdminsSystemDialog] = useState(false);
|
||||||
|
const toast = useRef(null);
|
||||||
|
|
||||||
|
|
||||||
|
let emptySysAdmin = {
|
||||||
|
_id: null,
|
||||||
|
dni: '',
|
||||||
|
name: '',
|
||||||
|
last_name: '',
|
||||||
|
email: '',
|
||||||
|
phone: '',
|
||||||
|
password: '',
|
||||||
|
user_type: '1',
|
||||||
|
status: ''
|
||||||
|
};
|
||||||
|
|
||||||
async function fetchP() {
|
async function fetchP() {
|
||||||
let nombres = await fetch(urlFetch, { method: 'GET' });
|
let nombres = await fetch(urlFetch, { method: 'GET' });
|
||||||
let pokemonesRes= await nombres.json();
|
let adminRes = await nombres.json();
|
||||||
setPokemones(pokemonesRes.message);
|
setAdministrators(adminRes.message);
|
||||||
console.log(pokemones);
|
console.log(administrators);
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchP();
|
fetchP();
|
||||||
|
@ -49,7 +70,10 @@ const AdministradoresSistema = () => {
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
function (response) {
|
function (response) {
|
||||||
fetchP();
|
let _administrators = [...administrators];
|
||||||
|
let _admin = { ...response.message };;
|
||||||
|
_administrators.push(_admin);
|
||||||
|
setAdministrators(_administrators)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch(
|
.catch(
|
||||||
|
@ -57,18 +81,100 @@ const AdministradoresSistema = () => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const hideDeleteAdminSystemDialog = () => {
|
||||||
|
setDeleteAdminSystemDialog(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const hideDeleteAdminsSystemsDialog = () => {
|
||||||
|
setDeleteAdminsSystemDialog(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmDeleteAdminSystem = (sysAdmin) => {
|
||||||
|
setSysAdmin(sysAdmin);
|
||||||
|
setDeleteAdminSystemDialog(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteSysAdmin = () => {
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
id: sysadmin._id
|
||||||
|
}
|
||||||
|
fetch('http://localhost:4000/user/deleteAdminSystem/' + sysadmin._id, {
|
||||||
|
cache: 'no-cache',
|
||||||
|
method: 'DELETE',
|
||||||
|
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) {
|
||||||
|
let _sysadmin = administrators.filter(val => val._id !== sysadmin._id);
|
||||||
|
setAdministrators(_sysadmin);
|
||||||
|
|
||||||
|
setDeleteAdminSystemDialog(false);
|
||||||
|
setSysAdmin(emptySysAdmin);
|
||||||
|
|
||||||
|
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador del Sistema Eliminado', life: 3000 });
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch(
|
||||||
|
err => {
|
||||||
|
console.log('Ocurrió un error con el fetch', err)
|
||||||
|
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Administrador del Sistema no se pudo eliminar', life: 3000 });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const actionsAdmin = (rowData) => {
|
||||||
|
return (
|
||||||
|
<div className="actions">
|
||||||
|
<Button icon="pi pi-trash" className="p-button-rounded p-button-warning mt-2" onClick={() => confirmDeleteAdminSystem(rowData)} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteAdminSystemDialogFooter = (
|
||||||
|
<>
|
||||||
|
<Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteAdminSystemDialog} />
|
||||||
|
<Button label="Yes" icon="pi pi-check" className="p-button-text" onClick={deleteSysAdmin} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid">
|
<div className="grid">
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
|
<Toast ref={toast} />
|
||||||
|
|
||||||
<div className="card">
|
<div className="card">
|
||||||
<h5>Administradores del sistema</h5>
|
<h5>Administradores del sistema</h5>
|
||||||
<DataTable value={pokemones} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
|
<DataTable value={administrators} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
|
||||||
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
<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="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="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="email" header="Correo electrónico" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||||
<Column field="phone" header="Telefóno" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
<Column field="phone" header="Telefóno" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||||
|
<Column body={actionsAdmin}></Column>
|
||||||
|
|
||||||
</DataTable>
|
</DataTable>
|
||||||
|
|
||||||
|
<Dialog visible={deleteAdminSystemDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteAdminSystemDialogFooter} onHide={hideDeleteAdminSystemDialog}>
|
||||||
|
<div className="flex align-items-center justify-content-center">
|
||||||
|
<i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} />
|
||||||
|
{sysadmin && <span>Are you sure you want to delete <b>{sysadmin.name}</b>?</span>}
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
|
|
Loading…
Reference in New Issue