diff --git a/src/app.module.ts b/src/app.module.ts index 910b8f9a1..16b9fb2fb 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,11 +1,12 @@ import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; +import { AuthModule } from './modules/auth/auth.module'; import { PrismaModule } from './modules/prisma/prisma.module'; import { UsersModule } from './modules/user/user.module'; @Module({ - imports: [UsersModule, PrismaModule], + imports: [PrismaModule, UsersModule, AuthModule], controllers: [AppController], providers: [AppService], }) diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts new file mode 100644 index 000000000..dd35ac235 --- /dev/null +++ b/src/modules/auth/auth.controller.ts @@ -0,0 +1,15 @@ +import { Body, Controller, Post } from '@nestjs/common'; +import { users } from '@prisma/client'; +import { OmitSecrets } from 'src/modules/prisma/prisma.interface'; +import { RegisterDto } from './auth.dto'; +import { AuthService } from './auth.service'; + +@Controller('auth') +export class AuthController { + constructor(private authService: AuthService) {} + + @Post('register') + async update(@Body() data: RegisterDto): Promise> { + return this.authService.register(data); + } +} diff --git a/src/modules/auth/auth.dto.ts b/src/modules/auth/auth.dto.ts new file mode 100644 index 000000000..73153d3c7 --- /dev/null +++ b/src/modules/auth/auth.dto.ts @@ -0,0 +1,10 @@ +import { IsEmail, IsString, MinLength } from 'class-validator'; + +export class RegisterDto { + @IsEmail() + email: string; + + @IsString() + @MinLength(3) + name: string; +} diff --git a/src/modules/auth/auth.module.ts b/src/modules/auth/auth.module.ts new file mode 100644 index 000000000..666194bda --- /dev/null +++ b/src/modules/auth/auth.module.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; +import { PrismaModule } from '../prisma/prisma.module'; +import { AuthController } from './auth.controller'; +import { AuthService } from './auth.service'; + +@Module({ + imports: [PrismaModule], + controllers: [AuthController], + providers: [AuthService], +}) +export class AuthModule {} diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts new file mode 100644 index 000000000..423173dd3 --- /dev/null +++ b/src/modules/auth/auth.service.ts @@ -0,0 +1,14 @@ +import { Injectable } from '@nestjs/common'; +import { users, usersCreateInput } from '@prisma/client'; +import { PrismaService } from '../prisma/prisma.service'; + +@Injectable() +export class AuthService { + constructor(private prisma: PrismaService) {} + + async register(data: usersCreateInput): Promise { + return this.prisma.users.create({ + data, + }); + } +}