|
|
|
@ -3,7 +3,8 @@ |
|
|
|
|
const removeBans = require(__dirname+'/../../models/forms/removebans.js') |
|
|
|
|
, dynamicResponse = require(__dirname+'/../../lib/misc/dynamic.js') |
|
|
|
|
, denyAppeals = require(__dirname+'/../../models/forms/denybanappeals.js') |
|
|
|
|
, editBans = require(__dirname+'/../../models/forms/editbans.js') |
|
|
|
|
, editBanDuration = require(__dirname+'/../../models/forms/editbanduration.js') |
|
|
|
|
, editBanNote = require(__dirname+'/../../models/forms/editbannote.js') |
|
|
|
|
, upgradeBans = require(__dirname+'/../../models/forms/upgradebans.js') |
|
|
|
|
, paramConverter = require(__dirname+'/../../lib/middleware/input/paramconverter.js') |
|
|
|
|
, { checkSchema, lengthBody, numberBody, inArrayBody } = require(__dirname+'/../../lib/input/schema.js'); |
|
|
|
@ -13,7 +14,7 @@ module.exports = { |
|
|
|
|
paramConverter: paramConverter({ |
|
|
|
|
timeFields: ['ban_duration'], |
|
|
|
|
numberFields: ['upgrade'], |
|
|
|
|
trimFields: ['option'], |
|
|
|
|
trimFields: ['option', 'ban_note'], |
|
|
|
|
allowedArrays: ['checkedbans'], |
|
|
|
|
objectIdArrays: ['checkedbans'] |
|
|
|
|
}), |
|
|
|
@ -22,8 +23,9 @@ module.exports = { |
|
|
|
|
|
|
|
|
|
const errors = await checkSchema([ |
|
|
|
|
{ result: lengthBody(req.body.checkedbans, 1), expected: false, error: 'Must select at least one ban' }, |
|
|
|
|
{ result: inArrayBody(req.body.option, ['unban', 'edit', 'upgrade', 'deny_appeal']), expected: true, error: 'Invalid ban action' }, |
|
|
|
|
{ result: req.body.option !== 'edit' || numberBody(req.body.ban_duration, 1), expected: true, error: 'Invalid ban duration' }, |
|
|
|
|
{ result: inArrayBody(req.body.option, ['unban', 'edit_duration', 'edit_note', 'upgrade', 'deny_appeal']), expected: true, error: 'Invalid ban action' }, |
|
|
|
|
{ result: req.body.option !== 'edit_duration' || numberBody(req.body.ban_duration, 1), expected: true, error: 'Invalid ban duration' }, |
|
|
|
|
{ result: req.body.option !== 'edit_note' || !lengthBody(req.body.ban_note, 1), expected: true, error: 'Invalid ban note' }, |
|
|
|
|
{ result: req.body.option !== 'upgrade' || inArrayBody(req.body.upgrade, [1, 2]), expected: true, error: 'Invalid ban upgrade option' }, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
@ -53,9 +55,13 @@ module.exports = { |
|
|
|
|
amount = await upgradeBans(req, res, next); |
|
|
|
|
message = `Upgraded ${amount} bans`; |
|
|
|
|
break; |
|
|
|
|
case 'edit': //could do other properties in future
|
|
|
|
|
amount = await editBans(req, res, next); |
|
|
|
|
message = `Edited ${amount} bans`; |
|
|
|
|
case 'edit_duration': |
|
|
|
|
amount = await editBanDuration(req, res, next); |
|
|
|
|
message = `Edited duration for ${amount} bans`; |
|
|
|
|
break; |
|
|
|
|
case 'edit_note': |
|
|
|
|
amount = await editBanNote(req, res, next); |
|
|
|
|
message = `Edited note for ${amount} bans`; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
throw 'Invalid ban action'; //should never happen anyway
|
|
|
|
|