mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.4 KiB
41 lines
1.4 KiB
3 years ago
|
'use strict';
|
||
|
|
||
|
const deleteStaff = require(__dirname+'/../../models/forms/deletestaff.js')
|
||
|
, dynamicResponse = require(__dirname+'/../../helpers/dynamic.js')
|
||
|
, paramConverter = require(__dirname+'/../../helpers/paramconverter.js')
|
||
|
, { checkSchema, lengthBody, numberBody, minmaxBody, numberBodyVariable,
|
||
|
inArrayBody, arrayInBody, existsBody } = require(__dirname+'/../../helpers/schema.js');
|
||
|
|
||
|
module.exports = {
|
||
|
|
||
|
paramConverter: paramConverter({
|
||
|
allowedArrays: ['checkedstaff'],
|
||
|
}),
|
||
|
|
||
|
controller: async (req, res, next) => {
|
||
|
|
||
|
const errors = await checkSchema([
|
||
|
{ result: lengthBody(req.body.checkedstaff, 1), expected: false, error: 'Must select at least one staff to delete' },
|
||
|
{ result: existsBody(req.body.checkedstaff) && req.body.checkedstaff.some(s => !res.locals.board.staff[s]), expected: false, error: 'Invalid staff selection' },
|
||
|
//not really necessary, but its a bit retarded to "delete yourself" as staff this way
|
||
|
{ result: existsBody(req.body.checkedstaff) && req.body.checkedstaff.some(s => s === res.locals.user.username), expected: false, error: 'Resign from the accounts page instead' },
|
||
|
]);
|
||
|
|
||
|
if (errors.length > 0) {
|
||
|
return dynamicResponse(req, res, 400, 'message', {
|
||
|
'title': 'Bad request',
|
||
|
'errors': errors,
|
||
|
'redirect': req.headers.referer || `/${req.params.board}/manage/staff.html`,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
await deleteStaff(req, res, next);
|
||
|
} catch (err) {
|
||
|
return next(err);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|