Fixed code duplication
All checks were successful
thehideout/TheHideout-API/pipeline/head This commit looks good

This commit is contained in:
Tom Butcher 2026-01-03 00:52:11 +00:00
parent ccfa654016
commit 0cafe140a0
2 changed files with 22 additions and 18 deletions

View File

@ -63,6 +63,7 @@ export async function importSmoobuProperties(env) {
(g) => g.smoobuId === property.smoobuId (g) => g.smoobuId === property.smoobuId
); );
if (!cached?.notionId) continue; if (!cached?.notionId) continue;
console.log("Updating property in Notion:", property);
const res = await updateNotionProperty(env, property, cached.notionId); const res = await updateNotionProperty(env, property, cached.notionId);
updated.push(res); updated.push(res);
} }

View File

@ -100,7 +100,10 @@ export function transformSmoobuProperty(env, property) {
.split(",") .split(",")
.map((s) => s.trim()) .map((s) => s.trim())
.join("\n"); .join("\n");
console.log(
"Transformed property:",
property.amenities.map((feature) => feature.replace(/,/g, ";")) || []
);
return { return {
smoobuId: property.id, smoobuId: property.id,
name: property.name || "Unknown Property", name: property.name || "Unknown Property",
@ -311,24 +314,24 @@ export async function addPropertyToNotion(env, property) {
export async function updateNotionProperty(env, property, notionId) { export async function updateNotionProperty(env, property, notionId) {
console.log("Updating property in Notion:", property.smoobuId); console.log("Updating property in Notion:", property.smoobuId);
const details = await fetchSmoobuPropertyDetails(env, property.smoobuId); // Use the transformed property data directly instead of fetching from Smoobu again
const notionProps = { const notionProps = {
...(property.syncName ? { Name: details.name } : {}), ...(property.syncName ? { Name: property.name } : {}),
"Max Occupancy": details.rooms.maxOccupancy, "Max Occupancy": property.maxOccupancy,
Bedrooms: details.rooms.bedrooms, Bedrooms: property.bedrooms,
Bathrooms: details.rooms.bathrooms, Bathrooms: property.bathrooms,
"Double Beds": details.rooms.doubleBeds, "Double Beds": property.doubleBeds,
"Single Beds": details.rooms.singleBeds, "Single Beds": property.singleBeds,
"Sofa Beds": details.rooms.sofaBeds, "Sofa Beds": property.sofaBeds,
Sofas: details.rooms.couches, Sofas: property.sofas,
"Child Beds": details.rooms.childBeds, "Child Beds": property.childBeds,
"Queen Size Beds": details.rooms.queenSizeBeds, "Queen Size Beds": property.queenSizeBeds,
"King Size Beds": details.rooms.kingSizeBeds, "King Size Beds": property.kingSizeBeds,
Timezone: { select: { name: details.timeZone || "UTC" } }, Timezone: { select: { name: property.timezone || "UTC" } },
Address: `${details.location.street}\n${details.location.city}\n${details.location.zip}`, Address: property.address,
Features: details.amenities, Features: property.features,
"Min Price": parseFloat(details.price.minimal), "Min Price": property.minPrice,
"Max Price": parseFloat(details.price.maximal), "Max Price": property.maxPrice,
}; };
Object.keys(notionProps).forEach( Object.keys(notionProps).forEach(
(k) => notionProps[k] === undefined && delete notionProps[k] (k) => notionProps[k] === undefined && delete notionProps[k]