Files
klz-cables.com/.pnpm-store/v10/files/d1/f8b9ea98b28d92b739aecd0a097e65e0b06427d5f8ce3a05710cdc20e0e5ec02c7ec8da7996d94a00f4ff2a6d8a295bd37fb6cd7fb86af67502c056b78db7e
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

42 lines
1.1 KiB
Plaintext

const sanitizeSort = ({ fields, sort })=>{
let sortProperty = sort;
let desc = false;
if (sort.indexOf('-') === 0) {
desc = true;
sortProperty = sortProperty.substring(1);
}
const segments = sortProperty.split('.');
for (const segment of segments){
const field = fields.find((each)=>each.name === segment);
if (!field) {
return sort;
}
if ('fields' in field) {
fields = field.flattenedFields;
continue;
}
if ('virtual' in field && typeof field.virtual === 'string') {
return `${desc ? '-' : ''}${field.virtual}`;
}
}
return sort;
};
/**
* Sanitizes the sort parameter, for example virtual fields linked to relationships are replaced with the full path.
*/ export const sanitizeSortQuery = ({ fields, sort })=>{
if (!sort) {
return undefined;
}
if (Array.isArray(sort)) {
return sort.map((sort)=>sanitizeSort({
fields,
sort
}));
}
return sanitizeSort({
fields,
sort
});
};
//# sourceMappingURL=sanitizeSortQuery.js.map