32 lines
1007 B
TypeScript
32 lines
1007 B
TypeScript
import BaseController from '../common/base.controller'
|
|
import { router } from '../decorators/router'
|
|
import { BaseConst } from '../constants/BaseConst'
|
|
import { ZError } from '../common/ZError'
|
|
import { MatchCfg } from '../cfg/parsers/MatchCfg'
|
|
import { BagItem } from '../models/BagItem'
|
|
|
|
export default class MatchController extends BaseController {
|
|
|
|
@router('post /svr/:accountid/beginmatch')
|
|
async beginMatch(req: any) {
|
|
let {accountid, matchid} = req.params
|
|
let cfg: MatchCfg = global.$cfg.get(BaseConst.MATCH).get(matchid << 0)
|
|
if (!cfg || !cfg.consume) {
|
|
throw new ZError(10, 'match not found')
|
|
}
|
|
let itemObj = cfg.consume.split(':')
|
|
let itemid: number = parseInt(itemObj[0])
|
|
let count: number = parseInt(itemObj[1])
|
|
let record = await BagItem.findOne({
|
|
accountid,
|
|
itemid
|
|
})
|
|
if (!record || record.count < count) {
|
|
throw new ZError(11, 'not enough ticket')
|
|
}
|
|
record.count -= count
|
|
await record.save()
|
|
return {}
|
|
}
|
|
}
|