diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 3753431b..4def7296 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -323,6 +323,11 @@ export class AppController { ) { return this.appService.saveTenant(community_id, number_house, tenant_id); } + + @Delete('community/deleteCommunity/:id') + deleteCommunity(@Param('id') paramCommunityId: string) { + return this.appService.deleteCommunity(paramCommunityId); + } // #==== API Common Areas @Post('commonArea/createCommonArea') createCommonArea( diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 1e173a1c..fbe5a423 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -407,6 +407,15 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + deleteCommunity(id: string) { + const pattern = { cmd: 'removeCommunity' }; + const payload = { _id: id }; + return this.clientCommunityApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + + // ====================== COMMON AREAS =============================== //POST parameter from API createCommonArea( diff --git a/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index a0fa2672..f71e2524 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -5,7 +5,7 @@ import { Community, CommunityDocument } from 'src/schemas/community.schema'; @Controller() export class CommunitiesController { - constructor(private readonly communitiesService: CommunitiesService) {} + constructor(private readonly communitiesService: CommunitiesService) { } @MessagePattern({ cmd: 'createCommunity' }) create(@Payload() community: CommunityDocument) { @@ -46,17 +46,17 @@ export class CommunitiesController { return this.communitiesService.remove(_id); } - //cambiar de estado - @MessagePattern({ cmd: 'changeStatus' }) - changeStatus(@Payload() body: string) { - let pid = body['id']; - let pstatus = body['status']; - return this.communitiesService.changeStatus(pid,pstatus); - } + //cambiar de estado + @MessagePattern({ cmd: 'changeStatus' }) + changeStatus(@Payload() body: string) { + let pid = body['id']; + let pstatus = body['status']; + return this.communitiesService.changeStatus(pid, pstatus); + } - @MessagePattern({ cmd: 'saveTenant' }) - saveTenant(@Payload() body: string) { + @MessagePattern({ cmd: 'saveTenant' }) + saveTenant(@Payload() body: string) { let id = body['_id']; let tenant_id = body['tenant_id']; @@ -66,9 +66,9 @@ export class CommunitiesController { @MessagePattern({ cmd: 'deleteTenant' }) deleteTenant(@Payload() body: string) { - let id = body['_id']; - let tenant_id = body['tenant_id']; - let number_house = body['number_house']; - return this.communitiesService.deleteTenant(id, number_house, tenant_id); - } + let id = body['_id']; + let tenant_id = body['tenant_id']; + let number_house = body['number_house']; + return this.communitiesService.deleteTenant(id, number_house, tenant_id); + } } diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index dc3773e7..93f7cbe2 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -57,6 +57,7 @@ export class CommunitiesService { } async remove(id: string) { + await this.removeIdCommunity(id); return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, { new: true, }); @@ -119,4 +120,16 @@ export class CommunitiesService { new: true, }); } + + async removeIdCommunity(community: string) { + const pattern = { cmd: 'removeIdCommunity' }; + const payload = { community_id: community}; + + let callback = await this.clientUserApp + .send(pattern, payload) + .pipe(map((response: string) => ({ response }))); + + const finalValue = await lastValueFrom(callback); + return finalValue['response']; + } } diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index be7deb01..53f32074 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -142,6 +142,13 @@ export class UsersController { user['number_house']); } + @MessagePattern({ cmd: 'removeIdCommunity' }) + removeIdCommunity(@Payload() user: any) { + let community_id = user['community_id']; + return this.userService.removeIdCommunity(community_id); + } + + @MessagePattern({ cmd: 'changeStatus' }) changeStatus(@Payload() body: string) { let pid = body['id']; diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 1393b2bd..bc8ea288 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -295,5 +295,11 @@ export class UsersService { map((response: string) => ({ response })) ) } + + async removeIdCommunity(community_id: string){ + return this.userModel.updateMany({community_id: community_id, user_type:'2' }, {"$set":{"community_id": ''}}); + /*await this.userModel.updateMany({community_id: community_id, user_type:'3' }, {"$set":{"community_id": ''}, {"status": '-1'}}); + return this.userModel.updateMany({community_id: community_id, user_type:'4' }, {"$set":{"community_id": ''}, {"status": '-1'}});*/ + } } diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index 2821bd20..68378ab7 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -315,10 +315,8 @@ const Communities = () => { setDeleteCommunitiesDialog(true); }; - const infoCommunity = async (community) => { await tenantsList(community._id); - setCommunity({ ...community }); setCommunityDialog(true); }; @@ -383,40 +381,38 @@ const Communities = () => { ); } - const deleteCommunity = () => { - /* 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 }); - } - ); - */ + 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 _communities = communitiesList.filter((val) => val._id !== community._id); _communities = _communities.filter( (val) => val.status != -1,