修改使用物品的接口
This commit is contained in:
parent
a1156888ac
commit
d063d16eac
@ -6,7 +6,7 @@ import { Card } from '../models/subdoc/Card'
|
||||
import { BaseConst } from '../constants/BaseConst'
|
||||
import { Hero } from '../models/subdoc/Hero'
|
||||
import { CardGroup } from '../models/CardGroup'
|
||||
import { BagItem } from '../models/BagItem'
|
||||
import { BagItem, ItemType } from '../models/BagItem'
|
||||
|
||||
export default class AccountController extends BaseController {
|
||||
@role('anon')
|
||||
@ -111,9 +111,28 @@ export default class AccountController extends BaseController {
|
||||
|
||||
@router('post /api/:accountid/useitem')
|
||||
async userItem(req: any) {
|
||||
let {accountid, items} = req.params;
|
||||
|
||||
return {}
|
||||
let { accountid, itemid, count } = req.params
|
||||
let record = await BagItem.findOne({accountid, itemid, itemtype: ItemType.UNKNOW})
|
||||
if (!record) {
|
||||
throw new ZError(11, 'item not found')
|
||||
}
|
||||
if (record.count < count) {
|
||||
throw new ZError(12, 'not enough item')
|
||||
}
|
||||
record.count -= count
|
||||
//TODO:: 根据使用逻辑获取真实的物品id
|
||||
let data = [{ itemid: 10001, itemnum: 1 }]
|
||||
for (let obj of data) {
|
||||
let item = (await BagItem.findOrCreate({
|
||||
accountid,
|
||||
itemid: obj.itemid,
|
||||
itemtype: ItemType.UNKNOW
|
||||
})).doc
|
||||
item.count += obj.itemnum
|
||||
await item.save()
|
||||
}
|
||||
await record.save()
|
||||
return data
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,9 +15,11 @@ export default class MailController extends BaseController {
|
||||
}
|
||||
if (data.attachments && data.attachments.length > 0) {
|
||||
for (let obj of data.attachments) {
|
||||
let item = (await BagItem.findOrCreate({accountid,
|
||||
let item = (await BagItem.findOrCreate({
|
||||
accountid,
|
||||
itemid: obj.itemid,
|
||||
itemtype: ItemType.UNKNOW })).doc
|
||||
itemtype: ItemType.UNKNOW
|
||||
})).doc
|
||||
item.count += obj.itemnum
|
||||
await item.save()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user