- 新增auth.schema.ts: 用户注册请求参数Schema定义和类型导出 - 新增auth.response.ts: 注册成功/失败响应格式定义 - 新增auth.service.ts: 注册业务逻辑,包含验证码验证、用户名邮箱唯一性检查、密码加密 - 新增auth.controller.ts: POST /api/auth/register路由实现,包含错误处理 - 新增auth.test.ts: 完整测试用例覆盖正常、异常、边界场景(14个测试全通过) - 修复数据库日期时间插入问题和路由路径重复问题 关联PRD: M2-基础用户系统,任务1.0完成
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
/**
|
||
* @file 认证模块Schema定义
|
||
* @author AI Assistant
|
||
* @date 2024-12-19
|
||
* @description 定义认证模块的用户注册Schema
|
||
*/
|
||
|
||
import { t, type Static } from 'elysia';
|
||
|
||
/**
|
||
* 用户注册Schema
|
||
* @description 用户注册请求参数验证规则,基于sys_users表结构
|
||
*/
|
||
export const RegisterSchema = t.Object({
|
||
/** 用户名,2-50字符,对应sys_users.username */
|
||
username: t.String({
|
||
minLength: 2,
|
||
maxLength: 50,
|
||
description: '用户名,2-50字符',
|
||
examples: ['admin', 'testuser']
|
||
}),
|
||
/** 邮箱地址,对应sys_users.email */
|
||
email: t.String({
|
||
format: 'email',
|
||
maxLength: 100,
|
||
description: '邮箱地址',
|
||
examples: ['user@example.com']
|
||
}),
|
||
/** 密码,6-50字符 */
|
||
password: t.String({
|
||
minLength: 6,
|
||
maxLength: 50,
|
||
description: '密码,6-50字符',
|
||
examples: ['password123']
|
||
}),
|
||
/** 图形验证码 */
|
||
captcha: t.String({
|
||
minLength: 4,
|
||
maxLength: 6,
|
||
description: '图形验证码',
|
||
examples: ['a1b2']
|
||
}),
|
||
/** 验证码会话ID */
|
||
captchaId: t.String({
|
||
description: '验证码会话ID',
|
||
examples: ['uuid-string-here']
|
||
})
|
||
});
|
||
|
||
/** 用户注册请求类型 */
|
||
export type RegisterRequest = Static<typeof RegisterSchema>;
|