wip: models/commands analytics

This commit is contained in:
Chen, Tai-Lin committed 2023-12-20 15:05:10 +08:00
1 parent ceb9416fab
commit 8c634c8115
7 files changed
+52 -40

No files matched your search

+15 -14
View File
@@ -4,25 +4,26 @@ import { errorCommands } from '../models/commands.js'
// eslint-disable-next-line import/prefer-default-export
export async function commandListController(req, res) {
const { nextKey } = req.query
const itemsPerPage = 250
try {
const totalCommands = await Command.countDocuments({
$and: [
{ error: { $exists: true } },
{ error: { $ne: null } },
{ error: { $ne: '' } },
],
})
// const totalCommands = await Command.countDocuments({
// $and: [
// { error: { $exists: true } },
// { error: { $ne: null } },
// { error: { $ne: '' } },
// ],
// })
const maxPages = Math.ceil(totalCommands / itemsPerPage)
// const maxPages = Math.ceil(totalCommands / itemsPerPage)
const pageNumber = req.query.page || 1
const payload = {
errorCommands: await errorCommands(pageNumber, itemsPerPage),
pages: Array.from({ length: maxPages }, (_, index) => index + 1),
}
res.render('commands', payload)
// const pageNumber = req.query
const payload = await errorCommands({ nextKey, itemsPerPage })
const newNextKey = payload[payload.length - 1]?._id
res.render('commands', { payload, nextKey: newNextKey })
} catch (error) {
res.status(500).send('Error fetching data')
}
@@ -1,18 +1,17 @@
import { sessionCount, sessionList, sessionDetail } from '../models/sessions.js'
export async function sessionListController(req, res) {
const pageNumber = req.query.page || 1
const { nextKey } = req.query
const itemsPerPage = 100
try {
const totalSessions = await sessionCount()
const maxPages = Math.ceil(totalSessions / itemsPerPage)
// const totalSessions = await sessionCount()
// const maxPages = Math.ceil(totalSessions / itemsPerPage)
const sessions = await sessionList(pageNumber, itemsPerPage)
const sessions = await sessionList({ nextKey, itemsPerPage })
const newNextKey = sessions[sessions.length - 1]?._id
const pages = Array.from({ length: maxPages }, (_, index) => index + 1)
res.render('sessions', { sessions, pages })
res.render('sessions', { sessions, nextKey: newNextKey })
} catch (error) {
res.status(500).send('Error fetching session data')
}