"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.pluginsSortValidator = exports.videoChannelSyncsSortValidator = exports.videoChannelsFollowersSortValidator = exports.accountsFollowersSortValidator = exports.videoPlaylistsSearchSortValidator = exports.videoRedundanciesSortValidator = exports.videoPlaylistsSortValidator = exports.userNotificationsSortValidator = exports.serversBlocklistSortValidator = exports.accountsBlocklistSortValidator = exports.videoChannelsSearchSortValidator = exports.availablePluginsSortValidator = exports.userSubscriptionsSortValidator = exports.videoRatesSortValidator = exports.videoCommentThreadsSortValidator = exports.jobsSortValidator = exports.instanceFollowingSortValidator = exports.instanceFollowersSortValidator = exports.accountsSortValidator = exports.blacklistSortValidator = exports.videosSortValidator = exports.videosSearchSortValidator = exports.videoCommentsValidator = exports.videoImportsSortValidator = exports.videoChannelsSortValidator = exports.abusesSortValidator = exports.adminUsersSortValidator = void 0;
const express_validator_1 = require("express-validator");
const constants_1 = require("../../initializers/constants");
const shared_1 = require("./shared");
function checkSortFactory(columns, tags = []) {
    return checkSort(createSortableColumns(columns), tags);
}
function checkSort(sortableColumns, tags = []) {
    return [
        (0, express_validator_1.query)('sort')
            .optional()
            .isIn(sortableColumns),
        (req, res, next) => {
            if ((0, shared_1.areValidationErrors)(req, res, { tags }))
                return;
            return next();
        }
    ];
}
function createSortableColumns(sortableColumns) {
    const sortableColumnDesc = sortableColumns.map(sortableColumn => '-' + sortableColumn);
    return sortableColumns.concat(sortableColumnDesc);
}
const adminUsersSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.ADMIN_USERS);
exports.adminUsersSortValidator = adminUsersSortValidator;
const accountsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.ACCOUNTS);
exports.accountsSortValidator = accountsSortValidator;
const jobsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.JOBS, ['jobs']);
exports.jobsSortValidator = jobsSortValidator;
const abusesSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.ABUSES);
exports.abusesSortValidator = abusesSortValidator;
const videosSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEOS);
exports.videosSortValidator = videosSortValidator;
const videoImportsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEO_IMPORTS);
exports.videoImportsSortValidator = videoImportsSortValidator;
const videosSearchSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEOS_SEARCH);
exports.videosSearchSortValidator = videosSearchSortValidator;
const videoChannelsSearchSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEO_CHANNELS_SEARCH);
exports.videoChannelsSearchSortValidator = videoChannelsSearchSortValidator;
const videoPlaylistsSearchSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEO_PLAYLISTS_SEARCH);
exports.videoPlaylistsSearchSortValidator = videoPlaylistsSearchSortValidator;
const videoCommentsValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEO_COMMENTS);
exports.videoCommentsValidator = videoCommentsValidator;
const videoCommentThreadsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS);
exports.videoCommentThreadsSortValidator = videoCommentThreadsSortValidator;
const videoRatesSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEO_RATES);
exports.videoRatesSortValidator = videoRatesSortValidator;
const blacklistSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.BLACKLISTS);
exports.blacklistSortValidator = blacklistSortValidator;
const videoChannelsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEO_CHANNELS);
exports.videoChannelsSortValidator = videoChannelsSortValidator;
const instanceFollowersSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.INSTANCE_FOLLOWERS);
exports.instanceFollowersSortValidator = instanceFollowersSortValidator;
const instanceFollowingSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.INSTANCE_FOLLOWING);
exports.instanceFollowingSortValidator = instanceFollowingSortValidator;
const userSubscriptionsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.USER_SUBSCRIPTIONS);
exports.userSubscriptionsSortValidator = userSubscriptionsSortValidator;
const accountsBlocklistSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.ACCOUNTS_BLOCKLIST);
exports.accountsBlocklistSortValidator = accountsBlocklistSortValidator;
const serversBlocklistSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.SERVERS_BLOCKLIST);
exports.serversBlocklistSortValidator = serversBlocklistSortValidator;
const userNotificationsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.USER_NOTIFICATIONS);
exports.userNotificationsSortValidator = userNotificationsSortValidator;
const videoPlaylistsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEO_PLAYLISTS);
exports.videoPlaylistsSortValidator = videoPlaylistsSortValidator;
const pluginsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.PLUGINS);
exports.pluginsSortValidator = pluginsSortValidator;
const availablePluginsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.AVAILABLE_PLUGINS);
exports.availablePluginsSortValidator = availablePluginsSortValidator;
const videoRedundanciesSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEO_REDUNDANCIES);
exports.videoRedundanciesSortValidator = videoRedundanciesSortValidator;
const videoChannelSyncsSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.VIDEO_CHANNEL_SYNCS);
exports.videoChannelSyncsSortValidator = videoChannelSyncsSortValidator;
const accountsFollowersSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.ACCOUNT_FOLLOWERS);
exports.accountsFollowersSortValidator = accountsFollowersSortValidator;
const videoChannelsFollowersSortValidator = checkSortFactory(constants_1.SORTABLE_COLUMNS.CHANNEL_FOLLOWERS);
exports.videoChannelsFollowersSortValidator = videoChannelsFollowersSortValidator;
//# sourceMappingURL=sort.js.map