diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 3417d20d..1dda5b22 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -202,6 +202,17 @@ export class AppController { return this.appService.findCommonArea(paramCommonAreaId); } + @Get('commonArea/findByCommunity/:community_id') + findByCommunity(@Param('community_id') paramCommunityId: string) { + 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 3f9b6dcd..89c337fb 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -277,6 +277,26 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + + //GET parameter from API + findByCommunity(paramCommunityId: string) { + const pattern = { cmd: 'findByCommunity' }; + const payload = { community_id: paramCommunityId }; + return this.clientCommonAreaApp + .send(pattern, payload) + .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 3fa8e1c6..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,13 @@ export class CommonAreasController { @MessagePattern({ cmd: 'removeCommonArea' }) remove(@Payload() id: string) { - let _id = id['_id']; + let _id = id['id']; return this.commonAreasService.remove(_id); } + + @MessagePattern({ cmd: 'findByCommunity' }) + findByCommunity(@Payload() id: string) { + let _community_id = id['community_id']; + return this.commonAreasService.findByCommunity(_community_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 a632a829..9135b5a2 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.service.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.service.ts @@ -32,6 +32,13 @@ export class CommonAreasService { } async remove(id: string) { - return this.commonAreaModel.findByIdAndRemove({ _id: id }).exec(); + 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/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index 06792ef5..69cd9f24 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -56,7 +56,9 @@ export class CommunitiesService { } async remove(id: string) { - return this.communityModel.findByIdAndRemove({ _id: id }).exec(); + return this.communityModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + new: true, + }); } async findCommunityAdmin(community: string, user_type: string) { diff --git a/servicio-foro-comunicaciones/src/post-comments/post-comments.service.ts b/servicio-foro-comunicaciones/src/post-comments/post-comments.service.ts index 4b8a0c0a..f82b71fa 100644 --- a/servicio-foro-comunicaciones/src/post-comments/post-comments.service.ts +++ b/servicio-foro-comunicaciones/src/post-comments/post-comments.service.ts @@ -33,6 +33,8 @@ export class PostCommentsService { } async remove(id: string) { - return this.commentModel.findByIdAndRemove({ _id: id }).exec(); + return this.commentModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + new: true, + }); } } diff --git a/servicio-invitados/src/guests/guests.service.ts b/servicio-invitados/src/guests/guests.service.ts index 97e1c4bd..02379936 100644 --- a/servicio-invitados/src/guests/guests.service.ts +++ b/servicio-invitados/src/guests/guests.service.ts @@ -32,6 +32,8 @@ export class GuestsService { } async remove(id: string) { - return this.guestModel.findByIdAndRemove({ _id: id }).exec(); + return this.guestModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + new: true, + }); } } diff --git a/servicio-reportes/src/reports/reports.service.ts b/servicio-reportes/src/reports/reports.service.ts index 37a68957..73bc7330 100644 --- a/servicio-reportes/src/reports/reports.service.ts +++ b/servicio-reportes/src/reports/reports.service.ts @@ -31,6 +31,9 @@ export class ReportsService { } async remove(id: string) { - return this.reportModel.findByIdAndRemove({ _id: id }).exec(); + return this.reportModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + new: true, + }); + } } diff --git a/servicio-reservaciones/src/reservations/reservations.service.ts b/servicio-reservaciones/src/reservations/reservations.service.ts index 8a681cd3..45382f50 100644 --- a/servicio-reservaciones/src/reservations/reservations.service.ts +++ b/servicio-reservaciones/src/reservations/reservations.service.ts @@ -41,6 +41,8 @@ export class ReservationsService { } async remove(id: string) { - return this.reservationModel.findByIdAndRemove({ _id: id }).exec(); + return this.reservationModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + new: true, + }); } } diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 1054116f..268ab49a 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -78,8 +78,14 @@ export class UsersService { }); } - async remove(id: string) { + /* async remove(id: string) { return this.userModel.findByIdAndRemove({ _id: id }).exec(); + }*/ + + async remove(id: string) { + return this.userModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + new: true, + }); } //inicio de sesion @@ -174,7 +180,9 @@ export class UsersService { } async deleteAdminSystem(id: string) { - return this.userModel.deleteOne({ _id: id }).exec(); + return this.userModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + new: true, + }); } async validateEmail(email: string) { diff --git a/web-ui/web-react/public/assets/themes/khaki/theme.css b/web-ui/web-react/public/assets/themes/khaki/theme.css index f051dbd7..10393ffd 100644 --- a/web-ui/web-react/public/assets/themes/khaki/theme.css +++ b/web-ui/web-react/public/assets/themes/khaki/theme.css @@ -89,8 +89,8 @@ } .p-icon-input-khaki { - border-top-right-radius: 0!important; - border-bottom-right-radius: 0!important; + border-top-right-radius: 0 !important; + border-bottom-right-radius: 0 !important; border-color: #C08135; } @@ -7126,4 +7126,34 @@ .row { display: flex; +} + + +.status { + border-radius: var(--border-radius); + padding: 0.25em 0.5rem; + text-transform: uppercase; + font-weight: 700; + font-size: 12px; + letter-spacing: 0.3px; +} + +.status.status-1 { + background: #c8e6c9!important; + color: #256029!important; +} + +.status.status-0 { + background: #ffcdd2; + color: #c63737; +} + +.status.status-2 { + background: #feedaf; + color: #8a5340; +} + +.status.status--1 { + background: #565656; + color: #f7f9f7; } \ No newline at end of file diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index dada19e8..46d3b946 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -51,6 +51,7 @@ import './assets/layout/layout.scss'; import './App.scss'; import LogIn from './components/LogIn'; import { PrimeIcons } from 'primereact/api'; +import AreasComunes from './components/AreasComunes'; const App = () => { const [layoutMode, setLayoutMode] = useState('static'); @@ -187,7 +188,16 @@ const App = () => { icon: PrimeIcons.BUILDING, to: '/comunidadesViviendas', }, - { label: 'Inquilinos', icon: PrimeIcons.USER, to: '/inquilinos' }, + { + label: 'Inquilinos', + icon: PrimeIcons.USER, + to: '/inquilinos' + }, + { + label: 'Áreas Comunes de Comunidad', + icon: PrimeIcons.BUILDING, + to: '/areasComunes', + }, { label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn' }, ], }, @@ -411,6 +421,7 @@ const App = () => { + diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index 3e8b8aa9..826f0619 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -344,15 +344,7 @@ const AdministradoresComunidad = () => { ) - const headerOptions = ( - <> -

- {' '} - {' '} - -

- - ) + const onInputChange = (e, name) => { const val = (e.target && e.target.value) || ''; @@ -388,9 +380,9 @@ const AdministradoresComunidad = () => { - - - + + +
diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 5d007e38..6b609bcf 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -313,15 +313,6 @@ const AdministradoresSistema = () => { ); - const headerOptions = ( - <> -

- Opciones{' '} - -

- - ); - return (
@@ -402,7 +393,6 @@ const AdministradoresSistema = () => { > { }} > diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js new file mode 100644 index 00000000..693467df --- /dev/null +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -0,0 +1,350 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { InputText } from 'primereact/inputtext'; +import { Button } from 'primereact/button'; +import { Dropdown } from 'primereact/dropdown'; +import { DataTable } from 'primereact/datatable'; +import { Column } from 'primereact/column'; +import { Toast } from 'primereact/toast'; +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 { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; +import { faAt } from '@fortawesome/free-solid-svg-icons'; +import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; +import { faClipboardCheck } from '@fortawesome/free-solid-svg-icons'; +import classNames from 'classnames'; +import { useCookies } from "react-cookie"; + + +const AreasComunes = () => { + + let emptyCommonArea = { + _id: null, + dni: '', + name: '', + hourMin: '', + hourMax: '', + community_id: '', + bookable: '1', + bookable_text: '', + status: '1', + status_text: '', + }; + + const [commonAreaList, setCommonAreaList] = useState([]); + const [commonArea, setCommonArea] = useState(emptyCommonArea); + const [selectedCommonAreas, setSelectedCommonAreas] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); + const [deleteCommonAreaDialog, setDeleteCommonAreaDialog] = useState(false); + const [deleteCommonAreasDialog, setDeleteCommonAreasDialog] = useState(false); + const [submitted, setSubmitted] = useState(false); + const toast = useRef(null); + const dt = useRef(null); + + const [cookies, setCookie] = useCookies(); + + async function getCommonAreas() { + await fetch(`http://localhost:4000/commonArea/findByCommunity/${cookies.community_id}`, { method: 'GET' }) + .then((response) => response.json()) + .then(data => data.message) + .then(data => { + if (data) { + data.map(item => { + 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); + }); + } + + useEffect(() => { + getCommonAreas(); + }, []); + + + const deleteCommonArea = () => { + 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 _common_areas = commonAreaList.filter( + (val) => !selectedCommonAreas.includes(val), + ); + 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({ + severity: 'success', + summary: 'Éxito', + detail: 'Áreas Comúnes Eliminadas', + life: 3000, + }); + }; + + const hideDeleteCommonAreaDialog = () => { + setDeleteCommonAreaDialog(false); + } + + const hideDeleteCommonAreasDialog = () => { + setDeleteCommonAreasDialog(false); + } + + const confirmDeleteCommonArea = (commonArea) => { + setCommonArea(commonArea); + setDeleteCommonAreaDialog(true); + } + + const confirmDeleteSelected = () => { + setDeleteCommonAreasDialog(true); + }; + + + + const actionsCommonArea = (rowData) => { + return ( +
+
+ ); + }; + + + const deleteCommonAreaDialogFooter = ( + <> +
+ + ) + } + + const rightToolbarTemplate = () => { + return ( + +