mirror of
https://github.com/directus/directus.git
synced 2026-02-08 18:04:57 -05:00
* Fix string unexpectedly being casted to numbers * Parse filter with multiple keys into `_and` block. * Fixed filter structure in tests
30 lines
668 B
TypeScript
30 lines
668 B
TypeScript
/**
|
|
* Sanitize query parameters.
|
|
* This ensures that query params are formatted and ready to go for the services.
|
|
*/
|
|
|
|
import { RequestHandler } from 'express';
|
|
import { sanitizeQuery } from '../utils/sanitize-query';
|
|
import { validateQuery } from '../utils/validate-query';
|
|
|
|
const sanitizeQueryMiddleware: RequestHandler = (req, _res, next) => {
|
|
req.sanitizedQuery = {};
|
|
if (!req.query) return;
|
|
|
|
req.sanitizedQuery = sanitizeQuery(
|
|
{
|
|
fields: req.query.fields || '*',
|
|
...req.query,
|
|
},
|
|
req.accountability || null
|
|
);
|
|
|
|
Object.freeze(req.sanitizedQuery);
|
|
|
|
validateQuery(req.sanitizedQuery);
|
|
|
|
return next();
|
|
};
|
|
|
|
export default sanitizeQueryMiddleware;
|