-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
417 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Data Source | ||
|
||
Esta camada tem como responsabilidade o acesso a dados no lado do servidor, contendo códigos que modela e se comunica com um ou mais tipos de fonte de dados e tudo que está relacionado diretamente, como gerenciamento de estado por exemplo. | ||
|
||
> Aqui encontraremos muitas implementações concretas cujos contratos foram definidos na camada de domínio. | ||
## Estrutura | ||
|
||
```sh | ||
📂 src | ||
└── 📂 lib | ||
├── dtos | ||
├── entities | ||
├── facades | ||
├── providers | ||
├── repositories | ||
├── services | ||
└── providers.ts | ||
``` | ||
|
||
## DTOs | ||
|
||
## Entities | ||
|
||
## Facades | ||
|
||
## Providers | ||
|
||
## Repositories | ||
|
||
## Services |
67 changes: 0 additions & 67 deletions
67
packages/data-source-account/src/lib/data-source-account.providers.ts
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
packages/data-source-account/src/lib/data-source-account.spec.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './create-user'; | ||
export * from './sign-in'; | ||
export * from './sign-up'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { IsString, MinLength } from 'class-validator'; | ||
import { SignIn } from '@platform/domain-account'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class SignInDto implements SignIn { | ||
@IsString() | ||
@ApiProperty() | ||
username: string; | ||
|
||
@IsString() | ||
@MinLength(6) | ||
@ApiProperty() | ||
password: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { IsEmail, IsString, MinLength } from 'class-validator'; | ||
import { SignUp } from '@platform/domain-account'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class SignUpDto implements SignUp { | ||
@IsString() | ||
@ApiProperty() | ||
firstName: string; | ||
|
||
@IsString() | ||
@ApiProperty() | ||
lastName: string; | ||
|
||
@IsEmail() | ||
@ApiProperty() | ||
email: string; | ||
|
||
@IsString() | ||
@ApiProperty() | ||
username: string; | ||
|
||
@IsString() | ||
@MinLength(6) | ||
@ApiProperty() | ||
password: string; | ||
|
||
phone?: string; | ||
|
||
photo?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import { SignInServerUseCase } from '@platform/domain-account'; | ||
import { SignInDto } from '../dtos'; | ||
import { SignInServerUseCase, SignUpServerUseCase } from '@platform/domain-account'; | ||
import { SignInDto, SignUpDto } from '../dtos'; | ||
|
||
export class AuthFacade { | ||
constructor(private readonly signInUseCase: SignInServerUseCase) {} | ||
constructor( | ||
private readonly signInUseCase: SignInServerUseCase, | ||
private readonly signUpUseCase: SignUpServerUseCase | ||
) {} | ||
|
||
signIn(data: SignInDto) { | ||
return this.signInUseCase.execute(data); | ||
} | ||
|
||
signUp(data: SignUpDto) { | ||
return this.signUpUseCase.execute(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
provideAuthServerFacade, | ||
provideCreateUserServerUseCase, | ||
provideCryptoService, | ||
provideFindUsersServerUseCase, | ||
provideSignInServerUseCase, | ||
provideSignUpServerUseCase, | ||
provideUserRepository, | ||
provideUserServerFacade, | ||
} from './providers/index'; | ||
import { UserRepositoryImpl } from './repositories'; | ||
import { Provider } from '@platform/util-shared'; | ||
import { CryptoServiceImpl } from './services'; | ||
|
||
export const dataSourceAccountProviders: Provider[] = [ | ||
provideUserRepository(UserRepositoryImpl), | ||
|
||
provideCreateUserServerUseCase(), | ||
provideFindUsersServerUseCase(), | ||
|
||
provideUserServerFacade(), | ||
|
||
provideCryptoService(CryptoServiceImpl), | ||
|
||
provideSignInServerUseCase(), | ||
provideSignUpServerUseCase(), | ||
|
||
provideAuthServerFacade(), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
CreateUserServerUseCase, | ||
FindUsersServerUseCase, | ||
SignInServerUseCase, | ||
SignUpServerUseCase, | ||
} from '@platform/domain-account'; | ||
import { AuthFacade, UserFacade } from '../facades'; | ||
|
||
export function provideUserServerFacade() { | ||
return { | ||
provide: UserFacade, | ||
useFactory( | ||
createUser: CreateUserServerUseCase, | ||
findUsers: FindUsersServerUseCase | ||
) { | ||
return new UserFacade(createUser, findUsers); | ||
}, | ||
inject: [CreateUserServerUseCase, FindUsersServerUseCase], | ||
}; | ||
} | ||
|
||
export function provideAuthServerFacade() { | ||
return { | ||
provide: AuthFacade, | ||
useFactory(signIn: SignInServerUseCase, signUp: SignUpServerUseCase) { | ||
return new AuthFacade(signIn, signUp); | ||
}, | ||
inject: [SignInServerUseCase, SignUpServerUseCase], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export * from './crypto'; | ||
export * from './facade'; | ||
export * from './jwt'; | ||
export * from './repository'; | ||
export * from './use-case'; |
22 changes: 22 additions & 0 deletions
22
packages/data-source-account/src/lib/providers/repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { UserRepository } from '@platform/domain-account'; | ||
import { getRepositoryToken } from '@nestjs/typeorm'; | ||
import { Type } from '@platform/util-shared'; | ||
import { UserEntity } from '../entities'; | ||
import { Repository } from 'typeorm'; | ||
|
||
export function provideUserRepository(Repository: Type<UserRepository>) { | ||
return { | ||
provide: UserRepository, | ||
useFactory(repository: Repository<UserEntity>) { | ||
return new Repository(repository); | ||
}, | ||
inject: [getRepositoryToken(UserEntity)], | ||
}; | ||
} | ||
|
||
export function provideUserRepositoryTest(Repository: UserRepository) { | ||
return { | ||
provide: UserRepository, | ||
useValue: Repository, | ||
}; | ||
} |
49 changes: 49 additions & 0 deletions
49
packages/data-source-account/src/lib/providers/use-case.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
UserRepository, | ||
CreateUserServerUseCase, | ||
FindUsersServerUseCase, | ||
SignInServerUseCase, | ||
CryptoService, | ||
JwtService, | ||
SignUpServerUseCase, | ||
} from '@platform/domain-account'; | ||
|
||
export function provideCreateUserServerUseCase() { | ||
return { | ||
provide: CreateUserServerUseCase, | ||
useFactory(repository: UserRepository) { | ||
return new CreateUserServerUseCase(repository); | ||
}, | ||
inject: [UserRepository], | ||
}; | ||
} | ||
|
||
export function provideFindUsersServerUseCase() { | ||
return { | ||
provide: FindUsersServerUseCase, | ||
useFactory(repository: UserRepository) { | ||
return new FindUsersServerUseCase(repository); | ||
}, | ||
inject: [UserRepository], | ||
}; | ||
} | ||
|
||
export function provideSignInServerUseCase() { | ||
return { | ||
provide: SignInServerUseCase, | ||
useFactory(user: UserRepository, crypto: CryptoService, jwt: JwtService) { | ||
return new SignInServerUseCase(user, crypto, jwt); | ||
}, | ||
inject: [UserRepository, CryptoService, JwtService], | ||
}; | ||
} | ||
|
||
export function provideSignUpServerUseCase() { | ||
return { | ||
provide: SignUpServerUseCase, | ||
useFactory(user: UserRepository, crypto: CryptoService) { | ||
return new SignUpServerUseCase(user, crypto); | ||
}, | ||
inject: [UserRepository, CryptoService], | ||
}; | ||
} |
Oops, something went wrong.