获取物品列表增加类型参数

This commit is contained in:
zhl 2021-01-21 19:41:07 +08:00
parent b2d32e8f62
commit feb768a810
3 changed files with 24 additions and 12 deletions

View File

@ -356,6 +356,12 @@
| -------- | -------------------------------------- |
| accountid | 帐号id |
> POST参数
| 字段 | 说明 |
| -------- | -------------------------------------- |
| type |物品类型, 不传的话就获取背包中所有物品 |
3. Response: JSON

View File

@ -102,8 +102,12 @@ export default class AccountController extends BaseController {
@router('post /api/:accountid/items')
async itemList(req: any) {
let { accountid } = req.params
let items = await BagItem.find({ accountid })
let { accountid, type } = req.params
let queryData: any = {accountid}
if (type != undefined) {
queryData.itemtype = type << 0
}
let items = await BagItem.find(queryData)
return items.map(o => o.toJson())
}
@ -140,6 +144,7 @@ export default class AccountController extends BaseController {
@router('post /api/:accountid/buyitem')
async buyItem(req: any) {
let {itemid, count} = req.params
return {}
}

View File

@ -1,6 +1,7 @@
import { dbconn } from '../decorators/dbconn'
import {
getModelForClass, index,
getModelForClass,
index,
modelOptions,
prop,
Severity
@ -15,11 +16,11 @@ import { DropItemCfg } from '../cfg/parsers/DropItemCfg'
import { ItemCardCfg } from '../cfg/parsers/ItemCardCfg'
export enum ItemType {
UNKNOW, // 未知
MONEY, // 杂物, 代币
BAG, // 礼包
CARD // 卡
UNKNOW = 0, // 未知
NORMAL = 1, // 杂物
BAG = 2, // 礼包
CARD = 3, // 卡
MONEY = 7 // 代币
}
/**
@ -43,14 +44,14 @@ interface BagItemClass extends Base<string>, TimeStamps {
}
@dbconn()
@index({accountid: 1, itemid: 1, itemtype: 1 }, {unique: true})
@index({accountid: 1, itemid: 1 }, {unique: true})
@index({ accountid: 1, itemid: 1, itemtype: 1 }, { unique: true })
@index({ accountid: 1, itemid: 1 }, { unique: true })
@modelOptions({
schemaOptions:
{ collection: 'bag_items', timestamps: true },
options: { allowMixed: Severity.ALLOW }
})
class BagItemClass extends FindOrCreate{
class BagItemClass extends FindOrCreate {
@prop()
public accountid: string
@ -63,7 +64,7 @@ class BagItemClass extends FindOrCreate{
@prop({ default: 0 })
public count: number
@prop({default: 0})
@prop({ default: 0 })
public position: number
@prop()