From b40616586603570d50dcdbd47415eb959b413b13 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 3 Jan 2026 00:55:06 +0000 Subject: [PATCH] Implemented Sync Price --- src/utils/properties.js | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/utils/properties.js b/src/utils/properties.js index 41d0be5..b603dd8 100644 --- a/src/utils/properties.js +++ b/src/utils/properties.js @@ -167,20 +167,36 @@ export function diffProperties(newList, oldList) { if (!old) return false; // If syncName is false, exclude name from comparison - const { smoobuId, notionId, name, ...restNew } = p; - const { smoobuId: _, notionId: __, name: oldName, ...restOld } = old; + // If syncPrice is false, exclude prices from comparison + const { smoobuId, notionId, name, minPrice, maxPrice, ...restNew } = p; + const { + smoobuId: _, + notionId: __, + name: oldName, + minPrice: oldMinPrice, + maxPrice: oldMaxPrice, + ...restOld + } = old; // Prepare objects for comparison let newObj, oldObj; - if (old.syncName === false) { - // Don't compare names when syncName is false - newObj = restNew; - oldObj = restOld; - } else { + // Build objects conditionally based on sync flags + newObj = { ...restNew }; + oldObj = { ...restOld }; + + if (old.syncName !== false) { // Include name in comparison when syncName is true or undefined - newObj = { name, ...restNew }; - oldObj = { name: oldName, ...restOld }; + newObj.name = name; + oldObj.name = oldName; + } + + if (old.syncPrice !== false) { + // Include prices in comparison when syncPrice is true or undefined + newObj.minPrice = minPrice; + newObj.maxPrice = maxPrice; + oldObj.minPrice = oldMinPrice; + oldObj.maxPrice = oldMaxPrice; } // Use microdiff to get differences @@ -242,6 +258,7 @@ export async function transformNotionProperty(env, notionProperty) { const smoobuId = properties["Smoobu ID"]?.number || null; const syncName = properties["Sync Name"]?.checkbox || false; + const syncPrice = properties["Sync Price"]?.checkbox || false; const features = properties["Features"]?.["multi_select"].map((feature) => feature.name.replace(/,/g, ";") @@ -277,6 +294,7 @@ export async function transformNotionProperty(env, notionProperty) { content, smoobuId, syncName, + syncPrice, active, }; } @@ -330,8 +348,9 @@ export async function updateNotionProperty(env, property, notionId) { Timezone: { select: { name: property.timezone || "UTC" } }, Address: property.address, Features: property.features, - "Min Price": property.minPrice, - "Max Price": property.maxPrice, + ...(property.syncPrice + ? { "Min Price": property.minPrice, "Max Price": property.maxPrice } + : {}), }; Object.keys(notionProps).forEach( (k) => notionProps[k] === undefined && delete notionProps[k]