Skip to content

Commit

Permalink
Remove unused validationResult imports
Browse files Browse the repository at this point in the history
  • Loading branch information
chimpdev committed Sep 29, 2024
1 parent 55a74c5 commit 6809f5b
Show file tree
Hide file tree
Showing 78 changed files with 111 additions and 384 deletions.
5 changes: 1 addition & 4 deletions server/src/routes/auth/@me/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Template = require('@/schemas/Template');
const VoteReminder = require('@/schemas/Server/Vote/Reminder');
const Reminder = require('@/schemas/Reminder');
const bodyParser = require('body-parser');
const { body, validationResult, matchedData } = require('express-validator');
const { body, matchedData } = require('express-validator');
const Deny = require('@/src/schemas/Bot/Deny');
const Sound = require('@/schemas/Sound');
const Link = require('@/schemas/Link');
Expand Down Expand Up @@ -41,9 +41,6 @@ module.exports = {
.custom(keys => keys.every(key => validKeys.includes(key))).withMessage('Invalid key provided.'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { keys } = matchedData(request);
const responseData = {};

Expand Down
5 changes: 1 addition & 4 deletions server/src/routes/auth/login.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { query, validationResult, matchedData } = require('express-validator');
const { query, matchedData } = require('express-validator');
const passport = require('passport');

module.exports = {
Expand All @@ -12,9 +12,6 @@ module.exports = {
}
}),
async (request, response, next) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { redirect } = matchedData(request);
if (redirect) {
const redirectUrl = new URL(redirect);
Expand Down
5 changes: 1 addition & 4 deletions server/src/routes/blocked-ips/[ip].js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const BlockedIp = require('@/schemas/BlockedIp');
const { param, validationResult, matchedData } = require('express-validator');
const { param, matchedData } = require('express-validator');
const useRateLimiter = require('@/utils/useRateLimiter');
const validateBody = require('@/utils/middlewares/validateBody');

Expand All @@ -12,9 +12,6 @@ module.exports = {
.isIP().withMessage('Invalid IP address'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const canDelete = config.permissions.canDeleteBlockedIps.includes(request.user.id);
if (!canDelete) return response.sendError('You do not have permission to delete blocked IPs.', 403);

Expand Down
5 changes: 1 addition & 4 deletions server/src/routes/bot-denies/[id].js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const BotDeny = require('@/schemas/Bot/Deny');
const { param, validationResult, matchedData } = require('express-validator');
const { param, matchedData } = require('express-validator');
const useRateLimiter = require('@/utils/useRateLimiter');
const validateBody = require('@/utils/middlewares/validateBody');

Expand All @@ -11,9 +11,6 @@ module.exports = {
param('id'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const canDelete = request.member && config.permissions.canDeleteBotDeniesRoles.some(role => request.member.roles.cache.has(role));
if (!canDelete) return response.sendError('You do not have permission to delete bot denies.', 403);

Expand Down
7 changes: 2 additions & 5 deletions server/src/routes/bots/[id]/deny.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const useRateLimiter = require('@/utils/useRateLimiter');
const { param, matchedData, body, validationResult } = require('express-validator');
const { param, matchedData, body} = require('express-validator');
const Bot = require('@/schemas/Bot');
const BotDeny = require('@/schemas/Bot/Deny');
const bodyParser = require('body-parser');
Expand All @@ -18,10 +18,7 @@ module.exports = {
.isString().withMessage('Reason must be a string.')
.isIn(Object.keys(config.botsDenyReasons)).withMessage('Invalid reason.'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

async (request, response) => {
const { id, reason } = matchedData(request);
if (!config.botsDenyReasons[reason]) return response.sendError('Invalid reason.', 400);

Expand Down
5 changes: 1 addition & 4 deletions server/src/routes/bots/[id]/extra-owners/[userId].js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const useRateLimiter = require('@/utils/useRateLimiter');
const { param, validationResult, matchedData } = require('express-validator');
const { param, matchedData } = require('express-validator');
const Bot = require('@/schemas/Bot');
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const validateBody = require('@/utils/middlewares/validateBody');
Expand All @@ -15,9 +15,6 @@ module.exports = {
.matches(/^\d+$/).withMessage('User ID must be a number.'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id } = matchedData(request);

const bot = await Bot.findOne({ id });
Expand Down
8 changes: 1 addition & 7 deletions server/src/routes/bots/[id]/extra-owners/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const useRateLimiter = require('@/utils/useRateLimiter');
const { param, validationResult, matchedData, body } = require('express-validator');
const { param, matchedData, body } = require('express-validator');
const Bot = require('@/schemas/Bot');
const bodyParser = require('body-parser');
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
Expand All @@ -12,9 +12,6 @@ module.exports = {
param('id'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id } = matchedData(request);

const bot = await Bot.findOne({ id });
Expand Down Expand Up @@ -53,9 +50,6 @@ module.exports = {
.matches(/^\d+$/).withMessage('User ID must be a number.'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id } = matchedData(request);

const bot = await Bot.findOne({ id });
Expand Down
14 changes: 1 addition & 13 deletions server/src/routes/bots/[id]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const categoriesValidation = require('@/utils/validations/bots/categories');
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const useRateLimiter = require('@/utils/useRateLimiter');
const bodyParser = require('body-parser');
const { param, body, validationResult, matchedData } = require('express-validator');
const { param, body, matchedData } = require('express-validator');
const findQuarantineEntry = require('@/utils/findQuarantineEntry');
const Bot = require('@/schemas/Bot');
const Server = require('@/schemas/Server');
Expand All @@ -24,9 +24,6 @@ module.exports = {
param('id'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id } = matchedData(request);

const bot = await Bot.findOne({ id });
Expand Down Expand Up @@ -137,9 +134,6 @@ module.exports = {
.custom(categoriesValidation),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id, short_description, description, invite_url, categories } = matchedData(request);

const userOrBotQuarantined = await findQuarantineEntry.multiple([
Expand Down Expand Up @@ -242,9 +236,6 @@ module.exports = {
param('id'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id } = matchedData(request);

const user = await client.users.fetch(id).catch(() => null);
Expand Down Expand Up @@ -303,9 +294,6 @@ module.exports = {
.custom(githubRepositoryValidation),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id, short_description, description, invite_url, categories, support_server_id, github_repository } = matchedData(request);

const bot = await Bot.findOne({ id });
Expand Down
5 changes: 1 addition & 4 deletions server/src/routes/bots/[id]/metadata.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const useRateLimiter = require('@/utils/useRateLimiter');
const { param, validationResult, matchedData } = require('express-validator');
const { param, matchedData } = require('express-validator');
const Bot = require('@/schemas/Bot');
const User = require('@/schemas/User');
const getUserHashes = require('@/utils/getUserHashes');
Expand All @@ -11,9 +11,6 @@ module.exports = {
param('id'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id } = matchedData(request);

const bot = await Bot.findOne({ id });
Expand Down
7 changes: 2 additions & 5 deletions server/src/routes/bots/[id]/reviews/[review_id]/approve.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const useRateLimiter = require('@/utils/useRateLimiter');
const { param, matchedData, validationResult } = require('express-validator');
const { param, matchedData} = require('express-validator');
const Bot = require('@/schemas/Bot');
const Review = require('@/schemas/Bot/Review');
const Discord = require('discord.js');
Expand All @@ -14,10 +14,7 @@ module.exports = {
param('review_id')
.isMongoId().withMessage('Invalid review ID'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

async (request, response) => {
const canApprove = request.member && config.permissions.canApproveReviewsRoles.some(roleId => request.member.roles.cache.has(roleId));
if (!canApprove) return response.sendError('You are not allowed to approve reviews.', 403);

Expand Down
7 changes: 2 additions & 5 deletions server/src/routes/bots/[id]/reviews/[review_id]/deny.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const useRateLimiter = require('@/utils/useRateLimiter');
const { param, matchedData, validationResult, body } = require('express-validator');
const { param, matchedData, body } = require('express-validator');
const Bot = require('@/schemas/Bot');
const Review = require('@/schemas/Bot/Review');
const bodyParser = require('body-parser');
Expand All @@ -19,10 +19,7 @@ module.exports = {
.isString().withMessage('Reason must be a string.')
.isLength({ min: 1, max: 200 }).withMessage('Reason must be between 1 and 200 characters.'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

async (request, response) => {
const canDeny = request.member && config.permissions.canApproveReviewsRoles.some(roleId => request.member.roles.cache.has(roleId));
if (!canDeny) return response.sendError('You are not allowed to deny reviews.', 403);

Expand Down
7 changes: 2 additions & 5 deletions server/src/routes/bots/[id]/reviews/[review_id]/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const useRateLimiter = require('@/utils/useRateLimiter');
const { param, matchedData, validationResult } = require('express-validator');
const { param, matchedData} = require('express-validator');
const Review = require('@/schemas/Bot/Review');
const validateBody = require('@/utils/middlewares/validateBody');

Expand All @@ -12,10 +12,7 @@ module.exports = {
param('review_id')
.isMongoId().withMessage('Invalid review ID.'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

async (request, response) => {
const canDelete = config.permissions.canDeleteReviewsRoles.some(role => request.member.roles.cache.has(role));
if (!canDelete) return response.sendError('You are not allowed to delete reviews.', 403);

Expand Down
5 changes: 1 addition & 4 deletions server/src/routes/bots/[id]/reviews/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const useRateLimiter = require('@/utils/useRateLimiter');
const { param, matchedData, body, validationResult } = require('express-validator');
const { param, matchedData, body} = require('express-validator');
const Bot = require('@/schemas/Bot');
const Review = require('@/schemas/Bot/Review');
const bodyParser = require('body-parser');
Expand All @@ -22,9 +22,6 @@ module.exports = {
.isLength({ min: config.reviewsMinCharacters, max: config.reviewsMaxCharacters }).withMessage(`Content must be between ${config.reviewsMinCharacters} and ${config.reviewsMaxCharacters} characters.`),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const userQuarantined = await findQuarantineEntry.single('USER_ID', request.user.id, 'BOTS_CREATE_REVIEW').catch(() => false);
if (userQuarantined) return response.sendError('You are not allowed to review bots.', 403);

Expand Down
7 changes: 2 additions & 5 deletions server/src/routes/bots/[id]/stats.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const useRateLimiter = require('@/utils/useRateLimiter');
const { param, body, matchedData, validationResult } = require('express-validator');
const { param, body, matchedData} = require('express-validator');
const Bot = require('@/schemas/Bot');
const bodyParser = require('body-parser');
const getApproximateGuildCount = require('@/utils/bots/getApproximateGuildCount');
Expand All @@ -17,10 +17,7 @@ module.exports = {
.isInt({ min: 0, max: 10000000 }).withMessage('Server count must be between 0 and 10 Million.')
.optional(),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

async (request, response) => {
const { id, command_count, server_count } = matchedData(request);

if (!command_count && !server_count) return response.sendError('One of the following fields is required: command_count, server_count.', 400);
Expand Down
5 changes: 1 addition & 4 deletions server/src/routes/bots/[id]/voters/[user_id]/timeout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { param, validationResult, matchedData } = require('express-validator');
const { param, matchedData } = require('express-validator');
const useRateLimiter = require('@/utils/useRateLimiter');
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const BotTimeout = require('@/schemas/Bot/Vote/Timeout');
Expand All @@ -12,9 +12,6 @@ module.exports = {
param('user_id'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const canDelete = request.member && config.permissions.canDeleteTimeoutsRoles.some(roleId => request.member.roles.cache.has(roleId));
if (!canDelete) return response.sendError('You do not have permission to delete timeouts.', 403);

Expand Down
5 changes: 1 addition & 4 deletions server/src/routes/bots/[id]/voters/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { query, param, validationResult, matchedData } = require('express-validator');
const { query, param, matchedData } = require('express-validator');
const useRateLimiter = require('@/utils/useRateLimiter');
const Bot = require('@/schemas/Bot');
const getUserHashes = require('@/utils/getUserHashes');
Expand All @@ -18,9 +18,6 @@ module.exports = {
.toInt(),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id, page = 1, limit = 12 } = matchedData(request);

const user = client.users.cache.get(id) || await client.users.fetch(id).catch(() => null);
Expand Down
8 changes: 1 addition & 7 deletions server/src/routes/bots/[id]/webhook-settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const checkAuthentication = require('@/utils/middlewares/checkAuthentication');
const useRateLimiter = require('@/utils/useRateLimiter');
const bodyParser = require('body-parser');
const { param, body, validationResult, matchedData } = require('express-validator');
const { param, body, matchedData } = require('express-validator');
const Bot = require('@/schemas/Bot');
const getValidationError = require('@/utils/getValidationError');
const validateBody = require('@/utils/middlewares/validateBody');
Expand All @@ -13,9 +13,6 @@ module.exports = {
param('id'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id } = matchedData(request);

const user = await client.users.fetch(id).catch(() => null);
Expand Down Expand Up @@ -58,9 +55,6 @@ module.exports = {
.trim(),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { id, url, token } = matchedData(request);

const bot = await Bot.findOne({ id });
Expand Down
5 changes: 1 addition & 4 deletions server/src/routes/bots/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { query, validationResult } = require('express-validator');
const { query} = require('express-validator');
const useRateLimiter = require('@/utils/useRateLimiter');
const categoriesValidation = require('@/validations/bots/categories');
const Bot = require('@/schemas/Bot');
Expand Down Expand Up @@ -34,9 +34,6 @@ module.exports = {
.toInt(),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { query, category = 'All', sort = 'Votes', limit = 12, page = 1 } = request.query;
const skip = (page - 1) * limit;
const baseFilter = category !== 'All' ? { categories: { $in: [category] }, verified: true } : { verified: true };
Expand Down
5 changes: 1 addition & 4 deletions server/src/routes/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const BotTimeout = require('@/schemas/Bot/Vote/Timeout');
const ServerTimeout = require('@/schemas/Server/Vote/Timeout');
const BlockedIp = require('@/schemas/BlockedIp');
const bodyParser = require('body-parser');
const { body, validationResult, matchedData } = require('express-validator');
const { body, matchedData } = require('express-validator');
const Quarantine = require('@/schemas/Quarantine');
const Link = require('@/schemas/Link');
const getUserHashes = require('@/utils/getUserHashes');
Expand Down Expand Up @@ -50,9 +50,6 @@ module.exports = {
.custom(keys => keys.every(key => validKeys.includes(key))).withMessage('Invalid key provided.'),
validateBody,
async (request, response) => {
const errors = validationResult(request);
if (!errors.isEmpty()) return response.sendError(errors.array()[0].msg, 400);

const { keys } = matchedData(request);

const permissions = {
Expand Down
Loading

0 comments on commit 6809f5b

Please sign in to comment.