Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
guiseek committed Sep 6, 2024
1 parent 0a3da63 commit 40ed4bd
Show file tree
Hide file tree
Showing 35 changed files with 417 additions and 125 deletions.
27 changes: 17 additions & 10 deletions apps/server/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/

import { Logger } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { NestFactory } from '@nestjs/core';

import { Logger } from '@nestjs/common';
import { AppModule } from './app/app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
const prefix = 'api';
app.setGlobalPrefix(prefix);

const config = new DocumentBuilder()
.setTitle('DevParaná')
.setDescription('The DevParaná Platform API')
.setVersion('1.0')
.addBearerAuth()
.build();

const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('docs', app, document);

const port = process.env.PORT || 3000;
await app.listen(port);

Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
`🚀 Application is running on: http://localhost:${port}/${prefix}`
);
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@nestjs/core": "^10.0.2",
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-express": "^10.0.2",
"@nestjs/swagger": "^7.4.0",
"@nestjs/typeorm": "^10.0.2",
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
Expand Down
5 changes: 4 additions & 1 deletion packages/data-source-account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"@platform/domain-account": "0.0.1",
"@platform/util-shared": "0.0.1",
"class-validator": "^0.14.1",
"typeorm": "^0.3.20"
"typeorm": "^0.3.20",
"@nestjs/typeorm": "^10.0.2",
"@nestjs/swagger": "^7.4.0",
"bcrypt": "^5.1.1"
},
"type": "commonjs",
"main": "./src/index.js",
Expand Down
31 changes: 31 additions & 0 deletions packages/data-source-account/readme.md
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

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions packages/data-source-account/src/lib/data-source-account.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/data-source-account/src/lib/dtos/index.ts
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';
3 changes: 3 additions & 0 deletions packages/data-source-account/src/lib/dtos/sign-in.ts
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;
}
30 changes: 30 additions & 0 deletions packages/data-source-account/src/lib/dtos/sign-up.ts
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;
}
13 changes: 10 additions & 3 deletions packages/data-source-account/src/lib/facades/auth.ts
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);
}
}
5 changes: 1 addition & 4 deletions packages/data-source-account/src/lib/facades/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export class UserFacade {
constructor(
private readonly createUserUseCase: CreateUserServerUseCase,
private readonly findUsersUseCase: FindUsersServerUseCase
) {
console.log(createUserUseCase, findUsersUseCase);

}
) {}

createUser(data: CreateUserDto) {
return this.createUserUseCase.execute(data);
Expand Down
29 changes: 29 additions & 0 deletions packages/data-source-account/src/lib/providers.ts
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(),
];
30 changes: 30 additions & 0 deletions packages/data-source-account/src/lib/providers/facade.ts
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],
};
}
3 changes: 3 additions & 0 deletions packages/data-source-account/src/lib/providers/index.ts
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 packages/data-source-account/src/lib/providers/repository.ts
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 packages/data-source-account/src/lib/providers/use-case.ts
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],
};
}
Loading

0 comments on commit 40ed4bd

Please sign in to comment.