Merge branch 'main' into develop

This commit is contained in:
luch 2023-12-28 12:11:03 +08:00 committed by GitHub
commit 8e44b858ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -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(),

View File

@ -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();

View File

@ -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());