mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
refactor: add Pagination class
This commit is contained in:
1 parent
19cd10ab7b
commit
68db16419d
9 files changed
+99
-89
No files matched your search
@@ -1,6 +1,5 @@
|
||||
/* eslint-disable object-shorthand */
|
||||
import { Desc } from '../constants.js'
|
||||
import { Command } from '@linux-odyssey/models'
|
||||
import { Desc } from '../models/pagination.js'
|
||||
import { errorCommands } from '../models/commands.js'
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
@@ -9,23 +8,7 @@ export async function commandListController(req, res) {
|
||||
const itemsPerPage = 100
|
||||
|
||||
try {
|
||||
// const totalCommands = await Command.countDocuments({
|
||||
// $and: [
|
||||
// { error: { $exists: true } },
|
||||
// { error: { $ne: null } },
|
||||
// { error: { $ne: '' } },
|
||||
// ],
|
||||
// })
|
||||
|
||||
// const maxPages = Math.ceil(totalCommands / itemsPerPage)
|
||||
|
||||
// const pageNumber = req.query
|
||||
|
||||
const payload = await errorCommands({
|
||||
nextKey,
|
||||
itemsPerPage,
|
||||
order: new Desc(),
|
||||
})
|
||||
const payload = await errorCommands(new Desc(itemsPerPage, nextKey))
|
||||
const newNextKey = payload[payload.length - 1]?._id
|
||||
|
||||
res.render('commands', { errorCommands: payload, nextKey: newNextKey })
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Desc } from '../constants.js'
|
||||
import { sessionCount, sessionList, sessionDetail } from '../models/sessions.js'
|
||||
import { Desc } from '../models/pagination.js'
|
||||
import { sessionList, sessionDetail } from '../models/sessions.js'
|
||||
|
||||
export async function sessionListController(req, res) {
|
||||
const { nextKey } = req.query
|
||||
@@ -9,11 +9,7 @@ export async function sessionListController(req, res) {
|
||||
// const totalSessions = await sessionCount()
|
||||
// const maxPages = Math.ceil(totalSessions / itemsPerPage)
|
||||
|
||||
const sessions = await sessionList({
|
||||
nextKey,
|
||||
itemsPerPage,
|
||||
order: new Desc(),
|
||||
})
|
||||
const sessions = await sessionList(new Desc(itemsPerPage, nextKey))
|
||||
const newNextKey = sessions[sessions.length - 1]?._id
|
||||
|
||||
res.render('sessions', { sessions, nextKey: newNextKey })
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import { Desc } from '../constants.js'
|
||||
import { userList, userCount } from '../models/users.js'
|
||||
import { Desc } from '../models/pagination.js'
|
||||
import { userList } from '../models/users.js'
|
||||
|
||||
export async function userListController(req, res) {
|
||||
const { nextKey } = req.query
|
||||
const itemsPerPage = 50
|
||||
|
||||
try {
|
||||
const users = await userList({
|
||||
nextKey,
|
||||
itemsPerPage,
|
||||
order: new Desc(),
|
||||
})
|
||||
const users = await userList(new Desc(itemsPerPage, nextKey))
|
||||
const newNextKey = users[users.length - 1]?._id
|
||||
|
||||
res.render('users', { users, nextKey: newNextKey })
|
||||
|
||||
Reference in new issue
Block a user