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

+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 {