mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: add order to pagination
This commit is contained in:
1 parent
68db16419d
commit
fa36b63fbe
8 files changed
+85
-50
No files matched your search
@@ -1,18 +1,21 @@
|
||||
/* eslint-disable object-shorthand */
|
||||
import { Desc } from '../models/pagination.js'
|
||||
import Pagination from '../models/pagination.js'
|
||||
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 { nextKey, order } = req.query
|
||||
const itemsPerPage = 100
|
||||
|
||||
try {
|
||||
const payload = await errorCommands(new Desc(itemsPerPage, nextKey))
|
||||
const payload = await errorCommands(
|
||||
new Pagination(order, itemsPerPage, nextKey)
|
||||
)
|
||||
const newNextKey = payload[payload.length - 1]?._id
|
||||
|
||||
res.render('commands', { errorCommands: payload, nextKey: newNextKey })
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
res.status(500).send('Error fetching data')
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
import { Desc } from '../models/pagination.js'
|
||||
import Pagination from '../models/pagination.js'
|
||||
import { sessionList, sessionDetail } from '../models/sessions.js'
|
||||
|
||||
export async function sessionListController(req, res) {
|
||||
const { nextKey } = req.query
|
||||
const { nextKey, order } = req.query
|
||||
const itemsPerPage = 50
|
||||
|
||||
try {
|
||||
// const totalSessions = await sessionCount()
|
||||
// const maxPages = Math.ceil(totalSessions / itemsPerPage)
|
||||
|
||||
const sessions = await sessionList(new Desc(itemsPerPage, nextKey))
|
||||
const sessions = await sessionList(
|
||||
new Pagination(order, itemsPerPage, nextKey)
|
||||
)
|
||||
const newNextKey = sessions[sessions.length - 1]?._id
|
||||
|
||||
res.render('sessions', { sessions, nextKey: newNextKey })
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Desc } from '../models/pagination.js'
|
||||
import Pagination from '../models/pagination.js'
|
||||
import { userList } from '../models/users.js'
|
||||
|
||||
export async function userListController(req, res) {
|
||||
const { nextKey } = req.query
|
||||
const { nextKey, order } = req.query
|
||||
const itemsPerPage = 50
|
||||
|
||||
try {
|
||||
const users = await userList(new Desc(itemsPerPage, nextKey))
|
||||
const users = await userList(new Pagination(order, itemsPerPage, nextKey))
|
||||
const newNextKey = users[users.length - 1]?._id
|
||||
|
||||
res.render('users', { users, nextKey: newNextKey })
|
||||
|
||||
Reference in new issue
Block a user