diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index f6bf3ab0..5066563a 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -468,38 +468,7 @@ export class AppController { } - // #==== API Payment - - @Post('payment/createPayment') - createPayment( - @Body('date_payment') date_payment: Date, - @Body('mount') mount: number, - @Body('description') description: string, - @Body('period') period: string, - @Body('status') status: string, - @Body('user_id') user_id: string, - @Body('communty_id') communty_id: string, - ) { - return this.appService.createPayment( - date_payment, - mount, - description, - period, - status, - user_id, - communty_id, - ); - } - - @Get('payment/allPayments') - allPayments() { - return this.appService.allPayments(); - } - - @Get('payment/find/:dni') - findPayment(@Param('dni') paramPaymentDNI: string) { - return this.appService.findPayment(paramPaymentDNI); - } + // #==== API Reservation @@ -541,6 +510,12 @@ export class AppController { return this.appService.findReservations(community_id); } + + @Delete('reservation/deleteReservation/:id') + deleteReservation(@Param('id') id: string) { + return this.appService.deleteReservation(id); + } + // #==== API Post diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 380e23d1..970b061e 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -571,45 +571,7 @@ export class AppService { .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } - // ====================== PAYMENTS =============================== - - //POST parameter from API - createPayment( - date_payment: Date, - mount: number, - description: string, - period: string, - status: string, - user_id: string, - communty_id: string, - ) { - const pattern = { cmd: 'createPayment' }; - const payload = { - date_payment: date_payment, mount: mount, description: description, - period: period, status: status, user_id: user_id, communty_id: communty_id - }; - return this.clientPaymentApp - .send(pattern, payload) - .pipe(map((message: string) => ({ message }))); - } - - allPayments() { - const pattern = { cmd: 'findAllPayments' }; - const payload = {}; - return this.clientPaymentApp - .send(pattern, payload) - .pipe(map((message: string) => ({ message }))); - } - - //GET parameter from API - findPayment(paramPaymentId: string) { - const pattern = { cmd: 'findOnePayment' }; - const payload = { id: paramPaymentId }; - return this.clientPaymentApp - .send(pattern, payload) - .pipe(map((message: string) => ({ message }))); - } - + // ====================== RESERVATIONS =============================== //POST parameter from API @@ -652,6 +614,15 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + //DELETE parameter from API + deleteReservation(paramReservationId: string) { + const pattern = { cmd: 'removeReservation' }; + const payload = { id: paramReservationId }; + return this.clientReservationApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + // ====================== POSTS =============================== //POST parameter from API diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index dcf2228e..84764a23 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -48,7 +48,6 @@ const Reservations = () => { const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar") const [reservationDialog, setReservationDialog] = useState(false); const [dateMax, setDateMax] = useState(); - const [tenants, setTenants] = useState([]); async function tenantsList(id) { @@ -94,7 +93,9 @@ const Reservations = () => { (val) => val.status != -1, ) data.map((item) => { - item.date = formatDateString(item.date) + + item.date = formatDateString(item.date) + if (item.status == '1') { item.status_text = 'Activo'; } else if (item.status == '0') { @@ -133,7 +134,7 @@ const Reservations = () => { let _reservation = { ...reservation }; if (_reservation.date && _reservation.time && tenantId && areaId - && !validationTime() + && !validationTime() && !validationIsSameUser() && !validationIsReservation()) { _reservation.common_area_name = areas.find(item => item._id == areaId).name; let tenant = tenants.find(item => item._id == tenantId); @@ -141,7 +142,7 @@ const Reservations = () => { _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'; @@ -160,8 +161,10 @@ const Reservations = () => { 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); + }).then((response) => { + let _r = response.message; + _r.date = formatDateString(_r.date) + _reservations.push(_r); setReservations(_reservations) toast.current.show({ severity: 'success', @@ -174,7 +177,7 @@ const Reservations = () => { setAreaId('') setTenantId('') }) - + } else { setSubmitted(true); } @@ -221,8 +224,87 @@ const Reservations = () => { setReservation(emptyReservation); setReservationDialog(true); setSubmitted(false); - }; + + + + const hideDeleteReservationDialog = () => { + setDeleteReservationDialog(false); + }; + + const hideDeleteReservationsDialog = () => { + setDeleteReservationsDialog(false); + }; + + + const deleteReservation = () => { + + + fetch('http://localhost:4000/reservation/deleteReservation/' + reservation._id, { + cache: 'no-cache', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + }) + .then(function (response) { + if (response.status != 201 || response.status != 200) + console.log('Ocurrió un error con el servicio: ' + response.status); + else return response.json(); + }) + .then(function (response) { + let _reservation = reservations.filter( + (val) => (val._id !== reservation._id), + ); + + setReservations(_reservation); + setDeleteReservationDialog(false); + setReservation(emptyReservation); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Reservación Eliminada', + life: 3000, + }); + }) + .catch((err) => { + console.log('Ocurrió un error con el fetch', err); + toast.current.show({ + severity: 'danger', + summary: 'Error', + detail: 'Reservación no se pudo Eliminar', + life: 3000, + }); + }); + }; + + const deleteSelectedReservations = () => { + let _reservations = reservations.filter( + (val) => (!selectedReservations.includes(val)), + ); + selectedReservations.map((item) => { + fetch('http://localhost:4000/reservation/deleteReservation/' + item._id, { + cache: 'no-cache', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + }); + }); + _reservations = _reservations.filter( + (val) => val.status != -1, + ) + setReservations(_reservations); + setDeleteReservationsDialog(false); + setSelectedReservations(null); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Reservaciones Eliminadas', + life: 3000, + }); + }; + const leftToolbarTemplate = () => { return ( @@ -268,7 +350,41 @@ const Reservations = () => { ); + + const deleteReservationDialogFooter = ( + <> +