From 47efe0bbdff0cd3898749569df1d701265f2261c Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 26 Aug 2022 11:07:35 -0600 Subject: [PATCH] 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' }} > { }} > {
- +