diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 715a1d92..76e6d442 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -536,6 +536,12 @@ export class AppController { return this.appService.findReservation(paramReservation); } + @Get('reservation/findReservations/:id') + findReservations(@Param('id') community_id: string) { + return this.appService.findReservations(community_id); + } + + // #==== API Post @Post('post/createPost') diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index f9cf4f9d..50beb9f6 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -325,12 +325,12 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } - updateAdminSystem(_id: string, dni: string, name: string, + updateAdminSystem(_id: string, dni: string, name: string, last_name: string, email: string, phone: number - ) { + ) { const pattern = { cmd: 'updateAdminSystem' }; const payload = { - _id: _id, dni: dni, name: name, last_name: last_name, + _id: _id, dni: dni, name: name, last_name: last_name, email: email, phone: phone }; return this.clientUserApp @@ -453,7 +453,7 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } - + // ====================== COMMON AREAS =============================== //POST parameter from API createCommonArea( @@ -644,6 +644,14 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + findReservations(community_id: string) { + const pattern = { cmd: 'findReservationsByCommunity' }; + const payload = { community_id: community_id }; + return this.clientReservationApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + // ====================== POSTS =============================== //POST parameter from API diff --git a/servicio-reservaciones/src/reservations/reservations.controller.ts b/servicio-reservaciones/src/reservations/reservations.controller.ts index ea6a2553..5089ba2b 100644 --- a/servicio-reservaciones/src/reservations/reservations.controller.ts +++ b/servicio-reservaciones/src/reservations/reservations.controller.ts @@ -28,6 +28,12 @@ export class ReservationsController { return this.reservationsService.findOne(_id); } + @MessagePattern({ cmd: 'findReservationsByCommunity' }) + findReservationsByCommunity(@Payload() body: string) { + let community_id = body['community_id']; + return this.reservationsService.findReservationsByCommunity(community_id); + } + @MessagePattern({ cmd: 'updateReservation' }) update(@Payload() reservation: ReservationDocument) { return this.reservationsService.update(reservation.id, reservation); diff --git a/servicio-reservaciones/src/reservations/reservations.service.ts b/servicio-reservaciones/src/reservations/reservations.service.ts index c56174f1..ce338270 100644 --- a/servicio-reservaciones/src/reservations/reservations.service.ts +++ b/servicio-reservaciones/src/reservations/reservations.service.ts @@ -49,4 +49,9 @@ export class ReservationsService { async removeIdCommunity(community_id: string){ await this.reservationModel.updateMany({community_id: community_id}, {"$set":{"status": '-1'}}); } + + + async findReservationsByCommunity(community_id: string){ + return this.reservationModel.find({ community_id: community_id }).exec(); + } } diff --git a/servicio-reservaciones/src/schemas/reservation.schema.ts b/servicio-reservaciones/src/schemas/reservation.schema.ts index a9ebd5b1..c51bf2d9 100644 --- a/servicio-reservaciones/src/schemas/reservation.schema.ts +++ b/servicio-reservaciones/src/schemas/reservation.schema.ts @@ -23,15 +23,12 @@ export class Reservation { @Prop() common_area_name: string; - - @Prop() - community_id: string; - @Prop() user_id: string; @Prop() community_id: string; + } export const ReservationSchema = SchemaFactory.createForClass(Reservation); 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 cbdfe8aa..7ffdbdf3 100644 --- a/web-ui/web-react/public/assets/themes/khaki/theme.css +++ b/web-ui/web-react/public/assets/themes/khaki/theme.css @@ -7163,4 +7163,8 @@ display: flex; flex-direction: column; align-items: center; +} + +.layout-config-button{ + display: none!important; } \ 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 1551381d..164aaa17 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -56,6 +56,7 @@ import AreasComunes from './components/AreasComunes'; import { useCookies } from "react-cookie"; import LogInUser from './components/LogInUser'; import Page404 from './components/Page404' +import Reservaciones from './components/Reservaciones'; const App = () => { @@ -202,6 +203,7 @@ const App = () => { to: '/areasComunes', }, + { label: 'Reservaciones', icon: PrimeIcons.CALENDAR, to: '/reservaciones'}, { label: 'Comunicados', icon: PrimeIcons.COMMENTS, to: '/registroComunicado'}, ] @@ -467,6 +469,7 @@ const App = () => { + ) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index adf8b3bf..a3f47866 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -107,6 +107,7 @@ const AdministradoresSistema = () => { } else { if (_admin._id) { + fetch('http://localhost:4000/user/updateAdminSystem/', { cache: 'no-cache', method: 'POST', diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js new file mode 100644 index 00000000..f14d9adf --- /dev/null +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -0,0 +1,355 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { InputText } from 'primereact/inputtext'; +import { Button } from 'primereact/button'; +import { DataTable } from 'primereact/datatable'; +import { Column } from 'primereact/column'; +import { Dropdown } from 'primereact/dropdown'; +import { Toast } from 'primereact/toast'; +import classNames from 'classnames'; +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 { faClockFour } from '@fortawesome/free-solid-svg-icons'; +import { useCookies } from 'react-cookie'; + +const Reservations = () => { + let emptyReservation = { + _id: null, + start_time: '', + finish_time: '', + user_id: '', + user_name: '', + common_area_id: '', + common_area_name: '', + community_id: '', + status: '1', + status_text: '', + date_entry: new Date(), + }; + + + const [reservations, setReservations] = useState([]); + const [reservation, setReservation] = useState(emptyReservation); + const [submitted, setSubmitted] = useState(false); + const [selectedReservations, setSelectedReservations] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); + const [deleteReservationDialog, setDeleteReservationDialog] = useState(false); + const [deleteReservationsDialog, setDeleteReservationsDialog] = useState(false); + const toast = useRef(null); + const dt = useRef(null); + const [cookies, setCookies] = useCookies() + const [areas, setAreas] = useState([]); + const [tenants, setTenants] = useState([]); + + async function tenantsList(id) { + await fetch(`http://localhost:4000/user/findTenants/${id}`, + { method: 'GET' }) + .then((response) => response.json()) + .then(data => data.message) + .then(data => { + data = data.filter( + (val) => val.status != -1, + ) + data = data.map(item => { + item.password = ''; + return item; + }) + setTenants(data) + }); + } + + async function areasList(id) { + await fetch(`http://localhost:4000/commonArea/findByCommunity/${id}`, + { method: 'GET' }) + .then((response) => response.json()) + .then(data => data.message) + .then(data => { + data = data.filter( + (val) => val.status != -1, + ) + setAreas(data) + }); + } + + async function reservationList(id) { + await fetch(`http://localhost:4000/reservation/findReservations/${id}`, + { method: 'GET' }) + .then((response) => response.json()) + .then(data => data.message) + .then(data => { + data = data.filter( + (val) => val.status != -1, + ) + data.map((item) => { + if (item.status == '1') { + item.status_text = 'Activo'; + } else if (item.status == '0') { + item.status_text = 'Inactivo'; + } + }) + + setReservations(data) + }); + } + + useEffect(() => { + tenantsList(cookies.community_id); + }, []) + + useEffect(() => { + areasList(cookies.community_id); + }, []) + + + reservations.map((item) => { + let tenant = tenants.find(item2 => item2._id == item.user_id); + if(tenant){ + item.user_name = tenant.name + ' ' + tenant.last_name; + } + }); + + + useEffect(() => { + reservationList(cookies.community_id); + }, []) + + + + + const actionsReservation = (rowData) => { + + + return ( +
+
+ ); + }; + + + + const confirmDeleteReservation = (reservation) => { + setReservation(reservation); + setDeleteReservationDialog(true); + }; + + const confirmDeleteSelected = () => { + setDeleteReservationsDialog(true); + }; + + const leftToolbarTemplate = () => { + return ( + +
+
+
+ ); + }; + + const rightToolbarTemplate = () => { + return ( + +