添加数据库类型别名
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop } from '@typegoose/typegoose';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 体力系统
|
||||
@@ -16,7 +16,7 @@ export default class ActionPoint extends BaseModel {
|
||||
ap: number; // 当前体力
|
||||
|
||||
public static async getAp(roleId: string, lean = true) {
|
||||
let result = await ActionPointModel.findOne({roleId}).select('ap refTime').lean(lean);
|
||||
let result: ActionPointType = await ActionPointModel.findOne({roleId}).select('ap refTime').lean(lean);
|
||||
if(!result) {
|
||||
result = await ActionPointModel.findOneAndUpdate({roleId}, { ap: 0, refTime: 0 }, {new: true, upsert: true}).lean(lean)
|
||||
}
|
||||
@@ -24,14 +24,16 @@ export default class ActionPoint extends BaseModel {
|
||||
}
|
||||
|
||||
public static async saveAp(roleId: string, ap: number, refTime: number, lean = true) {
|
||||
let result = await ActionPointModel.findOneAndUpdate({roleId}, { ap, refTime }, {upsert: true, new: true}).lean(lean);
|
||||
return result||{};
|
||||
let result: ActionPointType = await ActionPointModel.findOneAndUpdate({roleId}, { ap, refTime }, {upsert: true, new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async deleteAccount(roleId: string, lean = true) {
|
||||
let result = await ActionPointModel.deleteMany({roleId}).lean(lean);
|
||||
return result||{};
|
||||
public static async deleteAccount(roleId: string) {
|
||||
let result = await ActionPointModel.deleteMany({roleId});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const ActionPointModel = getModelForClass(ActionPoint);
|
||||
|
||||
export interface ActionPointType extends Pick<DocumentType<ActionPoint>, keyof ActionPoint>{}
|
||||
Reference in New Issue
Block a user