优化优惠券相关接口

This commit is contained in:
CounterFire2023 2024-04-17 11:50:58 +08:00
parent 17961ce320
commit f7b28b80b8
5 changed files with 20 additions and 14 deletions

View File

@ -51,7 +51,7 @@
},{
"id": "e2far3lj30vwcpe0mf8",
"task": "DiscordJoin",
"title": "Join Discord",
"title": "Join Counter Fire Discord",
"type": 1,
"desc": "Join Counter Fires official Discord server",
"category": "Social Tasks",
@ -66,7 +66,7 @@
}, {
"id": "e2fuah0j30vwcpe0my7",
"task": "TwitterRetweet",
"title": "Retweet on X",
"title": "Retweet a tweet",
"type": 1,
"desc": "Retweet specific tweets",
"category": "Social Tasks",
@ -81,7 +81,7 @@
}, {
"id": "e2fuah0j30vwcpe0my9",
"task": "TwitterLike",
"title": "Like the tweets on X",
"title": "Like a tweet",
"type": 1,
"desc": "Like specific tweets",
"category": "Social Tasks",

View File

@ -30,7 +30,7 @@
"fastify-xml-body-parser": "^2.2.0",
"mongodb-extended-json": "^1.11.1",
"mongoose": "8.2.3",
"nanoid": "^5.0.7",
"nanoid": "^3.1.23",
"node-schedule": "^2.0.0",
"siwe": "^2.1.4",
"tracer": "^1.1.6",

View File

@ -1,9 +1,9 @@
import { isValidShareCode, isValidVoucherCode } from 'common/Utils'
import { isValidVoucherCode } from 'common/Utils'
import logger from 'logger/logger'
import { ChestStatusEnum } from 'models/ActivityChest'
import { SourceEnum, VoucherRecord, VoucherStatusEnum } from 'models/VoucherRecord'
import { generateNewChest } from 'services/game.svr'
import { SyncLocker, BaseController, router, role, ROLE_ANON, ZError } from 'zutils'
import { SyncLocker, BaseController, router, ZError } from 'zutils'
import { customAlphabet } from 'nanoid'
import { BASE52_ALPHABET } from 'common/Constants'
/**
@ -13,7 +13,7 @@ class VoucherController extends BaseController {
@router('post /api/voucher/generate')
async generateTestVoucher(req) {
logger.db('generate_test_voucher', req)
if (process.env.NODE_ENV !== 'development') {
if (process.env.NODE_ENV === 'production') {
throw new ZError(10, 'only support in development')
}
const user = req.user
@ -25,6 +25,12 @@ class VoucherController extends BaseController {
const nanoid = customAlphabet(BASE52_ALPHABET, 8)
for (let i = 0; i < num; i++) {
let code = 'test' + nanoid()
// check if code exists
let record = await VoucherRecord.findOne({ code })
if (record) {
i--
continue
}
let voucher = new VoucherRecord({
batch: 'test',
code,
@ -38,7 +44,7 @@ class VoucherController extends BaseController {
creator: user.id,
})
await voucher.save()
results.push(voucher.id)
results.push(voucher.code)
}
return results
}

View File

@ -23,12 +23,12 @@ export enum SourceEnum {
@index({ user: 1, activity: 1 }, { unique: false })
@index({ code: 1, activity: 1 }, { unique: true })
@modelOptions({
schemaOptions: { collection: 'activity_box', timestamps: true },
schemaOptions: { collection: 'voucher_record', timestamps: true },
options: { allowMixed: Severity.ALLOW },
})
export class VoucherRecordClass extends BaseModule {
@prop()
public batch: number
public batch: string
@prop()
public code: string
// 0 锁定, 1 未发放 2 已发放,待使用 9 已兑换

View File

@ -3317,10 +3317,10 @@ nano-json-stream-parser@^0.1.2:
resolved "https://registry.npmjs.org/nano-json-stream-parser/-/nano-json-stream-parser-0.1.2.tgz"
integrity sha512-9MqxMH/BSJC7dnLsEMPyfN5Dvoo49IsPFYMcHw3Bcfc2kN0lpHRBSzlMSVx4HGyJ7s9B31CyBTVehWJoQ8Ctew==
nanoid@^5.0.7:
version "5.0.7"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.7.tgz#6452e8c5a816861fd9d2b898399f7e5fd6944cc6"
integrity sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ==
nanoid@^3.1.23:
version "3.3.7"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8"
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==
natural-compare@^1.4.0:
version "1.4.0"