bug fix: 关注任务获取奖励报错

This commit is contained in:
CounterFire2023 2024-04-09 14:17:55 +08:00
parent bb28f444e1
commit fcffa0260a

View File

@ -32,12 +32,12 @@ export abstract class ITask {
if (!cfg.score) {
return
}
let claimAmount = task.data.claimAmount || 0
let claimAmount = task.data?.claimAmount || 0
let score = cfg.score
if (user.boost > 1 && Date.now() < user.boostExpire.getTime()) {
score = Math.floor(score * user.boost)
}
let finishAmount = cfg.repeat > 1 ? task.data.finishAmount || 0 : 1
let finishAmount = cfg.repeat > 1 ? task.data?.finishAmount || 0 : 1
for (let i = claimAmount; i < Math.min(cfg.repeat, finishAmount); i++) {
await updateRankScore({
user: user.id,
@ -52,7 +52,7 @@ export abstract class ITask {
})
claimAmount += 1
}
task.data.claimAmount = claimAmount
task.data = Object.assign(task.data || {}, { claimAmount })
task.markModified('data')
if ((cfg.repeat > 1 && claimAmount >= cfg.repeat) || (cfg.repeat === 1 && claimAmount >= 1)) {
task.status = TaskStatusEnum.CLAIMED