From 99064e9a4db274a5f5d59d9682d7e67b91e98e42 Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 19 Aug 2022 00:02:08 -0600 Subject: [PATCH 1/3] cambiar status en frontend --- .../src/components/AdministradoresSistema.js | 3 +- .../web-react/src/components/AreasComunes.js | 111 +++++++++++++++++- 2 files changed, 111 insertions(+), 3 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 10f299f2..a301c3ed 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -44,7 +44,6 @@ const AdministradoresSistema = () => { status_text: '', }; - async function fetchP() { let nombres = await fetch(urlFetch, { method: 'GET' }); let adminRes = await nombres.json(); @@ -60,11 +59,11 @@ const AdministradoresSistema = () => { }) setAdministrators(await data); } + useEffect(() => { fetchP(); }, []) - function registrarAdmin() { var data = { dni: document.getElementById('identificacion').value, diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js index 0850e31c..7b0b6fd8 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -43,6 +43,7 @@ const AreasComunes = () => { const dt = useRef(null); const [cookies, setCookie] = useCookies(); + const [changeStatusAreaDialog, setChangeStatusAreaDialog] = useState(false); @@ -220,6 +221,51 @@ const AreasComunes = () => { }); }; + const cambiarStatuscommonArea = () => { + if (commonArea.status == '1') { + commonArea.status = '0'; + commonArea.status_text = 'Inactivo'; + + } else if (commonArea.status == '0') { + commonArea.status = '1'; + commonArea.status_text = 'Activo'; + } + var data = { + id: commonArea._id, + status: commonArea.status, + }; + fetch('http://localhost:4000/commonArea/changeStatus', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(data), + 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) { + setChangeStatusAreaDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Área Común Actualizada', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } + const hideDeleteCommonAreaDialog = () => { setDeleteCommonAreaDialog(false); } @@ -237,9 +283,36 @@ const AreasComunes = () => { setDeleteCommonAreasDialog(true); }; + + + const hideChangeStatusAreaDialog = () => { + setChangeStatusAreaDialog(false); + }; + + const confirmChangeStatusArea = (commonArea) => { + setCommonArea(commonArea); + setChangeStatusAreaDialog(true); + }; + const actionsCommonArea = (rowData) => { + let icono = ''; + let text = ''; + if (rowData.status == '0') { + icono = "pi pi-eye"; + text = "Activar Área Común" + } else if (rowData.status == '1') { + icono = "pi pi-eye-slash"; + text = "Inactivar Área Común" + } + return (
+
+ +
+ + {commonArea && ( + + ¿Estás seguro que desea cambiar estado a {commonArea.name}? + + )} +
+
@@ -513,7 +622,7 @@ const AreasComunes = () => {
-
+
Date: Fri, 19 Aug 2022 00:04:11 -0600 Subject: [PATCH 2/3] change status en service --- .../src/common_areas/common_areas.controller.ts | 8 ++++++++ .../src/common_areas/common_areas.service.ts | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/servicio-areas-comunes/src/common_areas/common_areas.controller.ts b/servicio-areas-comunes/src/common_areas/common_areas.controller.ts index b4374c7d..28b5ce7e 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.controller.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.controller.ts @@ -39,4 +39,12 @@ export class CommonAreasController { let _community_id = id['community_id']; return this.commonAreasService.findByCommunity(_community_id); } + + //cambiar de estado + @MessagePattern({ cmd: 'changeStatus' }) + changeStatus(@Payload() body: string) { + let pid = body['id']; + let pstatus = body['status']; + return this.commonAreasService.changeStatus(pid,pstatus); + } } diff --git a/servicio-areas-comunes/src/common_areas/common_areas.service.ts b/servicio-areas-comunes/src/common_areas/common_areas.service.ts index 9135b5a2..e617df0c 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.service.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.service.ts @@ -41,4 +41,10 @@ export class CommonAreasService { return this.commonAreaModel.find({ community_id: community_id }).exec(); } + async changeStatus(id: string, status: string) { + return this.commonAreaModel.findOneAndUpdate({ _id: id }, {status: status}, { + new: true, + }); + } + } From e1bcdd3995b0d1ed4e9b855fb03f70e07461bd0e Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 19 Aug 2022 00:19:15 -0600 Subject: [PATCH 3/3] api change status --- api-gateway/src/app.controller.ts | 10 ++++++++++ api-gateway/src/app.service.ts | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index abc90be1..ea569ede 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -215,6 +215,8 @@ export class AppController { ) { return this.appService.changeStatusCommunity(pId, pStatus); } + + // #==== API Common Areas @Post('commonArea/createCommonArea') createCommonArea( @@ -254,6 +256,14 @@ export class AppController { return this.appService.deleteCommonArea(id); } + @Post('commonArea/changeStatus') + changeStatusCommonArea( + @Body('id') pId: string, + @Body('status') pStatus: string, + ) { + return this.appService.changeStatusCommonArea(pId, pStatus); + } + // #==== API GUEST //#API userService - create user @Post('guest/createGuest') diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index a5df9129..9dc93a79 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -343,6 +343,15 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + changeStatusCommonArea(pId: string, pStatus: string) { + const pattern = { cmd: 'changeStatus' }; + const payload = { id: pId, status: pStatus }; + return this.clientCommonAreaApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + + // ====================== GUESTS =============================== //POST parameter from API