refactor: use questList to calculate total quests and completed

This commit is contained in:
Chen, Tai-Lin committed 2023-12-21 17:58:52 +08:00
1 parent 3b68693177
commit b0e12b2027
2 files changed
+12 -58

No files matched your search

-55
View File
@@ -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([
{