Implemented Sync Price
Some checks failed
thehideout/TheHideout-API/pipeline/head There was a failure building this commit

This commit is contained in:
Tom Butcher 2026-01-03 00:55:06 +00:00
parent 0cafe140a0
commit b406165866

View File

@ -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]