Merge pull request #207 from DeimosPr4/US-31-Eliminarreservadeinquilino
eliminar reserva de inquilino
This commit is contained in:
commit
8f7c15381e
|
@ -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
|
||||
|
||||
|
@ -542,6 +511,12 @@ export class AppController {
|
|||
}
|
||||
|
||||
|
||||
@Delete('reservation/deleteReservation/:id')
|
||||
deleteReservation(@Param('id') id: string) {
|
||||
return this.appService.deleteReservation(id);
|
||||
}
|
||||
|
||||
|
||||
// #==== API Post
|
||||
|
||||
@Post('post/createPost')
|
||||
|
|
|
@ -571,44 +571,6 @@ export class AppService {
|
|||
.send<string>(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<string>(pattern, payload)
|
||||
.pipe(map((message: string) => ({ message })));
|
||||
}
|
||||
|
||||
allPayments() {
|
||||
const pattern = { cmd: 'findAllPayments' };
|
||||
const payload = {};
|
||||
return this.clientPaymentApp
|
||||
.send<string>(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<string>(pattern, payload)
|
||||
.pipe(map((message: string) => ({ message })));
|
||||
}
|
||||
|
||||
// ====================== RESERVATIONS ===============================
|
||||
|
||||
|
@ -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<string>(pattern, payload)
|
||||
.pipe(map((message: string) => ({ message })));
|
||||
}
|
||||
|
||||
// ====================== POSTS ===============================
|
||||
|
||||
//POST parameter from API
|
||||
|
|
|
@ -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)
|
||||
|
||||
if (item.status == '1') {
|
||||
item.status_text = 'Activo';
|
||||
} else if (item.status == '0') {
|
||||
|
@ -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',
|
||||
|
@ -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 (
|
||||
<React.Fragment>
|
||||
|
@ -269,6 +351,40 @@ const Reservations = () => {
|
|||
</>
|
||||
);
|
||||
|
||||
const deleteReservationDialogFooter = (
|
||||
<>
|
||||
<Button
|
||||
label="No"
|
||||
icon="pi pi-times"
|
||||
className="p-button-text"
|
||||
onClick={hideDeleteReservationDialog}
|
||||
/>
|
||||
<Button
|
||||
label="Yes"
|
||||
icon="pi pi-check"
|
||||
className="p-button-text"
|
||||
onClick={deleteReservation}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
const deleteReservationsDialogFooter = (
|
||||
<>
|
||||
<Button
|
||||
label="No"
|
||||
icon="pi pi-times"
|
||||
className="p-button-text"
|
||||
onClick={hideDeleteReservationsDialog}
|
||||
/>
|
||||
<Button
|
||||
label="Yes"
|
||||
icon="pi pi-check"
|
||||
className="p-button-text"
|
||||
onClick={deleteSelectedReservations}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
const header = (
|
||||
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
|
||||
<h5 className="m-0">
|
||||
|
@ -408,9 +524,9 @@ const Reservations = () => {
|
|||
}
|
||||
|
||||
function validationIsReservation() {
|
||||
if(reservation.date && reservation.time && areaId){
|
||||
if (reservation.date && reservation.time && areaId) {
|
||||
let date1 = new Date(reservation.date).toJSON().split('T')[0];
|
||||
let date2 = date1.split('-')[2] + '-' + date1.split('-')[1] + '-' +date1.split('-')[0];
|
||||
let date2 = date1.split('-')[2] + '-' + date1.split('-')[1] + '-' + date1.split('-')[0];
|
||||
|
||||
let booked = reservations.filter(item => item.common_area_id == areaId
|
||||
&& item.date == date2
|
||||
|
@ -426,9 +542,9 @@ const Reservations = () => {
|
|||
}
|
||||
|
||||
function validationIsSameUser() {
|
||||
if(reservation.date && tenantId && areaId){
|
||||
if (reservation.date && tenantId && areaId) {
|
||||
let date1 = new Date(reservation.date).toJSON().split('T')[0];
|
||||
let date2 = date1.split('-')[2] + '-' + date1.split('-')[1] + '-' +date1.split('-')[0];
|
||||
let date2 = date1.split('-')[2] + '-' + date1.split('-')[1] + '-' + date1.split('-')[0];
|
||||
|
||||
let booked = reservations.filter(item => item.common_area_id == areaId
|
||||
&& item.date == date2
|
||||
|
@ -694,6 +810,47 @@ const Reservations = () => {
|
|||
</div>
|
||||
)}
|
||||
</Dialog>
|
||||
<Dialog
|
||||
visible={deleteReservationDialog}
|
||||
style={{ width: '450px' }}
|
||||
header="Confirmar"
|
||||
modal
|
||||
footer={deleteReservationDialogFooter}
|
||||
onHide={hideDeleteReservationDialog}
|
||||
>
|
||||
<div className="flex align-items-center justify-content-center">
|
||||
<i
|
||||
className="pi pi-exclamation-triangle mr-3"
|
||||
style={{ fontSize: '2rem' }}
|
||||
/>
|
||||
{reservation && (
|
||||
<span>
|
||||
¿Estás seguro que desea eliminar la reservación de <b>{reservation.user_name}</b>?
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</Dialog>
|
||||
<Dialog
|
||||
visible={deleteReservationsDialog}
|
||||
style={{ width: '450px' }}
|
||||
header="Confirmar"
|
||||
modal
|
||||
footer={deleteReservationsDialogFooter}
|
||||
onHide={hideDeleteReservationsDialog}
|
||||
>
|
||||
<div className="flex align-items-center justify-content-center">
|
||||
<i
|
||||
className="pi pi-exclamation-triangle mr-3"
|
||||
style={{ fontSize: '2rem' }}
|
||||
/>
|
||||
{selectedReservations && (
|
||||
<span>
|
||||
¿Está seguro eliminar las reservaciones
|
||||
seleccionadas?
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</Dialog>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue