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

View File

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