2022-03-13 16:06:25 +03:00
|
|
|
const { User } = require("../../classes/index");
|
2022-02-26 21:12:54 +03:00
|
|
|
const db = require("quick.db");
|
|
|
|
const error = require("../../errors/error.js")
|
|
|
|
|
2022-03-13 16:06:25 +03:00
|
|
|
module.exports = (req, res) => {
|
2022-02-26 21:12:54 +03:00
|
|
|
if (!req.session.loggedin) return res.redirect('/login');
|
|
|
|
const user = new User().getId(req.session.userid)
|
|
|
|
|
|
|
|
const id = req.url.slice(7);
|
|
|
|
|
|
|
|
if (!id) {
|
|
|
|
|
|
|
|
const users = db.get("users").slice(0, 10);
|
|
|
|
|
|
|
|
const links = users.map(user => "/users/" + user.id)
|
|
|
|
return res.render("users", { users, links, user })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const member = new User().getId(id);
|
|
|
|
|
|
|
|
|
2022-03-13 16:06:25 +03:00
|
|
|
if (member) {
|
|
|
|
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 })
|
|
|
|
}
|
2022-02-26 21:12:54 +03:00
|
|
|
else
|
|
|
|
error(res, 404, "We have not got this user.");
|
|
|
|
|
|
|
|
}
|