Added reservation and username lookup
All checks were successful
Build BAB Application Deployment Artifact / build (push) Successful in 2m13s

This commit is contained in:
2024-05-13 10:49:03 -04:00
parent 4a273ccb2f
commit 78211a33ae
17 changed files with 180 additions and 72 deletions

View File

@@ -108,19 +108,32 @@ export const useScheduleStore = defineStore('schedule', () => {
});
};
async function fetchReservations() {
try {
const response = await databases.listDocuments(
AppwriteIds.databaseId,
AppwriteIds.collection.reservation
);
reservations.value = response.documents as Reservation[];
} catch (error) {
console.error('Failed to fetch timeblocks', error);
}
}
const getBoatReservations = (
searchDate: Timestamp,
boat?: string
): Reservation[] => {
return reservations.value.filter((x) => {
const result = reservations.value.filter((x) => {
return (
((parseDate(x.start)?.date == searchDate.date ||
parseDate(x.end)?.date == searchDate.date) && // Part of reservation falls on day
((parsed(x.start)?.date == searchDate.date ||
parsed(x.end)?.date == searchDate.date) && // Part of reservation falls on day
x.resource != undefined && // A boat is defined
!boat) ||
x.resource.$id == boat // A specific boat has been passed, and matches
x.resource == boat // A specific boat has been passed, and matches
);
});
return result;
};
async function fetchIntervals() {
@@ -170,21 +183,21 @@ export const useScheduleStore = defineStore('schedule', () => {
// };
const getConflictingReservations = (
resource: Boat,
resource: string,
start: Date,
end: Date
): Reservation[] => {
const overlapped = reservations.value.filter(
(entry: Reservation) =>
entry.resource.$id == resource.$id &&
entry.start < end &&
entry.end > start
entry.resource == resource &&
new Date(entry.start) < end &&
new Date(entry.end) > start
);
return overlapped;
};
const isResourceTimeOverlapped = (
resource: Boat,
resource: string,
start: Date,
end: Date
): boolean => {
@@ -192,7 +205,11 @@ export const useScheduleStore = defineStore('schedule', () => {
};
const isReservationOverlapped = (res: Reservation): boolean => {
return isResourceTimeOverlapped(res.resource, res.start, res.end);
return isResourceTimeOverlapped(
res.resource,
new Date(res.start),
new Date(res.end)
);
};
const getNewId = (): string => {
@@ -235,7 +252,6 @@ export const useScheduleStore = defineStore('schedule', () => {
{ ...interval, $id: undefined }
);
timeblocks.value.push(response as Interval);
console.log(interval, response);
} else {
console.error('Update interval called without an ID');
}
@@ -315,19 +331,20 @@ export const useScheduleStore = defineStore('schedule', () => {
timeblockTemplates,
getBoatReservations,
getConflictingReservations,
addOrCreateReservation,
isReservationOverlapped,
isResourceTimeOverlapped,
fetchReservations,
getIntervalsForDate,
getIntervals,
fetchIntervals,
fetchIntervalTemplates,
getNewId,
addOrCreateReservation,
createInterval,
updateInterval,
deleteInterval,
createIntervalTemplate,
deleteIntervalTemplate,
updateIntervalTemplate,
isReservationOverlapped,
isResourceTimeOverlapped,
};
});