Added more fixes.
This commit is contained in:
parent
23050f5a22
commit
bf319a8acf
@ -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.");
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user