Skip to content

Commit 4c5e984

Browse files
committed
refactor: cleanup
1 parent 0a3da63 commit 4c5e984

36 files changed

+462
-125
lines changed

apps/server/src/main.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
/**
2-
* This is not a production server yet!
3-
* This is only a minimal backend to get started.
4-
*/
5-
6-
import { Logger } from '@nestjs/common';
1+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
72
import { NestFactory } from '@nestjs/core';
8-
3+
import { Logger } from '@nestjs/common';
94
import { AppModule } from './app/app.module';
105

116
async function bootstrap() {
127
const app = await NestFactory.create(AppModule);
13-
const globalPrefix = 'api';
14-
app.setGlobalPrefix(globalPrefix);
8+
const prefix = 'api';
9+
app.setGlobalPrefix(prefix);
10+
11+
const config = new DocumentBuilder()
12+
.setTitle('DevParaná')
13+
.setDescription('The DevParaná Platform API')
14+
.setVersion('1.0')
15+
.addBearerAuth()
16+
.build();
17+
18+
const document = SwaggerModule.createDocument(app, config);
19+
SwaggerModule.setup('docs', app, document);
20+
1521
const port = process.env.PORT || 3000;
1622
await app.listen(port);
23+
1724
Logger.log(
18-
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
25+
`🚀 Application is running on: http://localhost:${port}/${prefix}`
1926
);
2027
}
2128

docs/data-source.html

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<h1>Data Source</h1>
2+
<p>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.</p>
3+
<blockquote>
4+
<p>Aqui encontraremos muitas implementações concretas cujos contratos foram definidos na camada de domínio.</p>
5+
</blockquote>
6+
<h2>Estrutura</h2>
7+
<pre><code class="language-sh">📂 src
8+
└── 📂 lib
9+
├── dtos
10+
├── entities
11+
├── facades
12+
├── providers
13+
├── repositories
14+
├── services
15+
└── providers.ts
16+
</code></pre>
17+
<h2>DTOs</h2>
18+
<h2>Entities</h2>
19+
<h2>Facades</h2>
20+
<h2>Providers</h2>
21+
<h2>Repositories</h2>
22+
<h2>Services</h2>
23+
<style>
24+
body {
25+
font-family: 'Segoe UI', sans-serif;
26+
}
27+
blockquote {
28+
margin-left: 1em;
29+
margin-top: 1em;
30+
padding: 0.06em 0.6em;
31+
background-color: #12e20b4a;
32+
border-style: solid;
33+
border-color: #12e20b;
34+
border-width: 0 0.2em 0.2em 0;
35+
border-radius: 0.3em;
36+
37+
transition: margin 500ms ease-in-out, border 500ms ease-in-out;
38+
}
39+
blockquote:hover {
40+
margin-left: 0;
41+
margin-top: 0;
42+
border-width: 0 0.8em 0.8em 0;
43+
}
44+
</style>
45+

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@nestjs/core": "^10.0.2",
4242
"@nestjs/jwt": "^10.2.0",
4343
"@nestjs/platform-express": "^10.0.2",
44+
"@nestjs/swagger": "^7.4.0",
4445
"@nestjs/typeorm": "^10.0.2",
4546
"bcrypt": "^5.1.1",
4647
"class-transformer": "^0.5.1",

packages/data-source-account/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"@platform/domain-account": "0.0.1",
77
"@platform/util-shared": "0.0.1",
88
"class-validator": "^0.14.1",
9-
"typeorm": "^0.3.20"
9+
"typeorm": "^0.3.20",
10+
"@nestjs/typeorm": "^10.0.2",
11+
"@nestjs/swagger": "^7.4.0",
12+
"bcrypt": "^5.1.1"
1013
},
1114
"type": "commonjs",
1215
"main": "./src/index.js",
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Data Source
2+
3+
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.
4+
5+
> Aqui encontraremos muitas implementações concretas cujos contratos foram definidos na camada de domínio.
6+
7+
## Estrutura
8+
9+
```sh
10+
📂 src
11+
└── 📂 lib
12+
├── dtos
13+
├── entities
14+
├── facades
15+
├── providers
16+
├── repositories
17+
├── services
18+
└── providers.ts
19+
```
20+
21+
## DTOs
22+
23+
## Entities
24+
25+
## Facades
26+
27+
## Providers
28+
29+
## Repositories
30+
31+
## Services

packages/data-source-account/src/lib/data-source-account.providers.ts

-67
This file was deleted.

packages/data-source-account/src/lib/data-source-account.spec.ts

-7
This file was deleted.

packages/data-source-account/src/lib/data-source-account.ts

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './create-user';
22
export * from './sign-in';
3+
export * from './sign-up';
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { IsString, MinLength } from 'class-validator';
22
import { SignIn } from '@platform/domain-account';
3+
import { ApiProperty } from '@nestjs/swagger';
34

