添加数据库类型别名

This commit is contained in:
luying
2020-12-15 18:08:29 +08:00
parent 1565dd206a
commit 2d774fc0e4
38 changed files with 393 additions and 321 deletions

View File

@@ -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>{}