diff --git a/src/app.module.ts b/src/app.module.ts index 171e5b9..1c028d1 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,10 +1,10 @@ import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; -import { GredisModule } from './Gservice/GREDIS/gredis.module'; -import { GloggerModule } from './Gservice/GLOGGER/glogger.module'; -import { GdatabaseModule } from './Gservice/GDATABASE/gdatabase.module'; -import config from '../config'; -import { StarlightModule } from './starlight/starlight.module'; +import { GredisModule } from '@/Gservice/GREDIS/gredis.module'; +import { GloggerModule } from '@/Gservice/GLOGGER/glogger.module'; +import { GdatabaseModule } from '@/Gservice/GDATABASE/gdatabase.module'; +import config from '@CFG/index'; +import { StarlightModule } from '@/starlight/starlight.module'; @Module({ imports: [ diff --git a/src/main.ts b/src/main.ts index 0c4f4b7..2a72616 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,18 +9,18 @@ import { ValidationPipe } from '@nestjs/common'; // Fastify文件上传插件 import fastifyMultipart from '@fastify/multipart'; // 日志服务 -import { GloggerService } from './Gservice/GLOGGER/glogger.service'; +import { GloggerService } from '@/Gservice/GLOGGER/glogger.service'; // API文档 import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; // 配置文件 import { ConfigService } from '@nestjs/config'; // 异常捕获 -import { GexceptionsfilterFilter } from './Gexceptions/gexceptionsfilter.filter'; +import { GexceptionsfilterFilter } from '@/Gexceptions/gexceptionsfilter.filter'; // 拦截器 // --全局开发拦截 -import { GdevinterceptorInterceptor } from './Ginterceptor/gdevinterceptor.interceptor'; +import { GdevinterceptorInterceptor } from '@/Ginterceptor/gdevinterceptor.interceptor'; // --全局响应拦截 -import { GresponseinterceptorInterceptor } from './Ginterceptor/gresponseinterceptor.interceptor'; +import { GresponseinterceptorInterceptor } from '@/Ginterceptor/gresponseinterceptor.interceptor'; async function bootstrap() { const app = await NestFactory.create( diff --git a/src/starlight/dto/create-starlight.dto.ts b/src/starlight/dto/create-starlight.dto.ts index 37353c1..998c37d 100644 --- a/src/starlight/dto/create-starlight.dto.ts +++ b/src/starlight/dto/create-starlight.dto.ts @@ -4,9 +4,16 @@ export class CreateStarlightDto { @IsNotEmpty({ message: 'name 不能为空', }) - @IsString() + @IsString({ + message: '必须为字符串', + }) name: string; - @IsNumber() + @IsNumber( + {}, + { + message: '必须为数字', + }, + ) age: number; } diff --git a/src/starlight/dto/register.dto.ts b/src/starlight/dto/register.dto.ts new file mode 100644 index 0000000..dae3a50 --- /dev/null +++ b/src/starlight/dto/register.dto.ts @@ -0,0 +1,113 @@ +/* * + * * @name: register.dto.ts + * * @description: 注册接口的参数验证 + * * @author: x7129 + * * @date: 2023-03-23 15:01 + * * */ +import { + IsDate, + IsEmail, + IsEnum, + IsNotEmpty, + IsNumber, + IsOptional, + IsPhoneNumber, + IsString, + Length, + Max, + Min, +} from 'class-validator'; +import { Type } from 'class-transformer'; + +// ? ? +// ? 函数名称: 性别枚举 +// ? 函数用法: +// ? ? + +export enum sex { + '男' = 1, + '女' = 2, + '其他' = 3, +} + +// 此文件为参数验证演示 +// https://github.com/typestack/class-validator#usage +// 这里有更多的验证方法 +export class RegisterEmailCheckoutEmailDto { + // @ 邮箱 + @Length(8, 128, { message: '请将邮箱长度控制在8到128位之间!' }) + @IsEmail({}, { message: '邮箱格式错误!' }) + @IsString({ message: '邮箱应为字符串格式!' }) + email: string; +} +export class RegisterEmailSignUpDto extends RegisterEmailCheckoutEmailDto { + // @ 验证码 + @Length(6, 6, { message: '验证码是6位字符!' }) + code: string; + + // @ 密码 + @Length(8, 128, { message: '请将密码长度控制在8到128位之间!' }) + password: string; + + // @ 用户名 + @Length(8, 128, { message: '请将用户名长度控制在8到128位之间!' }) + usernmae: string; + + // @ 真实姓名 + @IsOptional() + @Length(2, 128, { message: '请将真实姓名长度控制在2到128位之间!' }) + realname: string; + + // @ 昵称 + @IsOptional() + @Length(1, 128, { message: '请将昵称长度控制在1到128位之间!' }) + nickname: string; + + // @ 生日 + @IsOptional() + @IsDate({ message: '生日是一个日期,如1999-12-24!' }) + @Type(() => Date) + birthday: number; + + // @ 性别 + @IsOptional() + @IsEnum(sex, { message: '性别必须为:' + Object.keys(sex) }) + sex: number; + + // @ 住址 + @IsOptional() + @Length(1, 128, { message: '请将住址长度控制在1到128位之间!' }) + address: string; + + // @ 国家/地区 + @IsOptional() + @Length(1, 128, { message: '请将国家/地区长度控制在1到128位之间!' }) + country: string; + + // @ 个人简介 + @IsOptional() + @Length(1, 128, { message: '请将个人简介长度控制在1到128位之间!' }) + profile: string; + + // @ github地址 + @IsOptional() + @Length(1, 128, { message: '请将github地址长度控制在1到128位之间!' }) + githubUrl: string; + + // @ 个人主页地址 + @IsOptional() + @Length(1, 128, { message: '请将个人主页地址长度控制在1到128位之间!' }) + personalUrl: string; + // @ 阿里账号 + @IsOptional() + @Length(1, 128, { message: '请将阿里账号长度控制在1到128位之间!' }) + alibabaId: string; + // @ 抖音账号 + @IsOptional() + @Length(1, 128, { message: '请将抖音账号长度控制在1到128位之间!' }) + tiktokId: string; + // @ 微博账号 + @IsOptional() + @Length(1, 128, { message: '请将微博账号长度控制在1到128位之间!' }) + weiboId: string; +} diff --git a/src/starlight/starlight.controller.ts b/src/starlight/starlight.controller.ts index 25a29e8..6f0219a 100644 --- a/src/starlight/starlight.controller.ts +++ b/src/starlight/starlight.controller.ts @@ -1,3 +1,9 @@ +/* * + * * @name: starlight.controller.ts + * * @description: starLight Controller层 + * * @author: x7129 + * * @date: 2023-03-23 16:09 + * * */ import { Controller, Get, @@ -18,23 +24,71 @@ import { StarlightService } from './starlight.service'; import { CreateStarlightDto } from './dto/create-starlight.dto'; import { UpdateStarlightDto } from './dto/update-starlight.dto'; -import { GloggerService } from '../Gservice/GLOGGER/glogger.service'; -import { GdatabaseService } from '../Gservice/GDATABASE/gdatabase.service'; -import { GredisService } from '../Gservice/GREDIS/gredis.service'; +import { GloggerService } from '@/Gservice/GLOGGER/glogger.service'; +import { GdatabaseService } from '@/Gservice/GDATABASE/gdatabase.service'; +import { GredisService } from '@/Gservice/GREDIS/gredis.service'; +import { + RegisterEmailCheckoutEmailDto, + RegisterEmailSignUpDto, +} from './dto/register.dto'; -@ApiTags('starlight') -@Controller('starlight') +// C C +// C 类名称: StarlightController +// C 类描述: starLight Controller层入口 +// C C +@ApiTags('starLight') +@Controller('starLight') // 拦截器 @UseGuards(StarlightGuard) export class StarlightController { constructor( + // @ 配置文件服务 private readonly config: ConfigService, + // @ service层 private readonly starlightService: StarlightService, + // @ 日志服务 private readonly logger: GloggerService, + // @ 数据库服务 private readonly database: GdatabaseService, + // @ Redis服务 private readonly redis: GredisService, ) {} + //#region 邮箱注册 + // ? ? + // ? 函数名称: registerEmailCheckoutEmail + // ? 函数描述: 查重邮箱注册 + // ? ? + @Get('register/email/checkoutEmail/:email') + registerEmailCheckoutEmail( + @Param() param: RegisterEmailCheckoutEmailDto, + ): Promise { + return this.starlightService.registerEmailCheckoutEmail(param); + } + // ? ? + // ? 函数名称: registerEmailSendCode + // ? 函数描述: 发送邮箱注册验证码 + // ? ? + @Get('register/email/sendCode/:email') + registerEmailSendCode( + @Param() param: RegisterEmailCheckoutEmailDto, + ): Promise { + return this.starlightService.registerEmailSendCode(param); + } + + // ? ? + // ? 函数名称: registerEmailSignUp + // ? 函数描述: + // ? ? + //#endregion + @Post('/register/email/signUp') + registerEmailSignUpDto( + @Body() body: RegisterEmailSignUpDto, + ): Promise { + return this.starlightService.registerEmailSignUpDto(body); + } + + //#region 测试 @Post() create(@Body() createStarlightDto: CreateStarlightDto) { this.logger.debug(createStarlightDto); @@ -44,7 +98,6 @@ export class StarlightController { }; return this.starlightService.create(createStarlightDto); } - @Get() async findAll() { this.logger.debug(this.config.get('master')); @@ -90,4 +143,5 @@ export class StarlightController { ); return 'Hello World'; } + //#endregion } diff --git a/src/starlight/starlight.service.ts b/src/starlight/starlight.service.ts index 86fedb5..a146a11 100644 --- a/src/starlight/starlight.service.ts +++ b/src/starlight/starlight.service.ts @@ -1,9 +1,76 @@ +/* * + * * @name: starlight.service.ts + * * @description: starLight Service层 + * * @author: x7129 + * * @date: 2023-03-23 17:44 + * * */ import { Injectable } from '@nestjs/common'; import { CreateStarlightDto } from './dto/create-starlight.dto'; import { UpdateStarlightDto } from './dto/update-starlight.dto'; +import { + RegisterEmailCheckoutEmailDto, + RegisterEmailSignUpDto, +} from './dto/register.dto'; +import { ConfigService } from '@nestjs/config'; +import { GloggerService } from '@/Gservice/GLOGGER/glogger.service'; +import { GdatabaseService } from '@/Gservice/GDATABASE/gdatabase.service'; +import { GredisService } from '@/Gservice/GREDIS/gredis.service'; +// C C +// C 类名称: StarlightService +// C 类描述: 为StartController提供服务 +// C C @Injectable() export class StarlightService { + constructor( + // @ 配置文件服务 + private readonly config: ConfigService, + // @ 日志服务 + private readonly logger: GloggerService, + // @ 数据库服务 + private readonly database: GdatabaseService, + // @ Redis服务 + private readonly redis: GredisService, + ) {} + //#region 邮箱注册 + // ? ? + // ? 函数名称: registerEmailCheckoutEmail + // ? 函数描述: 查重邮箱注册 + // ? ? + // ? ? + async registerEmailCheckoutEmail(params: RegisterEmailCheckoutEmailDto) { + return { + data: { ok: 'ok' }, + message: '', + success: true, + }; + } + + // ? 函数名称: registerEmailSendCode + // ? 函数描述: 发送邮箱注册验证码 + // ? ? + async registerEmailSendCode(params: RegisterEmailCheckoutEmailDto) { + return { + data: { ok: 'ok' }, + message: '', + success: true, + }; + } + + // ? ? + // ? 函数名称: registerEmailSignUpDto + // ? 函数描述: 邮箱注册 + // ? ? + async registerEmailSignUpDto(body: RegisterEmailSignUpDto) { + return { + data: { ok: 'ok' }, + message: '', + success: true, + }; + } + //#endregion + //#region + create(createStarlightDto: CreateStarlightDto) { return 'This action adds a new starlight'; } @@ -27,4 +94,5 @@ export class StarlightService { remove(id: number) { return `This action removes a #${id} starlight`; } + //#endredion } diff --git a/tsconfig.json b/tsconfig.json index adb614c..d5a45aa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,14 @@ "noImplicitAny": false, "strictBindCallApply": false, "forceConsistentCasingInFileNames": false, - "noFallthroughCasesInSwitch": false - } + "noFallthroughCasesInSwitch": false, + "paths": { + "@/*": [ + "src/*" + ], + "@CFG/*": [ + "config/*" + ] + } + }, }