Implemented Sync Price
Some checks failed
thehideout/TheHideout-API/pipeline/head There was a failure building this commit
Some checks failed
thehideout/TheHideout-API/pipeline/head There was a failure building this commit
This commit is contained in:
parent
0cafe140a0
commit
b406165866
@ -167,20 +167,36 @@ export function diffProperties(newList, oldList) {
|
|||||||
if (!old) return false;
|
if (!old) return false;
|
||||||
|
|
||||||
// If syncName is false, exclude name from comparison
|
// If syncName is false, exclude name from comparison
|
||||||
const { smoobuId, notionId, name, ...restNew } = p;
|
// If syncPrice is false, exclude prices from comparison
|
||||||
const { smoobuId: _, notionId: __, name: oldName, ...restOld } = old;
|
const { smoobuId, notionId, name, minPrice, maxPrice, ...restNew } = p;
|
||||||
|
const {
|
||||||
|
smoobuId: _,
|
||||||
|
notionId: __,
|
||||||
|
name: oldName,
|
||||||
|
minPrice: oldMinPrice,
|
||||||
|
maxPrice: oldMaxPrice,
|
||||||
|
...restOld
|
||||||
|
} = old;
|
||||||
|
|
||||||
// Prepare objects for comparison
|
// Prepare objects for comparison
|
||||||
let newObj, oldObj;
|
let newObj, oldObj;
|
||||||
|
|
||||||
if (old.syncName === false) {
|
// Build objects conditionally based on sync flags
|
||||||
// Don't compare names when syncName is false
|
newObj = { ...restNew };
|
||||||
newObj = restNew;
|
oldObj = { ...restOld };
|
||||||
oldObj = restOld;
|
|
||||||
} else {
|
if (old.syncName !== false) {
|
||||||
// Include name in comparison when syncName is true or undefined
|
// Include name in comparison when syncName is true or undefined
|
||||||
newObj = { name, ...restNew };
|
newObj.name = name;
|
||||||
oldObj = { name: oldName, ...restOld };
|
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
|
// Use microdiff to get differences
|
||||||
@ -242,6 +258,7 @@ export async function transformNotionProperty(env, notionProperty) {
|
|||||||
const smoobuId = properties["Smoobu ID"]?.number || null;
|
const smoobuId = properties["Smoobu ID"]?.number || null;
|
||||||
|
|
||||||
const syncName = properties["Sync Name"]?.checkbox || false;
|
const syncName = properties["Sync Name"]?.checkbox || false;
|
||||||
|
const syncPrice = properties["Sync Price"]?.checkbox || false;
|
||||||
|
|
||||||
const features = properties["Features"]?.["multi_select"].map((feature) =>
|
const features = properties["Features"]?.["multi_select"].map((feature) =>
|
||||||
feature.name.replace(/,/g, ";")
|
feature.name.replace(/,/g, ";")
|
||||||
@ -277,6 +294,7 @@ export async function transformNotionProperty(env, notionProperty) {
|
|||||||
content,
|
content,
|
||||||
smoobuId,
|
smoobuId,
|
||||||
syncName,
|
syncName,
|
||||||
|
syncPrice,
|
||||||
active,
|
active,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -330,8 +348,9 @@ export async function updateNotionProperty(env, property, notionId) {
|
|||||||
Timezone: { select: { name: property.timezone || "UTC" } },
|
Timezone: { select: { name: property.timezone || "UTC" } },
|
||||||
Address: property.address,
|
Address: property.address,
|
||||||
Features: property.features,
|
Features: property.features,
|
||||||
"Min Price": property.minPrice,
|
...(property.syncPrice
|
||||||
"Max Price": property.maxPrice,
|
? { "Min Price": property.minPrice, "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]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user