修改状态码机制,初步改造web-server中接口返回

This commit is contained in:
liangtongchuan
2020-10-16 16:02:34 +08:00
parent c8a826466b
commit fefd2dfdd5
7 changed files with 46 additions and 34 deletions

View File

@@ -1,17 +1,17 @@
import { STATUS_TOKEN_ERR, STATUS_WRONG_PARMS } from '@consts/statusCode';
import { UserModel } from './../db/User';
import { STATUS } from '@consts/statusCode';
import { UserModel } from '@db/User';
module.exports = () => {
return async function tokenParser(ctx, next) {
if (!ctx.request.body || !ctx.request.body.token) {
console.error('token not found');
ctx.body = ctx.service.utils.exceptionResult(STATUS_WRONG_PARMS);
ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS);
return;
}
const user = await UserModel.findUserByToken(ctx.request.body.token);
if (!user) {
console.error('token invalid');
ctx.body = ctx.service.utils.exceptionResult(STATUS_TOKEN_ERR);
ctx.body = ctx.service.utils.resResult(STATUS.TOKEN_ERR);
return;
}
ctx.uid = user.uid;