mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
refactor: use questList to calculate total quests and completed
This commit is contained in:
1 parent
3b68693177
commit
b0e12b2027
2 files changed
+12
-58
No files matched your search
@@ -2,61 +2,6 @@
|
||||
/* eslint-disable func-names */
|
||||
import { UserProfile } from '@linux-odyssey/models'
|
||||
|
||||
export function totalQuests() {
|
||||
return UserProfile.aggregate([
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
progress: { $objectToArray: '$progress' },
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$progress',
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
totalCount: { $sum: 1 },
|
||||
},
|
||||
},
|
||||
]).then((results) => {
|
||||
if (results.length === 0) {
|
||||
throw new Error('No documents found')
|
||||
}
|
||||
return results[0].totalCount
|
||||
})
|
||||
}
|
||||
|
||||
export function totalCompleted() {
|
||||
return UserProfile.aggregate([
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
progress: { $objectToArray: '$progress' },
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$progress',
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
'progress.v.completed': true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
totalCount: { $sum: 1 },
|
||||
},
|
||||
},
|
||||
]).then((results) => {
|
||||
if (results.length === 0) {
|
||||
throw new Error('No documents found')
|
||||
}
|
||||
return results[0].totalCount
|
||||
})
|
||||
}
|
||||
|
||||
export function questList() {
|
||||
return UserProfile.aggregate([
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user