添加后台连接用的后端
This commit is contained in:
47
shared/db/Item.ts
Normal file
47
shared/db/Item.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop } from '@typegoose/typegoose';
|
||||
|
||||
|
||||
@index({ roleId: 1, hid: 1, eid: 1 })
|
||||
@index({ seqId: 1 })
|
||||
export default class Item extends BaseModel {
|
||||
@prop({ required: true })
|
||||
roleId: string; // 角色 id
|
||||
@prop({ required: true })
|
||||
roleName: string; // 角色名称
|
||||
|
||||
@prop({ required: true })
|
||||
itemid: number; // 道具 id
|
||||
@prop({ required: true })
|
||||
itemName: string; // 道具名称
|
||||
@prop({ required: true })
|
||||
seqId: number; // 道具表自增 id
|
||||
@prop({ required: true, default: 0 })
|
||||
count: number; // 道具数量
|
||||
|
||||
|
||||
public static async findbyRole(roleId: string, lean = true) {
|
||||
const items = await ItemModel.find({ roleId }).lean(lean);
|
||||
return items;
|
||||
}
|
||||
|
||||
public static async findbyItemid(itemid: number, roleId: string, lean = true) {
|
||||
const equips = await ItemModel.findOne({ itemid, roleId }).lean(lean);
|
||||
return equips;
|
||||
}
|
||||
|
||||
public static async changeItemCount(seqId: number, count: number, lean = true) {
|
||||
const equips = await ItemModel.findOneAndUpdate({ seqId }, {$inc:{count}}).lean(lean);
|
||||
return equips;
|
||||
}
|
||||
|
||||
public static async createItem(itemInfo: {roleId: string, roleName: string, itemid: number, seqId: number, itemName: string, count: number}, lean = true) {
|
||||
const doc = new ItemModel();
|
||||
const update = Object.assign(itemInfo, doc.toJSON());
|
||||
const item = await ItemModel.findOneAndUpdate({ seqId: itemInfo.seqId }, update, {upsert: true, new: true}).lean(lean);
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const ItemModel = getModelForClass(Item);
|
||||
Reference in New Issue
Block a user