后台添加权限管理
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop } from '@typegoose/typegoose';
|
||||
import { COUNTER } from './../consts/consts';
|
||||
import { CounterModel } from './Counter';
|
||||
|
||||
/**
|
||||
* 接口字段接口
|
||||
*/
|
||||
@index({ apiId: 1 })
|
||||
@index({ api: 1 })
|
||||
|
||||
export default class Api extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
apiId: number;
|
||||
|
||||
@prop({ required: true })
|
||||
api: string;
|
||||
|
||||
@prop({ required: true })
|
||||
name: string;
|
||||
|
||||
public static async getApi(api: string, lean = true) {
|
||||
let result = 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);
|
||||
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);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const ApiModel = getModelForClass(Api);
|
||||
Reference in New Issue
Block a user