akf-forum/src/routes/.js

31 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-08-27 20:22:28 +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
const [
2023-08-27 20:22:28 +03:00
categories, users, threads, messages, newestMember, newestMessages, newestThreads, onlineMemberCount, onlineMembers
] = await Promise.all([
CategoryModel.countDocuments(),
UserModel.countDocuments({ deleted: false }),
ThreadModel.countDocuments({ state: "OPEN" }),
MessageModel.countDocuments({ deleted: false }),
UserModel.findOne({ deleted: false }, "name id").sort({ time: -1 }),
MessageModel.find({ deleted: false }).sort({ time: -1 }).limit(10),
ThreadModel.find({ state: "OPEN" }).sort({ time: -1 }).limit(10),
UserModel.countDocuments({ deleted: false, lastSeen: { $gt: Date.now() - 1000 * 60 * 5 } }),
UserModel.find({ deleted: false, hideLastSeen: false, lastSeen: { $gt: Date.now() - 1000 * 60 * 5 } }, "name id")
2023-08-27 20:22:28 +03:00
]),
onlineTotal = req.app.onlines.size,
onlineGuests = onlineTotal - onlineMemberCount;
res.reply("index", {
categories, users, threads, messages,
newestMember, newestMessages, newestThreads,
2023-08-27 20:22:28 +03:00
onlineMemberCount, onlineMembers, onlineGuests, onlineTotal
});
2022-03-21 23:53:22 +03:00
2023-05-25 16:15:50 +03:00
});
2022-03-21 23:53:22 +03:00
module.exports = app;