设置modelOptions
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
|
||||
@index({ roleId: 1, id: 1 })
|
||||
@index({ seqId: 1 })
|
||||
@modelOptions({schemaOptions: {id: false}})
|
||||
export default class Item extends BaseModel {
|
||||
@prop({ required: true, default: '' })
|
||||
roleId: string; // 角色 id
|
||||
@@ -44,7 +45,7 @@ export default class Item extends BaseModel {
|
||||
public static async increaseItem(roleId: string, id: number, count: number, itemInfo: {roleId: string, roleName: string, id: number, itemName: string, type: number, hid?: number }, lean = true) {
|
||||
const doc = new ItemModel();
|
||||
const setOnInsert = Object.assign(doc.toJSON(), itemInfo);
|
||||
const items = await ItemModel.findOneAndUpdate({roleId, id },{$setOnInsert: setOnInsert, $inc: { count }}, {new: true, upsert: true}).lean(lean);
|
||||
const items: ItemType = await ItemModel.findOneAndUpdate({roleId, id },{$setOnInsert: setOnInsert, $inc: { count }}, {new: true, upsert: true}).lean(lean);
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -77,4 +78,6 @@ export default class Item extends BaseModel {
|
||||
|
||||
export const ItemModel = getModelForClass(Item);
|
||||
|
||||
export interface ItemType extends Pick<DocumentType<Item>, keyof Item>{};
|
||||
export interface ItemType extends Pick<DocumentType<Item>, keyof Item>{
|
||||
id: number;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user