Merge pull request #207 from DeimosPr4/US-31-Eliminarreservadeinquilino

eliminar reserva de inquilino
This commit is contained in:
Eduardo Quiros 2022-08-30 05:25:19 +00:00 committed by GitHub
commit 8f7c15381e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 193 additions and 90 deletions

View File

@ -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 // #==== API Reservation
@ -541,6 +510,12 @@ export class AppController {
return this.appService.findReservations(community_id); return this.appService.findReservations(community_id);
} }
@Delete('reservation/deleteReservation/:id')
deleteReservation(@Param('id') id: string) {
return this.appService.deleteReservation(id);
}
// #==== API Post // #==== API Post

View File

@ -571,45 +571,7 @@ export class AppService {
.send<string>(pattern, payload) .send<string>(pattern, payload)
.pipe(map((message: string) => ({ message }))); .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 =============================== // ====================== RESERVATIONS ===============================
//POST parameter from API //POST parameter from API
@ -652,6 +614,15 @@ export class AppService {
.pipe(map((message: string) => ({ message }))); .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 =============================== // ====================== POSTS ===============================
//POST parameter from API //POST parameter from API

View File

@ -48,7 +48,6 @@ const Reservations = () => {
const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar") const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar")
const [reservationDialog, setReservationDialog] = useState(false); const [reservationDialog, setReservationDialog] = useState(false);
const [dateMax, setDateMax] = useState(); const [dateMax, setDateMax] = useState();
const [tenants, setTenants] = useState([]);
async function tenantsList(id) { async function tenantsList(id) {
@ -94,7 +93,9 @@ const Reservations = () => {
(val) => val.status != -1, (val) => val.status != -1,
) )
data.map((item) => { data.map((item) => {
item.date = formatDateString(item.date)
item.date = formatDateString(item.date)
if (item.status == '1') { if (item.status == '1') {
item.status_text = 'Activo'; item.status_text = 'Activo';
} else if (item.status == '0') { } else if (item.status == '0') {
@ -133,7 +134,7 @@ const Reservations = () => {
let _reservation = { ...reservation }; let _reservation = { ...reservation };
if (_reservation.date && _reservation.time && tenantId && areaId if (_reservation.date && _reservation.time && tenantId && areaId
&& !validationTime() && !validationTime()
&& !validationIsSameUser() && !validationIsReservation()) { && !validationIsSameUser() && !validationIsReservation()) {
_reservation.common_area_name = areas.find(item => item._id == areaId).name; _reservation.common_area_name = areas.find(item => item._id == areaId).name;
let tenant = tenants.find(item => item._id == tenantId); let tenant = tenants.find(item => item._id == tenantId);
@ -141,7 +142,7 @@ const Reservations = () => {
_reservation.user_id = tenantId; _reservation.user_id = tenantId;
_reservation.common_area_id = areaId; _reservation.common_area_id = areaId;
_reservation.community_id = cookies.community_id; _reservation.community_id = cookies.community_id;
_reservation.date = formatDateString(_reservation.date)
if (_reservation.status == '1') { if (_reservation.status == '1') {
_reservation.status_text = 'Activo'; _reservation.status_text = 'Activo';
@ -160,8 +161,10 @@ const Reservations = () => {
if (response.status !== 200 && response.status !== 201) if (response.status !== 200 && response.status !== 201)
console.log(`Hubo un error en el servicio: ${response.status}`) console.log(`Hubo un error en el servicio: ${response.status}`)
else return response.json() else return response.json()
}).then(() => { }).then((response) => {
_reservations.push(_reservation); let _r = response.message;
_r.date = formatDateString(_r.date)
_reservations.push(_r);
setReservations(_reservations) setReservations(_reservations)
toast.current.show({ toast.current.show({
severity: 'success', severity: 'success',
@ -174,7 +177,7 @@ const Reservations = () => {
setAreaId('') setAreaId('')
setTenantId('') setTenantId('')
}) })
} else { } else {
setSubmitted(true); setSubmitted(true);
} }
@ -221,8 +224,87 @@ const Reservations = () => {
setReservation(emptyReservation); setReservation(emptyReservation);
setReservationDialog(true); setReservationDialog(true);
setSubmitted(false); 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 = () => { const leftToolbarTemplate = () => {
return ( return (
<React.Fragment> <React.Fragment>
@ -268,7 +350,41 @@ 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 = ( const header = (
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center"> <div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
<h5 className="m-0"> <h5 className="m-0">
@ -408,17 +524,17 @@ const Reservations = () => {
} }
function validationIsReservation() { 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 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 let booked = reservations.filter(item => item.common_area_id == areaId
&& item.date == date2 && item.date == date2
&& item.time == reservation.time); && item.time == reservation.time);
if (booked.length > 0) { if (booked.length > 0) {
return true; return true;
} else { } else {
return false; return false;
} }
@ -426,16 +542,16 @@ const Reservations = () => {
} }
function validationIsSameUser() { function validationIsSameUser() {
if(reservation.date && tenantId && areaId){ if (reservation.date && tenantId && areaId) {
let date1 = new Date(reservation.date).toJSON().split('T')[0]; 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 let booked = reservations.filter(item => item.common_area_id == areaId
&& item.date == date2 && item.date == date2
&& item.user_id == tenantId); && item.user_id == tenantId);
if (booked.length >= 2) { if (booked.length >= 2) {
return true; return true;
} else { } else {
return false; return false;
} }
@ -694,6 +810,47 @@ const Reservations = () => {
</div> </div>
)} )}
</Dialog> </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> </div>
</div> </div>