"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sanitizationMiddleware = void 0;
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
const sanitizeValue = (value) => {
    if (Array.isArray(value)) {
        return value.map(sanitizeValue);
    }
    if (isObject(value)) {
        const sanitized = {};
        for (const [key, val] of Object.entries(value)) {
            if (key.startsWith('$') || key.includes('.')) {
                continue;
            }
            sanitized[key] = sanitizeValue(val);
        }
        return sanitized;
    }
    if (typeof value === 'string') {
        return value.trim();
    }
    return value;
};
const sanitizationMiddleware = (req, _res, next) => {
    if (req.body) {
        req.body = sanitizeValue(req.body);
    }
    if (req.query) {
        req.query = sanitizeValue(req.query);
    }
    if (req.params) {
        req.params = sanitizeValue(req.params);
    }
    next();
};
exports.sanitizationMiddleware = sanitizationMiddleware;
//# sourceMappingURL=sanitization.middleware.js.map