From 1da7b2c63f0e54a911c840a15e2a529ec96586c1 Mon Sep 17 00:00:00 2001 From: Mariela Date: Wed, 24 Aug 2022 16:14:33 -0600 Subject: [PATCH 01/11] =?UTF-8?q?=C3=81reacom=C3=BAnparainquilino:=20Auto?= =?UTF-8?q?=20stash=20before=20merge=20of=20"US-30-Reservar=C3=81reacom?= =?UTF-8?q?=C3=BAnparainquilino"=20and=20"US-32-ListarReservas"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web-react/src/components/Reservaciones.js | 74 ++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index f14d9adf..70cf6275 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -41,7 +41,9 @@ const Reservations = () => { const dt = useRef(null); const [cookies, setCookies] = useCookies() const [areas, setAreas] = useState([]); + const [areaId, setAreaId] = useState(); const [tenants, setTenants] = useState([]); + const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar") async function tenantsList(id) { await fetch(`http://localhost:4000/user/findTenants/${id}`, @@ -105,8 +107,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,7 +117,13 @@ const Reservations = () => { reservationList(cookies.community_id); }, []) + const saveReservation = () => { + if (reservation.common_area_id) { + } else { + setSubmitted(true); + } + } const actionsReservation = (rowData) => { @@ -144,6 +152,12 @@ const Reservations = () => { setDeleteReservationsDialog(true); }; + const cancelEdit = () => { + setReservation(emptyReservation); + setSaveButtonTitle('Registrar'); + setAreaId(''); + } + const leftToolbarTemplate = () => { return ( @@ -250,6 +264,16 @@ const Reservations = () => { ); }; + const handleAreas = (e) => { + const getAreaId = e.target.value; + setAreaId(getAreaId); + } + + const aList = areas.map((item) => ({ + label: item.name, + value: item._id, + })); + return (
@@ -343,7 +367,53 @@ const Reservations = () => {
+
+
+
Reservar Área para Inquilino
+
+
+ +
+
+ + + + +
+ {submitted + && !areaId + && Área Común es requerida.} +
+
+
+
+
+
+
From ac2f644334417e3b19e0d3afc9a574871378853d Mon Sep 17 00:00:00 2001 From: Mariela Date: Wed, 24 Aug 2022 16:35:20 -0600 Subject: [PATCH 02/11] =?UTF-8?q?a=C3=B1adir=20input=20inquilino?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web-react/src/components/Reservaciones.js | 68 ++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index 70cf6275..fc51f6b4 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -43,6 +43,7 @@ const Reservations = () => { const [areas, setAreas] = useState([]); const [areaId, setAreaId] = useState(); const [tenants, setTenants] = useState([]); + const [tenantId, setTenantId] = useState(); const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar") async function tenantsList(id) { @@ -264,16 +265,34 @@ const Reservations = () => { ); }; + const onInputChange = (e, name) => { + const val = (e.target && e.target.value) || ''; + let _reservation = { ...reservation }; + _reservation[`${name}`] = val; + + setReservation(_reservation); + }; + const handleAreas = (e) => { const getAreaId = e.target.value; setAreaId(getAreaId); } + const handleTenants = (e) => { + const getTenantId = e.target.value; + setAreaId(getTenantId); + } + const aList = areas.map((item) => ({ label: item.name, value: item._id, })); + const tList = tenants.map((item) => ({ + label: item.name, + value: item._id, + })); + return (
@@ -371,8 +390,53 @@ const Reservations = () => {
Reservar Área para Inquilino
- -
+
+ +
+
+ + + + onInputChange(e, 'name')} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && reservation.start_time === '', + })} + /> +
+ {submitted && reservation.start_time === '' && ( + Nombre es requirido. + )} +
+
+
+ +
+
+ + + + +
+ {submitted + && !tenantId + && Inquilino es requerido.} +
+
+
From 0a7cc3c1db3ce932edfcf19b990a92e1766c2a26 Mon Sep 17 00:00:00 2001 From: Mariela Date: Thu, 25 Aug 2022 00:03:19 -0600 Subject: [PATCH 03/11] funciones reservaciones --- .../web-react/src/components/Reservaciones.js | 162 ++++++++++++------ 1 file changed, 114 insertions(+), 48 deletions(-) diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index fc51f6b4..90792960 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -41,6 +41,7 @@ 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(); @@ -269,13 +270,15 @@ const Reservations = () => { const val = (e.target && e.target.value) || ''; let _reservation = { ...reservation }; _reservation[`${name}`] = val; - + setReservation(_reservation); - }; + }; const handleAreas = (e) => { const getAreaId = e.target.value; setAreaId(getAreaId); + let area = areas.find(item => item._id == getAreaId); + setArea(area) } const handleTenants = (e) => { @@ -293,6 +296,35 @@ const Reservations = () => { value: item._id, })); + function convertToISO(timeString) { + const [hour12, ampm] = timeString.split(/(?=[ap]m$)/i) + const hour = hour12 % 12 + (ampm.toLowerCase() === 'pm' ? 12 : 0) + const date = new Date() + // Set time, adjusted for time zone + date.setHours(hour, -date.getTimezoneOffset(), 0, 0) + return date.toISOString() + } + + function validateTime(timeStart, timeFinish) { + if ((timeFinish - timeStart) == 1) { + return ( + <> + La hora de inicio debe ser la hora . + + ) + } + } + + function convertToTime(timeString) { + const [hour, minute] = timeString.split(':'); + const date = new Date() + date.setHours(hour); + date.setMinutes(minute); + console.log(date.toTimeString()); + return date.toString() + } + + return (
@@ -390,52 +422,6 @@ const Reservations = () => {
Reservar Área para Inquilino
-
- -
-
- - - - onInputChange(e, 'name')} - required - autoFocus - className={classNames({ - 'p-invalid': submitted && reservation.start_time === '', - })} - /> -
- {submitted && reservation.start_time === '' && ( - Nombre es requirido. - )} -
-
-
- -
-
- - - - -
- {submitted - && !tenantId - && Inquilino es requerido.} -
-
@@ -459,6 +445,86 @@ const Reservations = () => { && Área Común es requerida.}
+ {area && + <> +
+ +
+
+ + + + onInputChange(e, 'start_time')} + required + autoFocus + min={area.hourMin} + max={area.hourMax} + type="time" + lang='es' + value={reservation.start_time} + className={classNames({ + 'p-invalid': submitted && reservation.start_time === '', + })} + /> +
+ {submitted && reservation.start_time === '' && ( + Nombre es requirido. + )} +
+
+ +
+ +
+
+ + + + onInputChange(e, 'finish_time')} + required + autoFocus + type="time" + className={classNames({ + 'p-invalid': submitted && reservation.finish_time === '', + })} + /> +
+ {submitted && reservation.finish_time === '' && ( + Nombre es requirido. + )} +
+
+ + } +
+ +
+
+ + + + +
+ {submitted + && !tenantId + && Inquilino es requerido.} +
+
+
Date: Thu, 25 Aug 2022 00:06:38 -0600 Subject: [PATCH 04/11] nuevos items --- api-gateway/src/app.controller.ts | 8 ++++---- api-gateway/src/app.service.ts | 4 ++-- servicio-reservaciones/src/schemas/reservation.schema.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 76e6d442..39e794ae 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -505,8 +505,8 @@ 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, @@ -515,8 +515,8 @@ export class AppController { @Body('communty_id') communty_id: string, ) { return this.appService.createReservation( - start_time, - finish_time, + date, + time, status, date_entry, user_id, diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 50beb9f6..2a843756 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -613,12 +613,12 @@ 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) { 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 }; diff --git a/servicio-reservaciones/src/schemas/reservation.schema.ts b/servicio-reservaciones/src/schemas/reservation.schema.ts index c51bf2d9..c5acc3c4 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: string; @Prop() - finish_time: string; + time: string; @Prop() status: string; From 2bce41dbc041b7c9251c46b8b124ca8fa488fb5f Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 26 Aug 2022 00:02:17 -0600 Subject: [PATCH 05/11] change manejo de fechas --- .../web-react/src/components/Reservaciones.js | 79 +++++++++++-------- 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index 90792960..c2868498 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: '', @@ -71,8 +71,12 @@ 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) }); } @@ -209,7 +213,7 @@ const Reservations = () => {

{' '} - Hora de Apertura + Fecha de Reserva

); @@ -219,7 +223,7 @@ const Reservations = () => {

{' '} {' '} - Hora de Cierre + Hora de Reserva

); @@ -283,7 +287,7 @@ const Reservations = () => { const handleTenants = (e) => { const getTenantId = e.target.value; - setAreaId(getTenantId); + setTenantId(getTenantId); } const aList = areas.map((item) => ({ @@ -305,14 +309,19 @@ const Reservations = () => { return date.toISOString() } - function validateTime(timeStart, timeFinish) { - if ((timeFinish - timeStart) == 1) { - return ( - <> - La hora de inicio debe ser la hora . - - ) + function validationTime() { + let value = true; + const [hourR, minuteR] = reservation.time.split(':'); + if (hourR != "") { + const [hourMin, minuteMin] = area.hourMin.split(':'); + const [hourMax, minuteMax] = area.hourMax.split(':'); + if ((parseInt(hourR) >= parseInt(hourMin)) && (parseInt(hourR) <= parseInt(hourMax))) { + value = false; + } + } else { + value = false; } + return value; } function convertToTime(timeString) { @@ -448,61 +457,67 @@ const Reservations = () => { {area && <>
- +
onInputChange(e, 'start_time')} + id="date" + onChange={(e) => onInputChange(e, 'date')} required autoFocus - min={area.hourMin} - max={area.hourMax} - type="time" + min={Date()} + type="date" lang='es' - value={reservation.start_time} + value={reservation.date} className={classNames({ - 'p-invalid': submitted && reservation.start_time === '', + 'p-invalid': submitted && reservation.date === '', })} /> +
- {submitted && reservation.start_time === '' && ( - Nombre es requirido. + {submitted && reservation.date === '' && ( + Fecha es requirida. )}
- +
onInputChange(e, 'finish_time')} + id="time" + value={reservation.time} + onChange={(e) => onInputChange(e, 'time')} required autoFocus type="time" + step='3600' className={classNames({ - 'p-invalid': submitted && reservation.finish_time === '', + 'p-invalid': submitted && (reservation.time === '' || validationTime()), })} />
- {submitted && reservation.finish_time === '' && ( - Nombre es requirido. + {submitted && reservation.time === '' && ( + Hora es requirido. )} + {submitted && validationTime() && ( + La hora de inicio debe set mayor de {area.hourMin} y menor de {area.hourMax} . + )} + +
}
- +
@@ -510,7 +525,7 @@ const Reservations = () => { Date: Fri, 26 Aug 2022 00:30:47 -0600 Subject: [PATCH 06/11] =?UTF-8?q?agregar=20dialogo=20para=20agregar=20y=20?= =?UTF-8?q?validaciones=20b=C3=A1sicas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web-react/src/components/Reservaciones.js | 294 +++++++++++------- 1 file changed, 176 insertions(+), 118 deletions(-) diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index c2868498..51c2682f 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -46,6 +46,9 @@ const Reservations = () => { const [tenants, setTenants] = useState([]); const [tenantId, setTenantId] = useState(); const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar") + const [reservationDialog, setReservationDialog] = useState(false); + + async function tenantsList(id) { await fetch(`http://localhost:4000/user/findTenants/${id}`, @@ -71,12 +74,12 @@ 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) }); } @@ -124,8 +127,20 @@ const Reservations = () => { }, []) const saveReservation = () => { - if (reservation.common_area_id) { + let _reservations = [...reservations]; + let _reservation = { ...reservation }; + + if ( _reservation.date && _reservation.time && tenantId && areaId && !validationTime()) { + _reservations.push(_reservation); + setReservations(_reservations) + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Administrador del Sistema Actualizado', + life: 3000, + }); + setReservationDialog(false) } else { setSubmitted(true); } @@ -162,12 +177,34 @@ const Reservations = () => { 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 (
+
+
); }; @@ -192,6 +230,19 @@ const Reservations = () => { ); }; + + const reservationDialogFooter = ( + <> +
-
-
-
Reservar Área para Inquilino
-
-
- -
-
- - - - -
- {submitted - && !areaId - && Área Común es requerida.} -
-
- {area && - <> -
- + + {reservation && ( +
+
+
- onInputChange(e, 'date')} - required - autoFocus - min={Date()} - type="date" - lang='es' - value={reservation.date} - className={classNames({ - 'p-invalid': submitted && reservation.date === '', - })} + -
- {submitted && reservation.date === '' && ( - Fecha es requirida. - )} + {submitted + && !areaId + && Área Común es requerida.}
+ {area && + <> +
+ +
+
+ + + + onInputChange(e, 'date')} + required + autoFocus + min={new Date().toJSON().split('T')[0]} + type="date" + lang='es' + value={reservation.date} + className={classNames({ + 'p-invalid': submitted && reservation.date === '', + })} + /> -
- +
+ {submitted && reservation.date === '' && ( + Fecha es requirida. + )} +
+
+ +
+ +
+
+ + + + onInputChange(e, 'time')} + required + autoFocus + type="time" + step='3600' + className={classNames({ + 'p-invalid': submitted && (reservation.time === '' || validationTime()), + })} + /> +
+ {submitted && reservation.time === '' && ( + Hora es requirido. + )} + {submitted && validationTime() && ( + La hora de inicio debe set mayor de {area.hourMin} y menor de {area.hourMax} . + )} + + +
+
+ + } +
+
- onInputChange(e, 'time')} - required - autoFocus - type="time" - step='3600' - className={classNames({ - 'p-invalid': submitted && (reservation.time === '' || validationTime()), - })} +
- {submitted && reservation.time === '' && ( - Hora es requirido. - )} - {submitted && validationTime() && ( - La hora de inicio debe set mayor de {area.hourMin} y menor de {area.hourMax} . - )} - - + {submitted + && !tenantId + && Inquilino es requerido.}
- - } -
- -
-
- - - - -
- {submitted - && !tenantId - && Inquilino es requerido.} -
-
-
-
-
+
+
+
+ )} +
+
+
From 47efe0bbdff0cd3898749569df1d701265f2261c Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 26 Aug 2022 11:07:35 -0600 Subject: [PATCH 07/11] registro de reservacion --- api-gateway/src/app.controller.ts | 4 +- api-gateway/src/app.service.ts | 4 +- .../src/schemas/reservation.schema.ts | 2 +- .../components/AdministradoresComunidad.js | 1 - .../web-react/src/components/Reservaciones.js | 80 ++++++++++++++----- 5 files changed, 65 insertions(+), 26 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 39e794ae..f6bf3ab0 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -512,7 +512,7 @@ export class AppController { @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( date, @@ -522,7 +522,7 @@ export class AppController { 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 2a843756..380e23d1 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -615,12 +615,12 @@ export class AppService { //POST parameter from API 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 = { 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/schemas/reservation.schema.ts b/servicio-reservaciones/src/schemas/reservation.schema.ts index c5acc3c4..857868cf 100644 --- a/servicio-reservaciones/src/schemas/reservation.schema.ts +++ b/servicio-reservaciones/src/schemas/reservation.schema.ts @@ -6,7 +6,7 @@ export type ReservationDocument = Reservation & Document; @Schema({ collection: 'reservations' }) export class Reservation { @Prop() - date: string; + date: Date; @Prop() time: string; 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 51c2682f..aba9a3fe 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -79,7 +79,6 @@ const Reservations = () => { data = data.filter( (val) => val.bookable == 1, ) - setAreas(data) }); } @@ -94,6 +93,9 @@ 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') { @@ -127,20 +129,52 @@ const Reservations = () => { }, []) const saveReservation = () => { - let _reservations = [...reservations]; - let _reservation = { ...reservation }; - if ( _reservation.date && _reservation.time && tenantId && areaId && !validationTime()) { - _reservations.push(_reservation); - setReservations(_reservations) - toast.current.show({ - severity: 'success', - summary: 'Éxito', - detail: 'Administrador del Sistema Actualizado', - life: 3000, - }); + let _reservations = [...reservations]; + let _reservation = { ...reservation }; - setReservationDialog(false) + if (_reservation.date && _reservation.time && tenantId && areaId && !validationTime()) { + _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; + + if (_reservation.status == '1') { + _reservation.status_text = 'Activo'; + } else if (_reservation.status == '0') { + _reservation.status_text = 'Inactivo'; + } + console.log(_reservation) + 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) + }) + + + + } else { setSubmitted(true); } @@ -259,7 +293,7 @@ const Reservations = () => {
); - const headerStartTime = ( + const headerDate = ( <>

{' '} @@ -269,7 +303,7 @@ const Reservations = () => { ); - const headerEndTime = ( + const headerTime = ( <>

{' '} @@ -384,6 +418,12 @@ const Reservations = () => { return date.toString() } + function formatDateString(dateString) { + const [date, time] = timeString.split('T'); + return date; + } + + return (

@@ -419,9 +459,9 @@ const Reservations = () => { headerStyle={{ width: '3rem' }} > { }} > {
- +
From ac80892afb65e957b8abcbf1638cb817f6ede5cf Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 26 Aug 2022 13:42:46 -0600 Subject: [PATCH 08/11] validaciones de fechas y horas repetidas --- .../web-react/src/components/Reservaciones.js | 96 ++++++++++++------- 1 file changed, 62 insertions(+), 34 deletions(-) diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index aba9a3fe..8e5dfb79 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -94,7 +94,9 @@ const Reservations = () => { ) data.map((item) => { - item.date = formatDateString(item.date) + if (item.date) { + item.date = formatDateString(item.date) + } if (item.status == '1') { item.status_text = 'Activo'; @@ -129,11 +131,11 @@ const Reservations = () => { }, []) const saveReservation = () => { - + let _reservations = [...reservations]; let _reservation = { ...reservation }; - if (_reservation.date && _reservation.time && tenantId && areaId && !validationTime()) { + if (!validationIsReservation() && _reservation.date && _reservation.time && tenantId && areaId && !validationTime()) { _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; @@ -147,34 +149,35 @@ const Reservations = () => { _reservation.status_text = 'Inactivo'; } console.log(_reservation) - 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) - }) + + /* 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) + /*})*/ + - } else { setSubmitted(true); } @@ -363,6 +366,16 @@ const Reservations = () => { setReservation(_reservation); }; + const onTimeChange = (e) => { + e.target.value.split(':')[1] = "00"; + const val = (e.target && e.target.value.split(':')[0]) || ''; + let _reservation = { ...reservation }; + document.getElementById('time').value = val + ":00"; + _reservation['time'] = val + ":00"; + setReservation(_reservation); + + }; + const handleAreas = (e) => { const getAreaId = e.target.value; setAreaId(getAreaId); @@ -419,11 +432,21 @@ const Reservations = () => { } function formatDateString(dateString) { - const [date, time] = timeString.split('T'); + const [date, time] = dateString.split('T'); return date; } + function validationIsReservation() { + let booked = reservations.filter(item => item.common_area_id == areaId && item.date == reservation.date && item.time == reservation.time); + if (booked.length > 0) { + return true; + + } else { + return false; + } + } + return (
@@ -567,7 +590,8 @@ const Reservations = () => { lang='es' value={reservation.date} className={classNames({ - 'p-invalid': submitted && reservation.date === '', + 'p-invalid': submitted && (reservation.date === '' + || validationIsReservation()), })} /> @@ -575,6 +599,7 @@ const Reservations = () => { {submitted && reservation.date === '' && ( Fecha es requirida. )} +
@@ -588,13 +613,14 @@ const Reservations = () => { onInputChange(e, 'time')} + onChange={(e) => onTimeChange(e)} required autoFocus type="time" step='3600' className={classNames({ - 'p-invalid': submitted && (reservation.time === '' || validationTime()), + 'p-invalid': submitted && (reservation.time === '' + || validationTime() || validationIsReservation()), })} />
@@ -602,9 +628,11 @@ const Reservations = () => { Hora es requirido. )} {submitted && validationTime() && ( - La hora de inicio debe set mayor de {area.hourMin} y menor de {area.hourMax} . + La hora de inicio debe ser mayor de {area.hourMin} y menor de {area.hourMax} . + )} + {submitted && validationIsReservation() && ( + Ya hay una reservación en la fecha y hora ingresada. )} -
From 5a2f0846d8764be3b2a0327c6411adcca69f558d Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 26 Aug 2022 13:44:00 -0600 Subject: [PATCH 09/11] descomentar fetch de registro --- .../web-react/src/components/Reservaciones.js | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index 8e5dfb79..5c284385 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -150,30 +150,30 @@ const Reservations = () => { } console.log(_reservation) - /* 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, - }); + 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) - /*})*/ + setReservationDialog(false) + }) @@ -440,13 +440,13 @@ const Reservations = () => { let booked = reservations.filter(item => item.common_area_id == areaId && item.date == reservation.date && item.time == reservation.time); if (booked.length > 0) { return true; - + } else { return false; } } - + return (
@@ -590,8 +590,8 @@ const Reservations = () => { lang='es' value={reservation.date} className={classNames({ - 'p-invalid': submitted && (reservation.date === '' - || validationIsReservation()), + 'p-invalid': submitted && (reservation.date === '' + || validationIsReservation()), })} /> @@ -599,7 +599,7 @@ const Reservations = () => { {submitted && reservation.date === '' && ( Fecha es requirida. )} - +
@@ -619,8 +619,8 @@ const Reservations = () => { type="time" step='3600' className={classNames({ - 'p-invalid': submitted && (reservation.time === '' - || validationTime() || validationIsReservation()), + 'p-invalid': submitted && (reservation.time === '' + || validationTime() || validationIsReservation()), })} />
From 1b99458b7dd26bc789c084182fded662c6936e0b Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 26 Aug 2022 17:13:18 -0600 Subject: [PATCH 10/11] formateo de fechas y eliminar impresiones innecesarias --- .../src/reservations/reservations.service.ts | 2 -- web-ui/web-react/public/index.html | 2 +- web-ui/web-react/src/AppFooter.js | 4 ++-- .../web-react/src/components/Reservaciones.js | 19 +++---------------- 4 files changed, 6 insertions(+), 21 deletions(-) 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/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/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index 5c284385..e002be63 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -49,7 +49,6 @@ const Reservations = () => { const [reservationDialog, setReservationDialog] = useState(false); - async function tenantsList(id) { await fetch(`http://localhost:4000/user/findTenants/${id}`, { method: 'GET' }) @@ -148,8 +147,6 @@ const Reservations = () => { } else if (_reservation.status == '0') { _reservation.status_text = 'Inactivo'; } - console.log(_reservation) - fetch('http://localhost:4000/reservation/createReservation/', { cache: 'no-cache', method: 'POST', @@ -174,19 +171,12 @@ const Reservations = () => { setReservationDialog(false) }) - - - - } else { setSubmitted(true); } } - - + const actionsReservation = (rowData) => { - - return (