From 05600cb829ee17bd6262988c3a5debe63bcfc850 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 01:22:32 -0600 Subject: [PATCH] editar funciones para editar administrador en backend --- api-gateway/src/app.controller.ts | 14 +++++ api-gateway/src/app.service.ts | 13 +++++ .../src/users/users.controller.ts | 8 ++- .../src/components/AdministradoresSistema.js | 58 +++++++++++++++---- 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index adff4cf7..e8f6326a 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -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( diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 965b4005..0cf32af5 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -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(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + //GET parameter from API findCommunityAdmin(community_id: string) { const pattern = { cmd: 'findCommunityAdmin' }; diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index a13bae7c..6a663394 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -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' }) @@ -74,7 +74,11 @@ export class UsersController { let dni = id['dni']; 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) { diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 890d1ebe..dd3f84af 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -86,18 +86,54 @@ const AdministradoresSistema = () => { let _administrators = [...administrators]; let _admin = { ...sysadmin }; if (sysadmin._id) { - 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); + 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; + 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 { var data = { dni: document.getElementById('identificacion').value,