File tree Expand file tree Collapse file tree 5 files changed +31
-7
lines changed
Expand file tree Collapse file tree 5 files changed +31
-7
lines changed Original file line number Diff line number Diff line change 1+ import { SignInInput } from '@/application/dtos/auth/sign-in.input'
2+ import { SignInDto } from '@/infrastructure/dtos/auth/sign-in.dto'
3+
4+ export abstract class SignInAdapter {
5+ static dtoToInput ( dto : SignInDto ) : SignInInput {
6+ return new SignInInput ( dto . email , dto . password )
7+ }
8+ }
Original file line number Diff line number Diff line change 1+ import { SignInDto } from '@/infrastructure/dtos/auth/sign-in.dto'
2+ import { SignInAdapter } from '@/infrastructure/adapters/auth/sign-in.adapter'
3+ import { Injectable , PipeTransform } from '@nestjs/common'
4+
5+ @Injectable ( )
6+ export class SignInDtoAdapterPipe implements PipeTransform {
7+ transform ( signInDto : SignInDto ) {
8+ return SignInAdapter . dtoToInput ( signInDto )
9+ }
10+ }
Original file line number Diff line number Diff line change 11import { AuthController } from '@/infrastructure/controllers/auth.controller'
2- import { AuthService } from '@/infrastructure/services/auth.service'
32import { ClientModule } from '@/infrastructure/modules/client.module'
4- import { JwtService } from '@nestjs/jwt'
53import { Test , TestingModule } from '@nestjs/testing'
4+ import { AuthModule } from '@/infrastructure/modules/auth.module'
65
76describe ( 'AuthController' , ( ) => {
87 let controller : AuthController
98
109 beforeEach ( async ( ) => {
1110 const module : TestingModule = await Test . createTestingModule ( {
12- imports : [ ClientModule ] ,
13- controllers : [ AuthController ] ,
14- providers : [ AuthService , JwtService ] ,
11+ imports : [ ClientModule , AuthModule ] ,
1512 } ) . compile ( )
1613
1714 controller = module . get < AuthController > ( AuthController )
Original file line number Diff line number Diff line change @@ -3,13 +3,17 @@ import { IAuthController } from '@/application/controllers/auth-controller.inter
33import { SignInDto } from '@/infrastructure/dtos/auth/sign-in.dto'
44import { Body , Controller , Post } from '@nestjs/common'
55import { AuthUseCasesFactory } from '../factories/auth/auth-use-cases.factory'
6+ import { SignInDtoAdapterPipe } from '../common/pipes/sign-in-adapter.pipe'
7+ import { SignInInput } from '@/application/dtos/auth/sign-in.input'
68
79@Controller ( 'auth' )
810export class AuthController implements IAuthController < SignInDto > {
911 constructor ( private readonly authUseCasesFactory : AuthUseCasesFactory ) { }
1012 @Post ( 'login' )
11- async login ( @Body ( ) signInDto : SignInDto ) : Promise < AcessToken > {
13+ async login (
14+ @Body ( SignInDtoAdapterPipe ) signInInput : SignInInput ,
15+ ) : Promise < AcessToken > {
1216 const signInUseCase = this . authUseCasesFactory . getSignInUseCaseInstance ( )
13- return await signInUseCase . execute ( signInDto )
17+ return await signInUseCase . execute ( signInInput )
1418 }
1519}
Original file line number Diff line number Diff line change @@ -8,4 +8,9 @@ export class SignInDto {
88 @IsString ( { message : 'A senha deve ser uma string' } )
99 @IsNotEmpty ( { message : 'A senha é obrigatória' } )
1010 password : string
11+
12+ constructor ( email : string , password : string ) {
13+ this . email = email
14+ this . password = password
15+ }
1116}
You can’t perform that action at this time.
0 commit comments