diff --git a/server/src/apps/user/index.ts b/server/src/apps/user/index.ts index 117bb5c2..4a7b93b6 100644 --- a/server/src/apps/user/index.ts +++ b/server/src/apps/user/index.ts @@ -1,16 +1,15 @@ + import { SurveyApp, SurveyServer } from '../../decorator'; -import { Request, Response } from 'koa'; import * as Joi from 'joi'; import { userService } from './service/userService'; import { captchaService } from './service/captchaService'; import { getValidateValue } from './utils/index'; - import { CommonError } from '../../types/index'; @SurveyApp('/api/user') export default class User { @SurveyServer({ type: 'http', method: 'post', routerName: '/register' }) - async register({ req }: { req: Request, res: Response }) { + async register({ req }) { const userInfo = getValidateValue(Joi.object({ username: Joi.string().required(), password: Joi.string().required(), @@ -34,7 +33,7 @@ export default class User { } @SurveyServer({ type: 'http', method: 'post', routerName: '/login' }) - async login({ req }: { req: Request, res: Response }) { + async login({ req }) { const userInfo = getValidateValue(Joi.object({ username: Joi.string().required(), password: Joi.string().required(), diff --git a/server/src/apps/user/service/captchaService.ts b/server/src/apps/user/service/captchaService.ts index 75599fc5..e7db4e96 100644 --- a/server/src/apps/user/service/captchaService.ts +++ b/server/src/apps/user/service/captchaService.ts @@ -1,5 +1,6 @@ import { mongo } from '../db/mongo'; import { create } from 'svg-captcha'; + class CaptchaService { createCaptcha() { @@ -38,3 +39,4 @@ class CaptchaService { } export const captchaService = new CaptchaService(); + diff --git a/server/src/apps/user/utils/index.ts b/server/src/apps/user/utils/index.ts index 8233dbca..4cf47b97 100644 --- a/server/src/apps/user/utils/index.ts +++ b/server/src/apps/user/utils/index.ts @@ -7,6 +7,7 @@ export function getStatusObject({ status }: { status: SURVEY_STATUS }) { date: Date.now(), }; } + export function getValidateValue(validationResult: Joi.ValidationResult): T { if (validationResult.error) { throw new CommonError(validationResult.error.details.map(e => e.message).join());