diff --git a/docs/api.md b/docs/api.md index 993ac3b..a698af9 100644 --- a/docs/api.md +++ b/docs/api.md @@ -356,6 +356,12 @@ | -------- | -------------------------------------- | | accountid | 帐号id | +> POST参数 + + +| 字段 | 说明 | +| -------- | -------------------------------------- | +| type |物品类型, 不传的话就获取背包中所有物品 | 3. Response: JSON diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index cba39c8..183d887 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -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 {} } diff --git a/src/models/BagItem.ts b/src/models/BagItem.ts index 3c076e7..4ac4ca8 100644 --- a/src/models/BagItem.ts +++ b/src/models/BagItem.ts @@ -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, 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()