From 086f2b571351734b740ee9314320f228418d48c3 Mon Sep 17 00:00:00 2001 From: Akif9748 Date: Tue, 9 Aug 2022 19:48:10 +0300 Subject: [PATCH] 2 todo did. --- README.md | 2 -- routes/threads.js | 2 +- routes/users.js | 7 +++---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d13c218..54c92ee 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,7 @@ And, you can learn about API in `util/APIDOCS.md`. - `/errors/error` will change, better error page. - Redirect query. - middleware for timeouts -- DELETED USERS: USERLIST - Will fix API -- if admin you van see deleted messages. ## Roadmap ### User diff --git a/routes/threads.js b/routes/threads.js index 07d40bd..2b6179f 100644 --- a/routes/threads.js +++ b/routes/threads.js @@ -33,7 +33,7 @@ app.get("/:id", async (req, res) => { const messages = await Promise.all(thread.messages.map(async id => { const message = await MessageModel.get(id) - return (message.deleted || !message) ? null : message; + return (user.admin || !message?.deleted) ? message : null; })); res.render("thread", { thread, messages, user }) diff --git a/routes/users.js b/routes/users.js index bed4257..254ffa7 100644 --- a/routes/users.js +++ b/routes/users.js @@ -4,9 +4,8 @@ const app = Router(); const error = require("../errors/error"); const { UserModel, MessageModel, ThreadModel } = require("../models"); -app.get("/", async (req, res) => { - const user = req.user - const users = await UserModel.find({ deleted: false }); +app.get("/", async ({ user }, res) => { + const users = await UserModel.find(user.admin ? {} : { deleted: false }); return res.render("users", { users, user }) }); @@ -21,7 +20,7 @@ app.get("/:id", async (req, res) => { const message = await MessageModel.count({ authorID: id }); const thread = await ThreadModel.count({ authorID: id }); - res.render("user", { user, member, counts:{ message, thread } }) + res.render("user", { user, member, counts: { message, thread } }) } else error(res, 404, "We have not got this user.");