Added more fixes.

This commit is contained in:
Tom Butcher 2025-11-16 15:21:38 +00:00
parent 23050f5a22
commit bf319a8acf
2 changed files with 14 additions and 12 deletions

View File

@ -92,21 +92,21 @@ export async function importSmoobuBookings(env) {
.filter((booking) => booking !== null);
// Get the current cache (source of truth)
const cachedBookings =
(await getBookingsCache(env)).filter(
(booking) =>
booking.status !== "cancelled" && booking.status !== "complete"
) || [];
const cachedBookings = (await getBookingsCache(env)) || [];
// Diff Smoobu bookings with cache
const { toAdd, toUpdate, toDelete } = diffBookings(
smoobuBookings,
cachedBookings
);
const filteredToAddBookings = toAdd.filter(
(booking) => booking.status !== "cancelled" && booking.status !== "complete"
);
console.log("Smoobu bookings:", smoobuBookings.length);
console.log(
"Add:",
toAdd.length,
filteredToAddBookings.length,
"Update:",
toUpdate.length,
"Delete:",
@ -115,7 +115,7 @@ export async function importSmoobuBookings(env) {
// Add new bookings to Notion
const added = [];
for (const booking of toAdd) {
for (const booking of filteredToAddBookings) {
const res = await addBookingToNotion(env, booking);
added.push(res);
}
@ -145,7 +145,13 @@ export async function importSmoobuBookings(env) {
});
if (added.length > 0 || updated.length > 0 || toDelete.length > 0) {
await storeBookingsCache(env, newCache);
await storeBookingsCache(
env,
newCache.filter(
(booking) =>
booking.status !== "cancelled" && booking.status !== "complete"
)
);
console.log("Imported bookings from Smoobu.");
} else {
console.log("No changes detected, cache not updated.");

View File

@ -166,10 +166,6 @@ export async function transformSmoobuBooking(
convertBookingDatesToISO(booking, property.timezone).departureISO
);
if (status == "complete") {
return null;
}
return {
smoobuId: booking.id,
reference: booking["reference-id"] || null,