mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
Merge branch 'main' into quest
This commit is contained in:
18 files changed
+315
-29
No files matched your search
@@ -22,3 +22,46 @@ export async function createUser(username, email, { password, socialLogin }) {
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
export function leaderboard() {
|
||||
return UserProfile.aggregate([
|
||||
{
|
||||
$project: {
|
||||
user: true, // Include the user field in the projection
|
||||
completedQuests: {
|
||||
$map: {
|
||||
input: {
|
||||
$filter: {
|
||||
input: { $objectToArray: '$progress' }, // Convert the progress map to an array
|
||||
as: 'prog',
|
||||
cond: { $eq: ['$$prog.v.completed', true] }, // Filter for completed quests
|
||||
},
|
||||
},
|
||||
as: 'completedProg',
|
||||
in: '$$completedProg.k', // Extract the quest IDs
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
score: { $size: '$completedQuests' }, // Calculate the size of the completedQuests array
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
score: { $gt: 0 }, // Filter out users who haven't completed any quests
|
||||
},
|
||||
},
|
||||
{ $sort: { score: -1 } },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'users',
|
||||
localField: 'user',
|
||||
foreignField: '_id',
|
||||
as: 'user',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$user' },
|
||||
])
|
||||
}
|
||||
Reference in new issue
Block a user