Files
klz-cables.com/.pnpm-store/v10/files/18/929b514ee0e16a9bba08d407bb3eaa81942a4f16a8c9866cfa52c981bc7b3ebb8d7b38019447d6dfeb38874b89ae89892444129d2e762b503db32dbccaa948
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

54 lines
1.7 KiB
Plaintext

/**
* Transforms a basic "where" query into a format in which the "where builder" can understand.
* Even though basic queries are valid, we need to hoist them into the "and" / "or" format.
* Use this function alongside `validateWhereQuery` to check that for valid queries before transforming.
* @example
* Inaccurate: [text][equals]=example%20post
* Accurate: [or][0][and][0][text][equals]=example%20post
*/ export const transformWhereQuery = (whereQuery)=>{
if (!whereQuery) {
return {};
}
// Check if 'whereQuery' has 'or' field but no 'and'. This is the case for "correct" queries
if (whereQuery.or && !whereQuery.and) {
return {
or: whereQuery.or.map((query)=>{
// ...but if the or query does not have an and, we need to add it
if (!query.and) {
return {
and: [
query
]
};
}
return query;
})
};
}
// Check if 'whereQuery' has 'and' field but no 'or'.
if (whereQuery.and && !whereQuery.or) {
return {
or: [
{
and: whereQuery.and
}
]
};
}
// Check if 'whereQuery' has neither 'or' nor 'and'.
if (!whereQuery.or && !whereQuery.and) {
return {
or: [
{
and: [
whereQuery
]
}
]
};
}
// If 'whereQuery' has 'or' and 'and', just return it as it is.
return whereQuery;
};
//# sourceMappingURL=transformWhereQuery.js.map