Merge branch 'main' into develop
This commit is contained in:
commit
8e44b858ef
@ -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(),
|
||||
|
@ -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();
|
||||
|
||||
|
@ -7,6 +7,7 @@ export function getStatusObject({ status }: { status: SURVEY_STATUS }) {
|
||||
date: Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
export function getValidateValue<T = unknown>(validationResult: Joi.ValidationResult<T>): T {
|
||||
if (validationResult.error) {
|
||||
throw new CommonError(validationResult.error.details.map(e => e.message).join());
|
||||
|
Loading…
Reference in New Issue
Block a user