Fix bug
Some checks failed
Build BAB Application Deployment Artifact / build (push) Failing after 2m6s

This commit is contained in:
2024-05-25 08:34:25 -04:00
parent 9f398e5509
commit 59d2729719
4 changed files with 121 additions and 21 deletions

View File

@@ -39,8 +39,9 @@ export const useBoatStore = defineStore('boat', () => {
}
}
const getBoatById = (id: string): Boat | null => {
return boats.value.find((b) => b.$id === id) || null;
const getBoatById = (id: string | null | undefined): Boat | null => {
if (!id) return null;
return boats.value?.find((b) => b.$id === id) || null;
};
return { boats, fetchBoats, getBoatById };

View File

@@ -60,6 +60,32 @@ export const useReservationStore = defineStore('reservation', () => {
}
};
const deleteReservation = async (
reservation: string | Reservation | null | undefined
) => {
if (!reservation) return false;
let id;
if (typeof reservation === 'string') {
id = reservation;
} else if ('$id' in reservation && typeof reservation.$id === 'string') {
id = reservation.$id;
} else {
return false;
}
try {
await databases.deleteDocument(
AppwriteIds.databaseId,
AppwriteIds.collection.interval,
id
);
reservations.value.delete(id);
console.info(`Deleted reservation: ${id}`);
} catch (e) {
console.error('Error deleting reservation: ' + e);
}
};
// Set the loading state for dates
const setDateLoaded = (start: Date, end: Date, state: LoadingTypes) => {
if (start > end) return [];
@@ -160,6 +186,7 @@ export const useReservationStore = defineStore('reservation', () => {
return {
getReservationsByDate,
createReservation,
deleteReservation,
fetchReservationsForDateRange,
isReservationOverlapped,
isResourceTimeOverlapped,