后台:添加操作日志

This commit is contained in:
luying
2021-12-21 19:42:39 +08:00
parent 7d0808a9dc
commit ebf0c1c398
3 changed files with 50 additions and 19 deletions
@@ -1,4 +1,10 @@
import {Application, RouteRecord, FrontendOrBackendSession, HandlerCallback } from "pinus";
import { GM_API_TYPE, STATUS } from "../../../consts";
import { GMGroupModel } from "../../../db/GMGroup";
import { GMRecordModel } from "../../../db/GMRecord";
import { GMUserGroupModel } from "../../../db/GMUserGroup";
import { gameData } from "../../../pubUtils/data";
import { resResult } from "../../../pubUtils/util";
export function tokenFilter(app: Application) {
return new Filter(app);
@@ -12,11 +18,34 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se
const uid = session.get('uid');
let route = routeRecord.route;
console.log('********uid', uid, route);
let dicApi = gameData.apiByUrl.get(route);
if(!dicApi) {
return next(new Error(), resResult(STATUS.GM_MISS_API));
}
let userGroup = await GMUserGroupModel.getUserGroupByUid(uid);
if(!userGroup) {
return next(new Error(), resResult(STATUS.GM_NO_AUTHORITY_GET));
}
let group = await GMGroupModel.getGroupById(userGroup.groupId);
if(!group) {
return next(new Error(), resResult(STATUS.GM_NO_AUTHORITY_GET));
}
if(!group.apis.includes(0) && !group.apis.includes(dicApi.id)) {
return next(new Error(), resResult(STATUS.GM_NO_AUTHORITY_GET));
}
next(null);
};
Filter.prototype.after = function (err: Error, routeRecord: RouteRecord, msg: any, session: FrontendOrBackendSession, resp: any, next: HandlerCallback) {
const uid = session.get('uid');
let route = routeRecord.route;
let dicApi = gameData.apiByUrl.get(route);
if(dicApi.type != GM_API_TYPE.find) {
GMRecordModel.createRecord(uid, route, JSON.stringify(msg||{}), JSON.stringify(resp||{}));
}
next(err);
};