editar funciones para editar administrador en backend

This commit is contained in:
Mariela 2022-08-22 01:22:32 -06:00
parent 999175a246
commit 05600cb829
4 changed files with 80 additions and 13 deletions

View File

@ -179,6 +179,20 @@ export class AppController {
return this.appService.changeStatusUser(pId, pStatus);
}
@Post('user/updateAdminSystem')
updateAdminSystem(
//Nombre, Apellidos, Correo electrónico, Cédula, Teléfono, Contraseña
@Body('_id') _id: string,
@Body('dni') dni: string,
@Body('name') name: string,
@Body('last_name') last_name: string,
@Body('email') email: string,
@Body('phone') phone: number,
) {
return this.appService.updateAdminSystem(_id, dni, name, last_name, email, phone);
}
// #==== API Communities
@Post('community/createCommunity')
createCommunity(

View File

@ -223,6 +223,19 @@ export class AppService {
.pipe(map((message: string) => ({ message })));
}
updateAdminSystem(_id: string, dni: string, name: string,
last_name: string, email: string, phone: number
) {
const pattern = { cmd: 'updateAdminSystem' };
const payload = {
_id: _id, dni: dni, name: name, last_name: last_name,
email: email, phone: phone
};
return this.clientUserApp
.send<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
//GET parameter from API
findCommunityAdmin(community_id: string) {
const pattern = { cmd: 'findCommunityAdmin' };

View File

@ -66,7 +66,7 @@ export class UsersController {
@MessagePattern({ cmd: 'updateUser' })
update(@Payload() user: UserDocument) {
return this.userService.update(user.id, user);
return this.userService.update(user._id, user);
}
@MessagePattern({ cmd: 'removeUser' })
@ -75,6 +75,10 @@ export class UsersController {
return this.userService.remove(dni);
}
@MessagePattern({ cmd: 'updateAdminSystem' })
updateAdminSystem(@Payload() user: UserDocument) {
return this.userService.update(user._id, user);
}
//inicio de sesion
@MessagePattern({ cmd: 'loginUser' })
findLogin(@Payload() body: string) {

View File

@ -86,6 +86,28 @@ const AdministradoresSistema = () => {
let _administrators = [...administrators];
let _admin = { ...sysadmin };
if (sysadmin._id) {
if (sysadmin.name && sysadmin.dni && sysadmin.last_name && sysadmin.email &&
sysadmin.phone) {
fetch('http://localhost:4000/user/updateAdminSystem/', {
cache: 'no-cache',
method: 'POST',
body: JSON.stringify(_admin),
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) {
const index = findIndexById(sysadmin._id);
_administrators[index] = _admin;
@ -98,6 +120,20 @@ const AdministradoresSistema = () => {
setAdministrators(_administrators)
setEditAdminDialog(false);
setSysAdmin(emptySysAdmin);
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
} else {
setSubmitted(true);
}
} else {
var data = {
dni: document.getElementById('identificacion').value,