Fix bug
Some checks failed
Build BAB Application Deployment Artifact / build (push) Failing after 2m6s
Some checks failed
Build BAB Application Deployment Artifact / build (push) Failing after 2m6s
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user