mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: add sorting order
This commit is contained in:
1 parent
1b94ae75ca
commit
c6733814ba
3 files changed
+39
-7
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { Session, User } from '@linux-odyssey/models'
|
||||
import mongoose from 'mongoose'
|
||||
import { Session, User } from '@linux-odyssey/models'
|
||||
|
||||
function loginMethods(user) {
|
||||
const methods = []
|
||||
@@ -12,10 +12,14 @@ export function userCount() {
|
||||
return User.find().count()
|
||||
}
|
||||
|
||||
export async function userList({ nextKey, itemsPerPage }) {
|
||||
const key = new mongoose.Types.ObjectId(nextKey)
|
||||
// const matchStage = nextKey ? { user: { $gt: key } } : {}
|
||||
const matchStage = nextKey ? { user: { $gt: key } } : {}
|
||||
export async function userList({ nextKey, itemsPerPage, order }) {
|
||||
console.log(order)
|
||||
let matchStage = {}
|
||||
if (nextKey) {
|
||||
const key = new mongoose.Types.ObjectId(nextKey)
|
||||
matchStage = { user: order.matchStage(key) }
|
||||
}
|
||||
console.log(matchStage)
|
||||
const users = await Session.aggregate([
|
||||
{
|
||||
$match: matchStage,
|
||||
@@ -36,7 +40,7 @@ export async function userList({ nextKey, itemsPerPage }) {
|
||||
},
|
||||
},
|
||||
{ $unwind: '$userData' },
|
||||
{ $sort: { 'userData._id': 1 } },
|
||||
{ $sort: { 'userData._id': order.order() } },
|
||||
{ $limit: itemsPerPage },
|
||||
])
|
||||
|
||||
|
||||
Reference in new issue
Block a user