feat: show analytics data page by page

This commit is contained in:
Chen, Tai-Lin committed 2023-12-10 03:21:30 +08:00
1 parent 9200336b49
commit ac31ca8659
9 files changed
+87 -12

No files matched your search

+5 -1
View File
@@ -1,7 +1,9 @@
import { Command } from '@linux-odyssey/models'
// eslint-disable-next-line import/prefer-default-export
export async function errorCommands() {
export async function errorCommands(pageNumber, itemsPerPage) {
const skipAmount = (pageNumber - 1) * itemsPerPage
const commands = await Command.find({
$and: [
{ error: { $exists: true } },
@@ -13,6 +15,8 @@ export async function errorCommands() {
path: 'session',
populate: { path: 'user' },
})
.skip(skipAmount)
.limit(itemsPerPage)
.exec()
return commands.map(({ command, error, createdAt, session }) => {
const { user, quest } = session
+5 -1
View File
@@ -30,7 +30,9 @@ function formatTime(time) {
return `${hours}h ${minutes % 60}m ${seconds % 60}s`
}
export async function sessionList() {
export async function sessionList(pageNumber, itemsPerPage) {
const skipAmount = (pageNumber - 1) * itemsPerPage
const sessions = await Session.aggregate([
{
$lookup: {
@@ -50,6 +52,8 @@ export async function sessionList() {
},
},
])
.skip(skipAmount)
.limit(itemsPerPage)
return sessions.map(
({
_id,
+6 -1
View File
@@ -11,7 +11,9 @@ export function userCount() {
return User.find().count()
}
export async function userList() {
export async function userList(pageNumber, itemsPerPage) {
const skipAmount = (pageNumber - 1) * itemsPerPage
const users = await Session.aggregate([
{
$group: {
@@ -30,7 +32,10 @@ export async function userList() {
},
{ $unwind: '$userData' },
{ $sort: { 'userData.createdAt': 1 } },
{ $skip: skipAmount },
{ $limit: itemsPerPage },
])
return users.map(({ userData, count, lastActivityAt }) => {
const { username, email, createdAt } = userData
return {