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
42 lines
1.1 KiB
Plaintext
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 |