Merge branch 'main' into develop
This commit is contained in:
commit
8e44b858ef
@ -1,16 +1,15 @@
|
|||||||
|
|
||||||
import { SurveyApp, SurveyServer } from '../../decorator';
|
import { SurveyApp, SurveyServer } from '../../decorator';
|
||||||
import { Request, Response } from 'koa';
|
|
||||||
import * as Joi from 'joi';
|
import * as Joi from 'joi';
|
||||||
import { userService } from './service/userService';
|
import { userService } from './service/userService';
|
||||||
import { captchaService } from './service/captchaService';
|
import { captchaService } from './service/captchaService';
|
||||||
import { getValidateValue } from './utils/index';
|
import { getValidateValue } from './utils/index';
|
||||||
|
|
||||||
import { CommonError } from '../../types/index';
|
import { CommonError } from '../../types/index';
|
||||||
|
|
||||||
@SurveyApp('/api/user')
|
@SurveyApp('/api/user')
|
||||||
export default class User {
|
export default class User {
|
||||||
@SurveyServer({ type: 'http', method: 'post', routerName: '/register' })
|
@SurveyServer({ type: 'http', method: 'post', routerName: '/register' })
|
||||||
async register({ req }: { req: Request, res: Response }) {
|
async register({ req }) {
|
||||||
const userInfo = getValidateValue(Joi.object({
|
const userInfo = getValidateValue(Joi.object({
|
||||||
username: Joi.string().required(),
|
username: Joi.string().required(),
|
||||||
password: Joi.string().required(),
|
password: Joi.string().required(),
|
||||||
@ -34,7 +33,7 @@ export default class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SurveyServer({ type: 'http', method: 'post', routerName: '/login' })
|
@SurveyServer({ type: 'http', method: 'post', routerName: '/login' })
|
||||||
async login({ req }: { req: Request, res: Response }) {
|
async login({ req }) {
|
||||||
const userInfo = getValidateValue(Joi.object({
|
const userInfo = getValidateValue(Joi.object({
|
||||||
username: Joi.string().required(),
|
username: Joi.string().required(),
|
||||||
password: Joi.string().required(),
|
password: Joi.string().required(),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { mongo } from '../db/mongo';
|
import { mongo } from '../db/mongo';
|
||||||
import { create } from 'svg-captcha';
|
import { create } from 'svg-captcha';
|
||||||
|
|
||||||
class CaptchaService {
|
class CaptchaService {
|
||||||
|
|
||||||
createCaptcha() {
|
createCaptcha() {
|
||||||
@ -38,3 +39,4 @@ class CaptchaService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const captchaService = new CaptchaService();
|
export const captchaService = new CaptchaService();
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ export function getStatusObject({ status }: { status: SURVEY_STATUS }) {
|
|||||||
date: Date.now(),
|
date: Date.now(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getValidateValue<T = unknown>(validationResult: Joi.ValidationResult<T>): T {
|
export function getValidateValue<T = unknown>(validationResult: Joi.ValidationResult<T>): T {
|
||||||
if (validationResult.error) {
|
if (validationResult.error) {
|
||||||
throw new CommonError(validationResult.error.details.map(e => e.message).join());
|
throw new CommonError(validationResult.error.details.map(e => e.message).join());
|
||||||
|
Loading…
Reference in New Issue
Block a user