Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
✨ Add auth module with register
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Oct 22, 2020
1 parent 6d43fcf commit c9f03df
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -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],
})
Expand Down
15 changes: 15 additions & 0 deletions src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -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<OmitSecrets<users>> {
return this.authService.register(data);
}
}
10 changes: 10 additions & 0 deletions src/modules/auth/auth.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IsEmail, IsString, MinLength } from 'class-validator';

export class RegisterDto {
@IsEmail()
email: string;

@IsString()
@MinLength(3)
name: string;
}
11 changes: 11 additions & 0 deletions src/modules/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
14 changes: 14 additions & 0 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -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<users> {
return this.prisma.users.create({
data,
});
}
}

0 comments on commit c9f03df

Please sign in to comment.