mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
feat: finish errorCommands pagination
This commit is contained in:
1 parent
8c634c8115
commit
bc0055781e
6 files changed
+59
-41
No files matched your search
@@ -1,11 +1,12 @@
|
||||
/* eslint-disable object-shorthand */
|
||||
import { Desc } from '../constants.js'
|
||||
import { Command } from '@linux-odyssey/models'
|
||||
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
|
||||
const itemsPerPage = 100
|
||||
|
||||
try {
|
||||
// const totalCommands = await Command.countDocuments({
|
||||
@@ -20,10 +21,14 @@ export async function commandListController(req, res) {
|
||||
|
||||
// const pageNumber = req.query
|
||||
|
||||
const payload = await errorCommands({ nextKey, itemsPerPage })
|
||||
const payload = await errorCommands({
|
||||
nextKey,
|
||||
itemsPerPage,
|
||||
order: new Desc(),
|
||||
})
|
||||
const newNextKey = payload[payload.length - 1]?._id
|
||||
|
||||
res.render('commands', { payload, nextKey: newNextKey })
|
||||
res.render('commands', { errorCommands: payload, nextKey: newNextKey })
|
||||
} catch (error) {
|
||||
res.status(500).send('Error fetching data')
|
||||
}
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
import { Desc } from '../constants.js'
|
||||
import { sessionCount, sessionList, sessionDetail } from '../models/sessions.js'
|
||||
|
||||
export async function sessionListController(req, res) {
|
||||
const { nextKey } = req.query
|
||||
const itemsPerPage = 100
|
||||
const itemsPerPage = 10
|
||||
|
||||
try {
|
||||
// const totalSessions = await sessionCount()
|
||||
// const maxPages = Math.ceil(totalSessions / itemsPerPage)
|
||||
|
||||
const sessions = await sessionList({ nextKey, itemsPerPage })
|
||||
const sessions = await sessionList({
|
||||
nextKey,
|
||||
itemsPerPage,
|
||||
order: new Desc(),
|
||||
})
|
||||
const newNextKey = sessions[sessions.length - 1]?._id
|
||||
|
||||
res.render('sessions', { sessions, nextKey: newNextKey })
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).send('Error fetching session data')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,6 @@ export async function userListController(req, res) {
|
||||
const itemsPerPage = 50
|
||||
|
||||
try {
|
||||
// const totalUsers = await userCount()
|
||||
// const maxPages = Math.ceil(totalUsers / itemsPerPage)
|
||||
|
||||
const users = await userList({
|
||||
nextKey,
|
||||
itemsPerPage,
|
||||
@@ -16,11 +13,7 @@ export async function userListController(req, res) {
|
||||
})
|
||||
const newNextKey = users[users.length - 1]?._id
|
||||
|
||||
res.render('users', {
|
||||
users,
|
||||
nextKey: newNextKey,
|
||||
// maxPages: Array.from({ length: maxPages }, (_, index) => index + 1),
|
||||
})
|
||||
res.render('users', { users, nextKey: newNextKey })
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
res.status(500).send('Error fetching user data')
|
||||
|
||||
Reference in new issue
Block a user