diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 76e6d442..f6bf3ab0 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -505,24 +505,24 @@ export class AppController { @Post('reservation/createReservation') createReservation( - @Body('start_time') start_time: string, - @Body('finish_time') finish_time: string, + @Body('date') date: string, + @Body('time') time: string, @Body('status') status: string, @Body('date_entry') date_entry: Date, @Body('user_id') user_id: string, @Body('common_area_id') common_area_id: string, @Body('common_area_name') common_area_name: string, - @Body('communty_id') communty_id: string, + @Body('community_id') community_id: string, ) { return this.appService.createReservation( - start_time, - finish_time, + date, + time, status, date_entry, user_id, common_area_id, common_area_name, - communty_id, + community_id, ); } diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 50beb9f6..380e23d1 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -613,14 +613,14 @@ export class AppService { // ====================== RESERVATIONS =============================== //POST parameter from API - createReservation(start_time: string, finish_time: string, status: string, + createReservation(date: string, time: string, status: string, date_entry: Date, user_id: string, common_area_id: string, - common_area_name: string, communty_id: string) { + common_area_name: string, community_id: string) { const pattern = { cmd: 'createReservation' }; const payload = { - start_time: start_time, finish_time: finish_time, status: status, + date: date, time: time, status: status, date_entry: date_entry, user_id: user_id, common_area_id: common_area_id, - common_area_name: common_area_name, communty_id: communty_id + common_area_name: common_area_name, community_id: community_id }; return this.clientReservationApp .send(pattern, payload) diff --git a/servicio-reservaciones/src/reservations/reservations.service.ts b/servicio-reservaciones/src/reservations/reservations.service.ts index ce338270..a7ab73d2 100644 --- a/servicio-reservaciones/src/reservations/reservations.service.ts +++ b/servicio-reservaciones/src/reservations/reservations.service.ts @@ -14,8 +14,6 @@ export class ReservationsService { ) {} create(reservation: ReservationDocument) { - console.log(reservation); - return this.reservationModel.create(reservation); } diff --git a/servicio-reservaciones/src/schemas/reservation.schema.ts b/servicio-reservaciones/src/schemas/reservation.schema.ts index c51bf2d9..857868cf 100644 --- a/servicio-reservaciones/src/schemas/reservation.schema.ts +++ b/servicio-reservaciones/src/schemas/reservation.schema.ts @@ -6,10 +6,10 @@ export type ReservationDocument = Reservation & Document; @Schema({ collection: 'reservations' }) export class Reservation { @Prop() - start_time: string; + date: Date; @Prop() - finish_time: string; + time: string; @Prop() status: string; diff --git a/web-ui/web-react/public/index.html b/web-ui/web-react/public/index.html index 72e2d161..69324c7a 100644 --- a/web-ui/web-react/public/index.html +++ b/web-ui/web-react/public/index.html @@ -1,5 +1,5 @@ - + Katoikia diff --git a/web-ui/web-react/src/AppFooter.js b/web-ui/web-react/src/AppFooter.js index fb9f6951..71548902 100644 --- a/web-ui/web-react/src/AppFooter.js +++ b/web-ui/web-react/src/AppFooter.js @@ -13,8 +13,8 @@ export const AppFooter = (props) => { height="20" className="mr-2" /> - by - PrimeReact + por + Deimos ); }; diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index 8d2fdeec..42b24186 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -316,7 +316,6 @@ const AdministradoresComunidad = () => { detail: 'Administrador de comunidad actualizado', life: 3000, }) - toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador de Comunidad de vivienda Actualizada', life: 3000 }); listaAdmin(); setCommunityId(''); diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index f14d9adf..dcf2228e 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -17,8 +17,8 @@ import { useCookies } from 'react-cookie'; const Reservations = () => { let emptyReservation = { _id: null, - start_time: '', - finish_time: '', + date: '', + time: '', user_id: '', user_name: '', common_area_id: '', @@ -41,7 +41,15 @@ const Reservations = () => { const dt = useRef(null); const [cookies, setCookies] = useCookies() const [areas, setAreas] = useState([]); + const [area, setArea] = useState(); + const [areaId, setAreaId] = useState(); const [tenants, setTenants] = useState([]); + const [tenantId, setTenantId] = useState(); + const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar") + const [reservationDialog, setReservationDialog] = useState(false); + const [dateMax, setDateMax] = useState(); + const [tenants, setTenants] = useState([]); + async function tenantsList(id) { await fetch(`http://localhost:4000/user/findTenants/${id}`, @@ -67,7 +75,10 @@ const Reservations = () => { .then(data => data.message) .then(data => { data = data.filter( - (val) => val.status != -1, + (val) => val.status != -1 + ) + data = data.filter( + (val) => val.bookable == 1, ) setAreas(data) }); @@ -83,6 +94,7 @@ const Reservations = () => { (val) => val.status != -1, ) data.map((item) => { + item.date = formatDateString(item.date) if (item.status == '1') { item.status_text = 'Activo'; } else if (item.status == '0') { @@ -105,8 +117,8 @@ const Reservations = () => { reservations.map((item) => { let tenant = tenants.find(item2 => item2._id == item.user_id); - if(tenant){ - item.user_name = tenant.name + ' ' + tenant.last_name; + if (tenant) { + item.user_name = tenant.name + ' ' + tenant.last_name; } }); @@ -115,12 +127,60 @@ const Reservations = () => { reservationList(cookies.community_id); }, []) + const saveReservation = () => { + let _reservations = [...reservations]; + let _reservation = { ...reservation }; + if (_reservation.date && _reservation.time && tenantId && areaId + && !validationTime() + && !validationIsSameUser() && !validationIsReservation()) { + _reservation.common_area_name = areas.find(item => item._id == areaId).name; + let tenant = tenants.find(item => item._id == tenantId); + _reservation.user_name = tenant.name + ' ' + tenant.last_name; + _reservation.user_id = tenantId; + _reservation.common_area_id = areaId; + _reservation.community_id = cookies.community_id; + _reservation.date = formatDateString(_reservation.date) + + if (_reservation.status == '1') { + _reservation.status_text = 'Activo'; + } else if (_reservation.status == '0') { + _reservation.status_text = 'Inactivo'; + } + fetch('http://localhost:4000/reservation/createReservation/', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(_reservation), + headers: { + 'Content-Type': 'application/json' + } + }) + .then((response) => { + if (response.status !== 200 && response.status !== 201) + console.log(`Hubo un error en el servicio: ${response.status}`) + else return response.json() + }).then(() => { + _reservations.push(_reservation); + setReservations(_reservations) + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Reservación realizada', + life: 3000, + }); + + setReservationDialog(false) + setAreaId('') + setTenantId('') + }) + + } else { + setSubmitted(true); + } + } const actionsReservation = (rowData) => { - - return (
); }; - - - + const confirmDeleteReservation = (reservation) => { setReservation(reservation); setDeleteReservationDialog(true); @@ -144,10 +202,37 @@ const Reservations = () => { setDeleteReservationsDialog(true); }; + const cancelEdit = () => { + setReservation(emptyReservation); + setSaveButtonTitle('Registrar'); + setAreaId(''); + setTenantId(''); + } + + const hideNewReservationDialog = () => { + setSubmitted(false); + setReservationDialog(false); + setReservation(emptyReservation); + setAreaId(''); + setTenantId(''); + }; + + const openNewReservation = () => { + setReservation(emptyReservation); + setReservationDialog(true); + setSubmitted(false); + + }; const leftToolbarTemplate = () => { return (
+
+ + )} + - - - ); - - } export default React.memo(Reservations);