2023-05-25 17:23:31 +03:00
|
|
|
const { UserModel, ThreadModel, MessageModel, CategoryModel } = require("../models")
|
2022-03-21 23:53:22 +03:00
|
|
|
const { Router } = require("express");
|
|
|
|
const app = Router();
|
|
|
|
|
2022-04-06 21:14:46 +03:00
|
|
|
app.get("/", async (req, res) => {
|
2022-08-26 16:27:29 +03:00
|
|
|
|
2023-05-26 12:02:46 +03:00
|
|
|
const [
|
|
|
|
categories, users, threads, messages, newestMember, newestMessages, onlineUserCount, onlineUsers
|
|
|
|
] = await Promise.all([
|
|
|
|
CategoryModel.count(),
|
|
|
|
UserModel.count({ deleted: false }),
|
|
|
|
ThreadModel.count({ state: "OPEN" }),
|
|
|
|
MessageModel.count({ deleted: false }),
|
|
|
|
UserModel.findOne({ deleted: false }, "name id").sort({ time: -1 }),
|
|
|
|
MessageModel.find({ deleted: false }).sort({ time: -1 }).limit(10),
|
|
|
|
UserModel.count({ deleted: false, lastSeen: { $gt: Date.now() - 1000 * 60 * 5 } }),
|
|
|
|
UserModel.find({ deleted: false, hideLastSeen: false, lastSeen: { $gt: Date.now() - 1000 * 60 * 5 } }, "name id")
|
|
|
|
])
|
2022-03-21 23:53:22 +03:00
|
|
|
|
2023-05-26 12:02:46 +03:00
|
|
|
|
|
|
|
res.reply("index", {
|
|
|
|
categories, users, threads, messages,
|
|
|
|
newestMember, newestMessages, onlineUserCount, onlineUsers
|
|
|
|
});
|
2022-03-21 23:53:22 +03:00
|
|
|
|
2023-05-25 16:15:50 +03:00
|
|
|
});
|
2022-09-23 23:10:13 +03:00
|
|
|
|
2022-03-21 23:53:22 +03:00
|
|
|
module.exports = app;
|