45
export class SignInDto implements SignIn {
56
@IsString()
7+
@ApiProperty()
68
username: string;
79

810
@IsString()
911
@MinLength(6)
12+
@ApiProperty()
1013
password: string;
1114
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { IsEmail, IsString, MinLength } from 'class-validator';
2+
import { SignUp } from '@platform/domain-account';
3+
import { ApiProperty } from '@nestjs/swagger';
4+
5+
export class SignUpDto implements SignUp {
6+
@IsString()
7+
@ApiProperty()
8+
firstName: string;
9+
10+
@IsString()
11+
@ApiProperty()
12+
lastName: string;
13+
14+
@IsEmail()
15+
@ApiProperty()
16+
email: string;
17+
18+
@IsString()
19+
@ApiProperty()
20+
username: string;
21+
22+
@IsString()
23+
@MinLength(6)
24+
@ApiProperty()
25+
password: string;
26+
27+
phone?: string;
28+
29+
photo?: string;
30+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import { SignInServerUseCase } from '@platform/domain-account';
2-
import { SignInDto } from '../dtos';
1+
import { SignInServerUseCase, SignUpServerUseCase } from '@platform/domain-account';
2+
import { SignInDto, SignUpDto } from '../dtos';
33

44
export class AuthFacade {
5-
constructor(private readonly signInUseCase: SignInServerUseCase) {}
5+
constructor(
6+
private readonly signInUseCase: SignInServerUseCase,
7+
private readonly signUpUseCase: SignUpServerUseCase
8+
) {}
69

710
signIn(data: SignInDto) {
811
return this.signInUseCase.execute(data);
912
}
13+
14+
signUp(data: SignUpDto) {
15+
return this.signUpUseCase.execute(data);
16+
}
1017
}

packages/data-source-account/src/lib/facades/user.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ export class UserFacade {
1010
constructor(
1111
private readonly createUserUseCase: CreateUserServerUseCase,
1212
private readonly findUsersUseCase: FindUsersServerUseCase
13-
) {
14-
console.log(createUserUseCase, findUsersUseCase);
15-
16-
}
13+
) {}
1714

1815
createUser(data: CreateUserDto) {
1916
return this.createUserUseCase.execute(data);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {
2+
provideAuthServerFacade,
3+
provideCreateUserServerUseCase,
4+
provideCryptoService,
5+
provideFindUsersServerUseCase,
6+
provideSignInServerUseCase,
7+
provideSignUpServerUseCase,
8+
provideUserRepository,
9+
provideUserServerFacade,
10+
} from './providers/index';
11+
import { UserRepositoryImpl } from './repositories';
12+
import { Provider } from '@platform/util-shared';
13+
import { CryptoServiceImpl } from './services';
14+
15+
export const dataSourceAccountProviders: Provider[] = [
16+
provideUserRepository(UserRepositoryImpl),
17+
18+
provideCreateUserServerUseCase(),
19+
provideFindUsersServerUseCase(),
20+
21+
provideUserServerFacade(),
22+
23+
provideCryptoService(CryptoServiceImpl),
24+
25+
provideSignInServerUseCase(),
26+
provideSignUpServerUseCase(),
27+
28+
provideAuthServerFacade(),
29+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {
2+
CreateUserServerUseCase,
3+
FindUsersServerUseCase,
4+
SignInServerUseCase,
5+
SignUpServerUseCase,
6+
} from '@platform/domain-account';
7+
import { AuthFacade, UserFacade } from '../facades';
8+
9+
export function provideUserServerFacade() {
10+
return {
11+
provide: UserFacade,
12+
useFactory(
13+
createUser: CreateUserServerUseCase,
14+
findUsers: FindUsersServerUseCase
15+
) {
16+
return new UserFacade(createUser, findUsers);
17+
},
18+
inject: [CreateUserServerUseCase, FindUsersServerUseCase],
19+
};
20+
}
21+
22+
export function provideAuthServerFacade() {
23+
return {
24+
provide: AuthFacade,
25+
useFactory(signIn: SignInServerUseCase, signUp: SignUpServerUseCase) {
26+
return new AuthFacade(signIn, signUp);
27+
},
28+
inject: [SignInServerUseCase, SignUpServerUseCase],
29+
};
30+
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
export * from './crypto';
2+
export * from './facade';
23
export * from './jwt';
4+
export * from './repository';
5+
export * from './use-case';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { UserRepository } from '@platform/domain-account';
2+
import { getRepositoryToken } from '@nestjs/typeorm';
3+
import { Type } from '@platform/util-shared';
4+
import { UserEntity } from '../entities';
5+
import { Repository } from 'typeorm';
6+
7+
export function provideUserRepository(Repository: Type<UserRepository>) {
8+
return {
9+
provide: UserRepository,
10+
useFactory(repository: Repository<UserEntity>) {
11+
return new Repository(repository);
12+
},
13+
inject: [getRepositoryToken(UserEntity)],
14+
};
15+
}
16+
17+
export function provideUserRepositoryTest(Repository: UserRepository) {
18+
return {
19+
provide: UserRepository,
20+
useValue: Repository,
21+
};
22+
}

0 commit comments

Comments
 (0)