后台:权限

This commit is contained in:
luying
2021-12-21 19:42:37 +08:00
parent 151ac33b91
commit 7d0808a9dc
26 changed files with 1009 additions and 818 deletions
-47
View File
@@ -1,47 +0,0 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';
import { COUNTER } from './../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: ApiType = await ApiModel.findOne({ api }).select('apiId api name').lean(lean);
return result;
}
public static async getAllApi(lean = true) {
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: ApiType = await ApiModel.findOneAndUpdate({ apiId }, { $set: { api, name } }, { upsert: true, new: true }).lean(lean);
return result;
}
}
export let ApiModel: ReturnModelType<typeof Api, {}>;
export function loadApiModel(connect: mongoose.Connection) {
ApiModel = getModelForClass(Api, {
existingConnection: connect
});
}
export interface ApiType extends Pick<DocumentType<Api>, keyof Api> { }
+2 -2
View File
@@ -1,5 +1,5 @@
import { COUNTER } from './../consts';
import { CounterModel } from './Counter';
import { CounterAllModal } from './CounterAll';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';
const bcrypt = require('bcrypt');
@@ -72,7 +72,7 @@ export default class GMUser extends BaseModel {
}
public static async createGmAccount(username: string, password: string, name: string, token: string, lean = true) {
const uid = await CounterModel.getNewCounter(COUNTER.GMUID);
const uid = await CounterAllModal.getNewCounter(COUNTER.GMUID);
let r = await this.encryptPass(password);
const user: GMUserType = await GMUserModel.findOneAndUpdate({ username }, { uid, password: r.npassword, salt: r.salt, name, token }, { upsert: true, new: true }).select('uid username name').lean(lean);
return user;
+10 -9
View File
@@ -4,30 +4,31 @@ import { index, getModelForClass, prop, DocumentType, ReturnModelType, mongoose
/**
* GM账号和用户组关系接口
*/
@index({ uid: 1, serverId: 1, groupId: 1 })
@index({ uid: 1, groupId: 1 })
@index({ uid: 1, env: 1 })
export default class GMUserGroup extends BaseModel {
@prop({ required: true })
uid: number;
@prop({ required: true })
serverId: number;
@prop({ required: true, type: String })
envs: string[];
@prop({ required: true })
groupId: number;
public static async getUserGroupByUid(uid: number, serverId: number, lean = true) {
const user: GMUserGroupType[] = await GMUserGroupModel.find({uid, serverId}).lean(lean);
public static async getUserGroupByUid(uid: number) {
const user: GMUserGroupType = await GMUserGroupModel.findOne({ uid }).lean();
return user;
}
public static async removeUserGroup(uid: number, serverId: number, groups: Array<number>) {
const user = await GMUserGroupModel.deleteMany({uid, serverId, groupId: {$in: groups}});
public static async removeUserGroup(uid: number, groups: Array<number>) {
const user = await GMUserGroupModel.deleteMany({uid, groupId: {$in: groups}});
return user;
}
public static async addUserGroup(uid: number, serverId: number, groupId: number, lean = true) {
const result: GMUserGroupType = await GMUserGroupModel.findOneAndUpdate({uid, serverId, groupId}, {}, {new:true, upsert:true}).lean(lean);
public static async addUserGroup(uid: number, groupId: number, envs: string[]) {
const result: GMUserGroupType = await GMUserGroupModel.findOneAndUpdate({uid}, { envs, groupId }, {new:true, upsert:true}).lean();
return result;
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
import { COUNTER } from './../consts';
import { CounterModel } from './Counter';
import { CounterAllModal } from './CounterAll';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';
import ServerStategy from './ServerStategy';
@@ -49,7 +49,7 @@ export default class Region extends BaseModel {
stategy: ServerStategy; // 策略配置
public static async createNewRegion(params: RegionUpdate, uid = 1) {
let id = await CounterModel.getNewCounter(COUNTER.REGION);
let id = await CounterAllModal.getNewCounter(COUNTER.REGION);
const rec: RegionType = await RegionModel.findOneAndUpdate({ id }, { $setOnInsert: { ...params, createdBy: uid}, $set: { updatedBy: uid } }, { new: true, upsert: true }).lean();
return rec;
-2
View File
@@ -1,5 +1,4 @@
import { mongoose } from "@typegoose/typegoose";
import { loadApiModel } from "./Api";
import { loadGMGroupModel } from "./GMGroup";
import { loadGMRecordModel } from "./GMRecord";
import { loadGMUserModel } from './GMUser'
@@ -12,7 +11,6 @@ import { loadMarqueeModel } from "./Marquee";
export function loadGmDb(connect: mongoose.Connection) {
// console.log('************')
loadApiModel(connect);
loadGMGroupModel(connect);
loadGMUserModel(connect);
loadGMUserGroupModel(connect);