payload
Version:
Node, React, Headless CMS and Application Framework built on Next.js
24 lines (23 loc) • 985 B
JavaScript
// @ts-strict-ignore
import { isNumber } from './isNumber.js';
/**
* Convert request JoinQuery object from strings to numbers
* @param joins
*/ export const sanitizeJoinParams = (joins = {})=>{
const joinQuery = {};
Object.keys(joins).forEach((schemaPath)=>{
if (joins[schemaPath] === 'false' || joins[schemaPath] === false) {
joinQuery[schemaPath] = false;
} else {
joinQuery[schemaPath] = {
count: joins[schemaPath].count === 'true',
limit: isNumber(joins[schemaPath]?.limit) ? Number(joins[schemaPath].limit) : undefined,
page: isNumber(joins[schemaPath]?.page) ? Number(joins[schemaPath].page) : undefined,
sort: joins[schemaPath]?.sort ? joins[schemaPath].sort : undefined,
where: joins[schemaPath]?.where ? joins[schemaPath].where : undefined
};
}
});
return joinQuery;
};
//# sourceMappingURL=sanitizeJoinParams.js.map