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
);
if (!cached?.notionId) continue;
console.log("Updating property in Notion:", property);
const res = await updateNotionProperty(env, property, cached.notionId);
updated.push(res);
}

View File

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