From b9f04f722144d53372a6d742076c78ea1036c54d Mon Sep 17 00:00:00 2001 From: Traym17 <51390112+Traym17@users.noreply.github.com> Date: Mon, 1 Aug 2022 23:12:58 -0600 Subject: [PATCH] Backend del servicio para activar y desactivar una comunidad de vivienda --- api-gateway/src/app.controller.ts | 8 +++++++- api-gateway/src/app.service.ts | 7 +++++++ .../src/communities/communities.controller.ts | 10 ++++++++++ .../src/communities/communities.service.ts | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 18196445..00f6f283 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -162,7 +162,13 @@ export class AppController { findCommunityAdmin(@Body('community_id') community_id: string) { return this.appService.findCommunityAdmin(community_id); } - + @Post('community/changeStatus') + changeStatus( + @Body('id') pId: string, + @Body('status') pStatus: string, + ) { + return this.appService.changeStatus(pId, pStatus); + } // #==== API Common Areas @Post('commonArea/createCommonArea') createCommonArea( diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index c7474c8d..fbfbf706 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -161,6 +161,13 @@ export class AppService { .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } + changeStatus(pId: string, pStatus: string) { + const pattern = { cmd: 'changeStatus' }; + const payload = { id: pId, status: pStatus }; + return this.clientCommunityApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } // ====================== COMMUNITIES =============================== diff --git a/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index 16af1dda..b9f75310 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -45,4 +45,14 @@ export class CommunitiesController { let _id = id['_id']; return this.communitiesService.remove(_id); } + + //cambiar de estado + @MessagePattern({ cmd: 'changeStatus' }) + changeStatus(@Payload() body: string) { + let pid = body['id']; + let pstatus = body['status']; + console.log(pid); + console.log(pstatus); + return this.communitiesService.changeStatus(pid,pstatus); + } } diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index 69cd9f24..8b5ce685 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -61,6 +61,12 @@ export class CommunitiesService { }); } + async changeStatus(id: string, status: string) { + return this.communityModel.findOneAndUpdate({ _id: id }, {status: status}, { + new: true, + }); + } + async findCommunityAdmin(community: string, user_type: string) { const pattern = { cmd: 'findOneCommunityUser' }; const payload = { community_id: community, user_type: user_type };