diff --git a/src/controllers/voucher.controller.ts b/src/controllers/voucher.controller.ts index 7df696e..b130374 100644 --- a/src/controllers/voucher.controller.ts +++ b/src/controllers/voucher.controller.ts @@ -97,10 +97,16 @@ class VoucherController extends BaseController { if (!id || !isValidVoucherCode(id)) { throw new ZError(10, 'invild voucher code') } - const record = await VoucherRecord.findOne({ code: id, status: VoucherStatusEnum.NORMAL }) + const record = await VoucherRecord.findOne({ code: id }) if (!record) { throw new ZError(11, 'voucher not found') } + if (record.status === VoucherStatusEnum.USED) { + throw new ZError(12, 'voucher already used') + } + if (record.status !== VoucherStatusEnum.NORMAL) { + throw new ZError(11, 'voucher not found') + } record.status = VoucherStatusEnum.USED record.user = user.id if (record.bonusScores.length > 0) {