mirror of https://gitgud.io/fatchan/jschan.git
reference #258 show open reports on account page after a very subtle hint from https://fatchan.org/t/manage/thread/1.html#346
parent
b8ce46719a
commit
3ed44ffa2d
3 changed files with 63 additions and 0 deletions
@ -1,12 +1,39 @@ |
||||
'use strict'; |
||||
|
||||
const Posts = require(__dirname+'/../../db/posts.js'); |
||||
|
||||
module.exports = async (req, res, next) => { |
||||
|
||||
const userBoards = res.locals.user.ownedBoards.concat(res.locals.user.modBoards); |
||||
let boardReportCountMap = {}; |
||||
let globalReportCount = 0; |
||||
|
||||
if (userBoards.length > 0) { |
||||
let boardReportCounts; |
||||
try { |
||||
([boardReportCounts, globalReportCount] = await Promise.all([ |
||||
Posts.getBoardReportCounts(userBoards), |
||||
res.locals.user.authLevel <= 1 ? Posts.getGlobalReportsCount() : 0 |
||||
])); |
||||
} catch (err) { |
||||
return next(err) |
||||
} |
||||
|
||||
if (boardReportCounts && boardReportCounts.length > 0) { |
||||
boardReportCountMap = boardReportCounts.reduce((acc, val) => { |
||||
acc[val._id] = val.count; |
||||
return acc; |
||||
}, boardReportCountMap); |
||||
} |
||||
} |
||||
|
||||
res |
||||
.set('Cache-Control', 'private, max-age=5') |
||||
.render('account', { |
||||
csrf: req.csrfToken(), |
||||
user: res.locals.user, |
||||
boardReportCountMap, |
||||
globalReportCount, |
||||
}); |
||||
|
||||
} |
||||
|
Loading…
Reference in new issue