添加数据库类型别名

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';
import { COUNTER } from './../consts';
import { CounterModel } from './Counter';
@@ -21,21 +21,23 @@ export default class Api extends BaseModel {
name: string;
public static async getApi(api: string, lean = true) {
let result = await ApiModel.findOne({api}).select('apiId api name').lean(lean);
let result: ApiType = await ApiModel.findOne({api}).select('apiId api name').lean(lean);
return result;
}
public static async getAllApi(lean = true) {
const api = await ApiModel.find().sort({apiId: 1}).lean(lean);
const api: ApiType[] = await ApiModel.find().sort({apiId: 1}).lean(lean);
return api;
}
public static async createApi(api:string, name: string, lean = true) {
const apiId = await CounterModel.getNewCounter(COUNTER.API);
const result = await ApiModel.findOneAndUpdate({apiId}, {$set:{api, name}}, {upsert: true, new: true}).lean(lean);
const result: ApiType = await ApiModel.findOneAndUpdate({apiId}, {$set:{api, name}}, {upsert: true, new: true}).lean(lean);
return result;
}
}
export const ApiModel = getModelForClass(Api);
export interface ApiType extends Pick<DocumentType<Api>, keyof Api>{}