"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidPlaylistIdParam = exports.isValidVideoIdParam = exports.areValidationErrors = void 0;
const express_validator_1 = require("express-validator");
const misc_1 = require("../../../helpers/custom-validators/misc");
const logger_1 = require("../../../helpers/logger");
function areValidationErrors(req, res) {
    const errors = (0, express_validator_1.validationResult)(req);
    if (!errors.isEmpty()) {
        logger_1.logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() });
        res.fail({
            message: 'Incorrect request parameters: ' + Object.keys(errors.mapped()).join(', '),
            instance: req.originalUrl,
            data: {
                'invalid-params': errors.mapped()
            }
        });
        return true;
    }
    return false;
}
exports.areValidationErrors = areValidationErrors;
function isValidVideoIdParam(paramName) {
    return (0, express_validator_1.param)(paramName)
        .customSanitizer(misc_1.toCompleteUUID)
        .custom(misc_1.isIdOrUUIDValid).withMessage('Should have a valid video id');
}
exports.isValidVideoIdParam = isValidVideoIdParam;
function isValidPlaylistIdParam(paramName) {
    return (0, express_validator_1.param)(paramName)
        .customSanitizer(misc_1.toCompleteUUID)
        .custom(misc_1.isIdOrUUIDValid).withMessage('Should have a valid playlist id');
}
exports.isValidPlaylistIdParam = isValidPlaylistIdParam;
//# sourceMappingURL=utils.js.map