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. 13
      models/pages/account.js

@ -4,15 +4,16 @@ 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
userBoards.length > 0 ? Posts.getBoardReportCounts(userBoards) : [],
//if user is global staff get the open global report count
res.locals.user.authLevel <= 1 ? Posts.getGlobalReportsCount() : 0 res.locals.user.authLevel <= 1 ? Posts.getGlobalReportsCount() : 0
])); ]));
} catch (err) { } catch (err) {
@ -20,12 +21,12 @@ module.exports = async (req, res, next) => {
} }
if (boardReportCounts && boardReportCounts.length > 0) { if (boardReportCounts && boardReportCounts.length > 0) {
//make the aggregate array from mongodb to a map
boardReportCountMap = boardReportCounts.reduce((acc, val) => { boardReportCountMap = boardReportCounts.reduce((acc, val) => {
acc[val._id] = val.count; acc[val._id] = val.count;
return acc; return acc;
}, boardReportCountMap); }, boardReportCountMap);
} }
}
res res
.set('Cache-Control', 'private, max-age=5') .set('Cache-Control', 'private, max-age=5')

Loading…
Cancel
Save