GM后台修改status code

This commit is contained in:
luying
2020-10-17 16:40:08 +08:00
parent 76a6259fbc
commit 81bce4f57b
10 changed files with 134 additions and 321 deletions
+5 -16
View File
@@ -3,34 +3,26 @@ import { GMUserGroupModel } from '@db/GMUserGroup'
import { GMGroupModel } from '@db/GMGroup'
import { GMRecordModel } from '@db/GMRecord'
import { ApiModel } from '@db/Api';
import { STATUS } from '@consts/statusCode';
module.exports = () => {
return async function tokenParser(ctx, next) {
if (!ctx.request.headers || !ctx.request.headers.token) {
console.error('token not found');
ctx.body = {
"status": "error",
"data": "账号未登录"
};
ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS);
return;
}
const user = await GMUserModel.getGmAccountByToken(ctx.request.headers.token);
if (!user) {
console.error('token invalid');
ctx.body = {
"status": "error",
"data": "账号未登录"
};
ctx.body = ctx.service.utils.resResult(STATUS.TOKEN_ERR);
return;
}
const url = ctx.request.url;
let apiResult = await ApiModel.getApi(url);
if(!apiResult) {
ctx.body = {
"status": "error",
"data": "未找到该接口"
};
ctx.body = ctx.service.utils.resResult(STATUS.GM_MISS_API);
return;
}
let userGroups = await GMUserGroupModel.getUserGroupByUid(user.uid, 1);
@@ -45,10 +37,7 @@ module.exports = () => {
}
}
if(flag != 1) {
ctx.body = {
"status": "error",
"data": "您没有权限访问该接口"
};
ctx.body = ctx.service.utils.resResult(STATUS.GM_NO_AUTHORITY_GET);
return;
}
ctx.user = user;