mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-23 04:10:40 +03:00
Akif9748
4be2069587
Co-authored-by: Sapphire1525 <Sapphire1525@users.noreply.github.com> Co-authored-by: inoaa79 <inoaa79@users.noreply.github.com>
28 lines
No EOL
851 B
JavaScript
28 lines
No EOL
851 B
JavaScript
const { Router } = require("express");
|
|
const app = Router();
|
|
|
|
const { UserModel, MessageModel, ThreadModel } = require("../models");
|
|
|
|
app.get("/", async ({ user }, res) => {
|
|
const users = await UserModel.find(user?.admin ? {} : { deleted: false });
|
|
return res.render("users", { users, user })
|
|
|
|
});
|
|
|
|
app.get("/:id", async (req, res) => {
|
|
const user = req.user
|
|
const { id = null } = req.params;
|
|
const member = await UserModel.get(id);
|
|
|
|
|
|
if (member && (user?.admin || !member.deleted)) {
|
|
|
|
const message = await MessageModel.count({ "author.id": id });// this place was having problem. fixed
|
|
const thread = await ThreadModel.count({ "author.id": id });
|
|
res.render("user", { user, member, counts: { message, thread } })
|
|
}
|
|
else res.error(404, "We have not got this user.");
|
|
|
|
});
|
|
|
|
module.exports = app; |