diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index ff53abf1..18196445 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -196,6 +196,12 @@ export class AppController { return this.appService.findByCommunity(paramCommunityId); } + + @Delete('commonArea/deleteCommonArea/:id') + deleteCommonArea(@Param('id') id: string) { + return this.appService.deleteCommonArea(id); + } + // #==== 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 426764c0..c7474c8d 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -258,6 +258,16 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + + //DELETE parameter from API + deleteCommonArea(paramCommonAreaId: string) { + const pattern = { cmd: 'removeCommonArea' }; + const payload = { id: paramCommonAreaId }; + return this.clientCommonAreaApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + // ====================== GUESTS =============================== //POST parameter from API 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 08d2866a..b4374c7d 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.controller.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.controller.ts @@ -30,7 +30,7 @@ export class CommonAreasController { @MessagePattern({ cmd: 'removeCommonArea' }) remove(@Payload() id: string) { - let _id = id['_id']; + let _id = id['id']; return this.commonAreasService.remove(_id); } 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 142b527a..9135b5a2 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.service.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.service.ts @@ -35,7 +35,7 @@ export class CommonAreasService { return this.commonAreaModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { new: true, }); - } + }; async findByCommunity(community_id: string): Promise { return this.commonAreaModel.find({ community_id: community_id }).exec(); diff --git a/servicio-areas-comunes/src/schemas/common_area.schema.ts b/servicio-areas-comunes/src/schemas/common_area.schema.ts index c01a32d8..927cdbbb 100644 --- a/servicio-areas-comunes/src/schemas/common_area.schema.ts +++ b/servicio-areas-comunes/src/schemas/common_area.schema.ts @@ -19,6 +19,9 @@ export class CommonArea { @Prop() bookable: number; //saber si es necesario reservarlo o no + @Prop() + status: string; + @Prop() community_id: string; } diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js index 7eefc66c..693467df 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -9,11 +9,10 @@ import { Dialog } from 'primereact/dialog'; import { Toolbar } from 'primereact/toolbar'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons'; -import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; +import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; import { faAt } from '@fortawesome/free-solid-svg-icons'; import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; -import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; -import { faHomeAlt } from '@fortawesome/free-solid-svg-icons'; +import { faClipboardCheck } from '@fortawesome/free-solid-svg-icons'; import classNames from 'classnames'; import { useCookies } from "react-cookie"; @@ -29,6 +28,8 @@ const AreasComunes = () => { community_id: '', bookable: '1', bookable_text: '', + status: '1', + status_text: '', }; const [commonAreaList, setCommonAreaList] = useState([]); @@ -48,15 +49,27 @@ const AreasComunes = () => { .then((response) => response.json()) .then(data => data.message) .then(data => { - if(data) { + if (data) { data.map(item => { - if(item.bookable == '1') { - item.bookable_text = 'Disponible'; - } else{ - item.bookable_text = 'Cerrado'; + if (item.bookable == '1') { + item.bookable_text = 'Necesaria'; + } else { + item.bookable_text = 'No es necesarioa'; + } + + if (item.status == '1') { + item.status_text = 'Activo'; + } else if (item.status == '0') { + item.status_text = 'Inactivo'; + } else { + item.status_text = 'Eliminado'; } }) } + + data = data.filter( + (val) => val.status != -1, + ) setCommonAreaList(data); }); } @@ -67,65 +80,66 @@ const AreasComunes = () => { const deleteCommonArea = () => { - /* 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 _common_areas = commonAreaList.filter( - (val) => val._id !== commonArea._id, - ); - setCommonAreaList(_common_areas); - setDeleteCommonAreaDialog(false); - setCommonArea(emptyCommonArea); - toast.current.show({ - severity: 'success', - summary: 'Área Común Eliminada', - life: 3000, - }); + fetch('http://localhost:4000/commonArea/deleteCommonArea/' + commonArea._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 _common_areas = commonAreaList.filter( + (val) => val._id !== commonArea._id, + ); + _common_areas = _common_areas.filter( + (val) => val.status != -1, + ) + setCommonAreaList(_common_areas); + setDeleteCommonAreaDialog(false); + setCommonArea(emptyCommonArea); + toast.current.show({ + severity: 'success', + summary: 'Área Común Eliminada', + life: 3000, + }); + } + ) + .catch( + err => { + console.log('Ocurrió un error con el fetch', err) + toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Área Común no se pudo eliminar', life: 3000 }); + } + ); + }; const deleteSelectedCommonAreas = () => { - let _commonareas = commonAreaList.filter( + let _common_areas = commonAreaList.filter( (val) => !selectedCommonAreas.includes(val), ); - /* selectedCommunities.map((item) => { - fetch('http://localhost:4000/user/deleteCommunity/' + item._id, { - cache: 'no-cache', - method: 'DELETE', - headers: { - 'Content-Type': 'application/json' - } - }) - })*/ - setCommonAreaList(_commonareas); + selectedCommonAreas.map((item) => { + fetch('http://localhost:4000/commonArea/deleteCommonArea/' + item._id, { + cache: 'no-cache', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + } + }) + }); + _common_areas = _common_areas.filter( + (val) => val.status != -1, + ) + setCommonAreaList(_common_areas); setDeleteCommonAreasDialog(false); setSelectedCommonAreas(null); toast.current.show({ @@ -246,24 +260,52 @@ const AreasComunes = () => { const headerBookable = ( <>

{' '} - {' '} - Reservable + {' '} + Reservación +

+ + ) + + const headerStatus = ( + <> +

{' '} + {' '} + Estado

) + const bookableBodyTemplate = (rowData) => { + let class_color = ''; + if(rowData.bookable == '1') { + class_color = '0'; + } else { + class_color = '1'; + + } + return ( + <> + + {rowData.bookable_text} + + + ); + }; + const statusBodyTemplate = (rowData) => { return ( - <> - - {rowData.bookable_text} - - + <> + + {rowData.status_text} + + ); - }; + }; return (
@@ -279,9 +321,10 @@ const AreasComunes = () => { globalFilter={globalFilter} emptyMessage="No hay áreas comunes registrados."> - - - + + + +