akf-forum/routes/get/users.js

33 lines
1,000 B
JavaScript
Raw Normal View History

2022-03-13 16:16:46 +03:00
const { User } = require("../../classes/index");
const db = require("quick.db");
const error = require("../../errors/error.js")
module.exports = (req, res) => {
if (!req.session.loggedin) return res.redirect('/login');
const user = new User().getId(req.session.userid)
const id = req.url.slice(7);
if (!id) {
2022-03-13 17:12:09 +03:00
const users = db.get("users").slice(0);
2022-03-13 16:16:46 +03:00
2022-03-13 17:12:09 +03:00
const links = users.filter(user=> !user.deleted).map(user => "/users/" + user.id)
2022-03-13 16:16:46 +03:00
return res.render("users", { users, links, user })
}
const member = new User().getId(id);
2022-03-13 17:12:09 +03:00
if (member && (user.admin || !member.deleted)) {
2022-03-13 16:16:46 +03:00
const message = db.get("messages").filter(message => message.author.id === Number(id)).length
const thread = db.get("threads").filter(thread => thread.author.id === Number(id)).length
const counts = { message, thread }
res.render("user", { user, member, counts })
}
else
error(res, 404, "We have not got this user.");
2022-02-26 21:12:54 +03:00
}