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); 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 // #==== API Communities
@Post('community/createCommunity') @Post('community/createCommunity')
createCommunity( createCommunity(

View File

@ -223,6 +223,19 @@ export class AppService {
.pipe(map((message: string) => ({ message }))); .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 //GET parameter from API
findCommunityAdmin(community_id: string) { findCommunityAdmin(community_id: string) {
const pattern = { cmd: 'findCommunityAdmin' }; const pattern = { cmd: 'findCommunityAdmin' };

View File

@ -66,7 +66,7 @@ export class UsersController {
@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);
} }
@MessagePattern({ cmd: 'removeUser' }) @MessagePattern({ cmd: 'removeUser' })
@ -74,7 +74,11 @@ export class UsersController {
let dni = id['dni']; let dni = id['dni'];
return this.userService.remove(dni); return this.userService.remove(dni);
} }
@MessagePattern({ cmd: 'updateAdminSystem' })
updateAdminSystem(@Payload() user: UserDocument) {
return this.userService.update(user._id, user);
}
//inicio de sesion //inicio de sesion
@MessagePattern({ cmd: 'loginUser' }) @MessagePattern({ cmd: 'loginUser' })
findLogin(@Payload() body: string) { findLogin(@Payload() body: string) {

View File

@ -86,18 +86,54 @@ const AdministradoresSistema = () => {
let _administrators = [...administrators]; let _administrators = [...administrators];
let _admin = { ...sysadmin }; let _admin = { ...sysadmin };
if (sysadmin._id) { if (sysadmin._id) {
const index = findIndexById(sysadmin._id);
_administrators[index] = _admin; if (sysadmin.name && sysadmin.dni && sysadmin.last_name && sysadmin.email &&
toast.current.show({ sysadmin.phone) {
severity: 'success',
summary: 'Exito', fetch('http://localhost:4000/user/updateAdminSystem/', {
detail: 'Administrador Actualizado', cache: 'no-cache',
life: 3000, method: 'POST',
}); body: JSON.stringify(_admin),
setAdministrators(_administrators) headers: {
setEditAdminDialog(false); 'Content-Type': 'application/json'
setSysAdmin(emptySysAdmin); }
})
.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;
toast.current.show({
severity: 'success',
summary: 'Exito',
detail: 'Administrador Actualizado',
life: 3000,
});
setAdministrators(_administrators)
setEditAdminDialog(false);
setSysAdmin(emptySysAdmin);
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
} else {
setSubmitted(true);
}
} else { } else {
var data = { var data = {
dni: document.getElementById('identificacion').value, dni: document.getElementById('identificacion').value,