diff --git a/src/controllers/chest.controller.ts b/src/controllers/chest.controller.ts index d00856a..db76ee6 100644 --- a/src/controllers/chest.controller.ts +++ b/src/controllers/chest.controller.ts @@ -66,12 +66,23 @@ class BoxController extends BaseController { @role(ROLE_ANON) @router('post /api/chest/enhance/list') async enhanceList(req) { - let { chestId, chestid } = req.params + let { chestId, chestid, code } = req.params chestid = chestId || chestid - if (!isObjectIdString(chestid)) { - throw new ZError(11, 'must provide valid chestid') + if (code && !isValidShareCode(code)) { + throw new ZError(11, 'invalid share code') + } + if (chestid && !isObjectIdString(chestid)) { + throw new ZError(11, 'invalid chest id') + } + if (!code && !chestId) { + throw new ZError(11, 'must provide share code or chest id') + } + let chest: any + if (chestId) { + chest = await ActivityChest.findById(chestId) + } else { + chest = await ActivityChest.findOne({ shareCode: code }) } - const chest = await ActivityChest.findById(chestid) if (!chest) { throw new ZError(12, 'chest not found') }