diff --git a/src/controllers/chest.controller.ts b/src/controllers/chest.controller.ts index 3ecc530..1b2c5f0 100644 --- a/src/controllers/chest.controller.ts +++ b/src/controllers/chest.controller.ts @@ -20,9 +20,11 @@ class BoxController extends BaseController { @router('get /api/chest/list') async chestList(req) { const user = req.user - const openRecord = await ChestRecord.find({ from: user.address.toLowerCase() }) - const chestIds = openRecord.map(record => record.chestId) - const chestSet = new Set(chestIds) + const openRecords = await ChestRecord.find({ from: user.address.toLowerCase() }) + const chestSet = new Set() + openRecords.forEach(record => { + chestSet.add(record.chestId) + }) const chests = await ActivityChest.find({ activity: user.activity, user: user.id, @@ -30,9 +32,18 @@ class BoxController extends BaseController { }).sort({ level: -1, }) + for (let chest of chests) { + // TODO:: 待规则确定后, 将符合条件的锁定的箱子解锁 + if (chest.status === 0) { + if (user.allTaskFinished()) { + chest.status = 1 + await chest.save() + } + } + } const results = chests.map(chest => chest.toJson()) for (let result of results) { - if (chestSet.has(result.id)) { + if (result.stat > 0 && chestSet.has(result.id)) { result.stat = 2 } }