From 01bd394a0d572875f5b2ae6f6f494903a409c49f Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 20:08:37 -0600 Subject: [PATCH] actualizar administrador de comunidad --- api-gateway/src/app.controller.ts | 2 +- api-gateway/src/app.service.ts | 4 ++-- .../src/users/users.controller.ts | 1 + .../components/AdministradoresComunidad.js | 23 +++++++++++++++++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 1b53de45..90f0df0c 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -243,7 +243,7 @@ export class AppController { @Put('user/updateAdminCommunity/:id') updateAdminCommunity( - @Param('_id') id: string, + @Param('id') id: string, @Body('dni') dni: string, @Body('name') name: string, @Body('last_name') last_name: string, diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 9f39ccaf..ebcf9adf 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -153,7 +153,7 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } updateAdminCommunity( - _id: string, + id: string, dni: string, name: string, last_name: string, @@ -163,7 +163,7 @@ export class AppService { ) { const pattern = { cmd: 'updateAdminCommunity' }; const payload = { - id: _id, + _id: id, dni: dni, name: name, last_name: last_name, diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index d01aafbb..81c1d968 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -82,6 +82,7 @@ export class UsersController { @MessagePattern({ cmd: 'updateAdminCommunity' }) updateAdminCommunity(@Payload() user: UserDocument) { + console.log(user); return this.userService.update(user._id, user); } diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index cc40ad7b..f75c7806 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -225,6 +225,24 @@ const AdministradoresComunidad = () => { ); } + const findIndexById = (id) => { + let index = -1; + for (let i = 0; i < listaAdmins.length; i++) { + if (listaAdmins[i]._id === id) { + index = i; + break; + } + } + return index; + + } + + const findRepeated = (name, value) => { + let _administrators = [...listaAdmins]; + let value_filtered = _administrators.filter(item => item[`${name}`] === value); + return value_filtered.length + } + const saveAdminCommunity = () => { let _administrators = [...listaAdmins]; let _admin = { ...adminCommunity }; @@ -289,16 +307,16 @@ const AdministradoresComunidad = () => { console.log(`Hubo un error en el servicio: ${response.status}`) else return response.json() }).then(() => { + toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Administrador de comunidad actualizado', life: 3000, }) - _administrators.push(_admin); toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador de Comunidad de vivienda Actualizada', life: 3000 }); - setListaAdmins(_administrators); + listaAdmin(); setAdminCommunity(emptyAdminCommunity); }) @@ -343,6 +361,7 @@ const AdministradoresComunidad = () => { const cancelEdit = () => { setAdminCommunity(emptyAdminCommunity); setSaveButtonTitle('Registrar'); + setC } const actionsAdminCommunity = (rowData) => {