From 0175d9065d064eb4a544e5369ed06f2c7db8a3f3 Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 19 Aug 2022 14:15:05 -0600 Subject: [PATCH] 1 --- api-gateway/src/app.controller.ts | 6 ++ api-gateway/src/app.service.ts | 8 ++ .../src/users/users.controller.ts | 9 +- servicio-usuarios/src/users/users.service.ts | 7 ++ .../components/AdministradoresComunidad.js | 84 +++++++++---------- 5 files changed, 66 insertions(+), 48 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index ea569ede..94b6fc14 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -155,6 +155,12 @@ export class AppController { return this.appService.deleteAdminSystem(id); } + @Delete('user/deleteAdminCommunity/:id') + deleteAdminCommunity(@Param('id') id: string) { + return this.appService.deleteAdminCommunity(id); + } + + @Post('user/changeStatus') changeStatusUser( @Body('id') pId: string, diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 9dc93a79..42e9bf22 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -193,6 +193,14 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + deleteAdminCommunity(id: string) { + const pattern = { cmd: 'deleteAdminCommunity' }; + const payload = { id: id }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + inicioSesion(pEmail: string, pPassword: string) { const pattern = { cmd: 'loginUser' }; const payload = { email: pEmail, password: pPassword }; diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index a32d265d..e8f261a4 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -112,11 +112,16 @@ export class UsersController { @MessagePattern({ cmd: 'deleteAdminSystem' }) deleteAdminSystem(@Payload() user: any) { - console.log('entró'); - return this.userService.deleteAdminSystem(user['id']); } + + @MessagePattern({ cmd: 'deleteAdminCommunity' }) + deleteAdminCommunity(@Payload() user: any) { + return this.userService.deleteAdminCommunity(user['id']); + } + + @MessagePattern({ cmd: 'changeStatus' }) changeStatus(@Payload() body: string) { diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 2015ef45..0cd70023 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -185,6 +185,13 @@ export class UsersService { }); } + + deleteAdminCommunity(id: string) { + return this.userModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + new: true, + }); + } + async validateEmail(email: string) { let repo1 = this.userModel; return new Promise((resolve, reject) => { diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index 94a5389f..0ec73891 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -117,64 +117,56 @@ const AdministradoresComunidad = () => { const deleteAdminCommunity = () => { - /* fetch('http://localhost:4000/community/deleteCommunity/' + community._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 _community = communities.filter(val => val._id !== community._id); - setCommunities(_community); - setDeleteCommunityDialog(false); - setCommunity(emptyCommunity); - toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 }); - } - ) - .catch( - err => { - console.log('Ocurrió un error con el fetch', err) - toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 }); - } - ); - */ - let _administrators = listaAdmins.filter( - (val) => val._id !== adminCommunity._id, - ); - setListaAdmins(_administrators); - setDeleteAdminCommunityDialog(false); - setAdminCommunity(emptyAdminCommunity); - toast.current.show({ - severity: 'success', - summary: 'Administrador de Comunidad Eliminada', - life: 3000, - }); + fetch('http://localhost:4000/user/deleteAdminCommunity/' + adminCommunity._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 _administrators = listaAdmins.filter( + (val) => val._id !== adminCommunity._id, + ); + setListaAdmins(_administrators); + setDeleteAdminCommunityDialog(false); + setAdminCommunity(emptyAdminCommunity); + toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador Comunidad Eliminada', life: 3000 }); + } + ) + .catch( + err => { + console.log('Ocurrió un error con el fetch', err) + toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Administrador Comunidad no se pudo eliminar', life: 3000 }); + } + ); + + }; const deleteSelectedAdminsCommunity = () => { let _admins = listaAdmins.filter( (val) => !selectedAdminsCommunities.includes(val), ); - /* selectedCommunities.map((item) => { - fetch('http://localhost:4000/user/deleteCommunity/' + item._id, { + selectedAdminsCommunities.map((item) => { + fetch('http://localhost:4000/user/deleteAdminCommunity/' + item._id, { cache: 'no-cache', method: 'DELETE', headers: { 'Content-Type': 'application/json' } }) - })*/ + }) setListaAdmins(_admins); setDeleteAdminsCommunitiesDialog(false); setSelectedAdminsCommunities(null);