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.
64 lines
1.6 KiB
64 lines
1.6 KiB
2 years ago
|
'use strict';
|
||
|
|
||
|
const { Accounts, Boards } = require(__dirname+'/../../db/')
|
||
|
, dynamicResponse = require(__dirname+'/../../helpers/dynamic.js')
|
||
|
, cache = require(__dirname+'/../../redis.js')
|
||
|
|
||
|
module.exports = async (req, res, next) => {
|
||
|
|
||
|
const accountsWithBoards = await Accounts.getOwnedOrStaffBoards(req.body.checkedaccounts);
|
||
|
if (accountsWithBoards.length > 0) {
|
||
|
const bulkWrites = [];
|
||
|
for (let i = 0; i < accountsWithBoards.length; i++) {
|
||
|
const acc = accountsWithBoards[i];
|
||
|
if (acc.staffBoards.length > 0) {
|
||
|
//remove from staff of any boards they are mod on
|
||
|
bulkWrites.push({
|
||
|
'updateMany': {
|
||
|
'filter': {
|
||
|
'_id': {
|
||
|
'$in': acc.staffBoards
|
||
|
}
|
||
|
},
|
||
|
'update': {
|
||
|
'$unset': {
|
||
|
[`staff.${acc.username}`]: "",
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
cache.del(acc.staffBoards.map(b => `board:${b}`));
|
||
|
}
|
||
|
if (acc.ownedBoards.length > 0) {
|
||
|
//remove as owner of any boards they own
|
||
|
bulkWrites.push({
|
||
|
'updateMany': {
|
||
|
'filter': {
|
||
|
'_id': {
|
||
|
'$in': acc.ownedBoards
|
||
|
}
|
||
|
},
|
||
|
'update': {
|
||
|
'$set': {
|
||
|
'owner': null //board has no owner
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
cache.del(acc.ownedBoards.map(b => `board:${b}`));
|
||
|
//todo: use list of board with no owners for claims
|
||
|
}
|
||
|
}
|
||
|
await Boards.db.bulkWrite(bulkWrites);
|
||
|
}
|
||
|
|
||
|
const amount = await Accounts.deleteMany(req.body.checkedaccounts).then(res => res.deletedCount);
|
||
|
|
||
|
return dynamicResponse(req, res, 200, 'message', {
|
||
|
'title': 'Success',
|
||
|
'message': `${req.body.delete_account ? 'Deleted' : 'Edited'} ${amount} accounts`,
|
||
|
'redirect': '/globalmanage/accounts.html'
|
||
|
});
|
||
|
|
||
|
}
|