reference #258 bugfix, global report count would only show if they owned or modded a board, which obviously isnt correct

merge-requests/208/head
Thomas Lynch 4 years ago
parent 3ed44ffa2d
commit 0cc762ad5d
  1. 39
      models/pages/account.js

@ -4,27 +4,28 @@ const Posts = require(__dirname+'/../../db/posts.js');
module.exports = async (req, res, next) => { module.exports = async (req, res, next) => {
const userBoards = res.locals.user.ownedBoards.concat(res.locals.user.modBoards); let boardReportCountMap = {}; //map of board to open report count
let boardReportCountMap = {}; let globalReportCount = 0; //number of open global reports
let globalReportCount = 0;
if (userBoards.length > 0) { let boardReportCounts;
let boardReportCounts; try {
try { const userBoards = res.locals.user.ownedBoards.concat(res.locals.user.modBoards);
([boardReportCounts, globalReportCount] = await Promise.all([ ([boardReportCounts, globalReportCount] = await Promise.all([
Posts.getBoardReportCounts(userBoards), //if user owns or mods any boards, get the open report count for them
res.locals.user.authLevel <= 1 ? Posts.getGlobalReportsCount() : 0 userBoards.length > 0 ? Posts.getBoardReportCounts(userBoards) : [],
])); //if user is global staff get the open global report count
} catch (err) { res.locals.user.authLevel <= 1 ? Posts.getGlobalReportsCount() : 0
return next(err) ]));
} } catch (err) {
return next(err)
}
if (boardReportCounts && boardReportCounts.length > 0) { if (boardReportCounts && boardReportCounts.length > 0) {
boardReportCountMap = boardReportCounts.reduce((acc, val) => { //make the aggregate array from mongodb to a map
acc[val._id] = val.count; boardReportCountMap = boardReportCounts.reduce((acc, val) => {
return acc; acc[val._id] = val.count;
}, boardReportCountMap); return acc;
} }, boardReportCountMap);
} }
res res

Loading…
Cancel
Save