diff --git a/apps/server/src/main.ts b/apps/server/src/main.ts index a124382..30b411b 100644 --- a/apps/server/src/main.ts +++ b/apps/server/src/main.ts @@ -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}` ); } diff --git a/package.json b/package.json index e7eb0e4..aff7fea 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/data-source-account/package.json b/packages/data-source-account/package.json index 4cf09ef..13c9fae 100644 --- a/packages/data-source-account/package.json +++ b/packages/data-source-account/package.json @@ -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", diff --git a/packages/data-source-account/readme.md b/packages/data-source-account/readme.md new file mode 100644 index 0000000..ccb6230 --- /dev/null +++ b/packages/data-source-account/readme.md @@ -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 diff --git a/packages/data-source-account/src/lib/data-source-account.providers.ts b/packages/data-source-account/src/lib/data-source-account.providers.ts deleted file mode 100644 index a32b2ba..0000000 --- a/packages/data-source-account/src/lib/data-source-account.providers.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { - JwtService, - CryptoService, - UserRepository, - SignInServerUseCase, - CreateUserServerUseCase, - FindUsersServerUseCase, -} from '@platform/domain-account'; -import { UserRepositoryImpl } from './repositories'; -import { provideCryptoService } from './providers'; -import { Provider } from '@platform/util-shared'; -import { CryptoServiceImpl } from './services'; -import { AuthFacade, UserFacade } from './facades'; - -export const dataSourceAccountProviders: Provider[] = [ - { - provide: UserRepository, - useFactory() { - return new UserRepositoryImpl(); - }, - }, - - { - provide: CreateUserServerUseCase, - useFactory(repository: UserRepository) { - return new CreateUserServerUseCase(repository); - }, - inject: [UserRepository], - }, - - { - provide: FindUsersServerUseCase, - useFactory(repository: UserRepository) { - return new FindUsersServerUseCase(repository); - }, - inject: [UserRepository], - }, - - { - provide: UserFacade, - useFactory( - createUser: CreateUserServerUseCase, - findUsers: FindUsersServerUseCase - ) { - return new UserFacade(createUser, findUsers); - }, - inject: [CreateUserServerUseCase, FindUsersServerUseCase], - }, - - provideCryptoService(CryptoServiceImpl), - - { - provide: SignInServerUseCase, - useFactory(user: UserRepository, crypto: CryptoService, jwt: JwtService) { - return new SignInServerUseCase(user, crypto, jwt); - }, - inject: [UserRepository, CryptoService, JwtService], - }, - - { - provide: AuthFacade, - useFactory(signIn: SignInServerUseCase) { - return new AuthFacade(signIn); - }, - inject: [SignInServerUseCase], - }, -]; diff --git a/packages/data-source-account/src/lib/data-source-account.spec.ts b/packages/data-source-account/src/lib/data-source-account.spec.ts deleted file mode 100644 index 4130307..0000000 --- a/packages/data-source-account/src/lib/data-source-account.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { dataSourceAccount } from './data-source-account'; - -describe('dataSourceAccount', () => { - it('should work', () => { - expect(dataSourceAccount()).toEqual('data-source-account'); - }); -}); diff --git a/packages/data-source-account/src/lib/data-source-account.ts b/packages/data-source-account/src/lib/data-source-account.ts deleted file mode 100644 index 86578b2..0000000 --- a/packages/data-source-account/src/lib/data-source-account.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function dataSourceAccount(): string { - return 'data-source-account'; -} diff --git a/packages/data-source-account/src/lib/dtos/index.ts b/packages/data-source-account/src/lib/dtos/index.ts index 552c692..bd3b812 100644 --- a/packages/data-source-account/src/lib/dtos/index.ts +++ b/packages/data-source-account/src/lib/dtos/index.ts @@ -1,2 +1,3 @@ export * from './create-user'; export * from './sign-in'; +export * from './sign-up'; diff --git a/packages/data-source-account/src/lib/dtos/sign-in.ts b/packages/data-source-account/src/lib/dtos/sign-in.ts index 4ca34eb..6f7d17a 100644 --- a/packages/data-source-account/src/lib/dtos/sign-in.ts +++ b/packages/data-source-account/src/lib/dtos/sign-in.ts @@ -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; } diff --git a/packages/data-source-account/src/lib/dtos/sign-up.ts b/packages/data-source-account/src/lib/dtos/sign-up.ts new file mode 100644 index 0000000..e1906a5 --- /dev/null +++ b/packages/data-source-account/src/lib/dtos/sign-up.ts @@ -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; +} diff --git a/packages/data-source-account/src/lib/facades/auth.ts b/packages/data-source-account/src/lib/facades/auth.ts index d92d7fc..326fc1c 100644 --- a/packages/data-source-account/src/lib/facades/auth.ts +++ b/packages/data-source-account/src/lib/facades/auth.ts @@ -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); + } } diff --git a/packages/data-source-account/src/lib/facades/user.ts b/packages/data-source-account/src/lib/facades/user.ts index 39b5109..b9740b1 100644 --- a/packages/data-source-account/src/lib/facades/user.ts +++ b/packages/data-source-account/src/lib/facades/user.ts @@ -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); diff --git a/packages/data-source-account/src/lib/providers.ts b/packages/data-source-account/src/lib/providers.ts new file mode 100644 index 0000000..3d52bec --- /dev/null +++ b/packages/data-source-account/src/lib/providers.ts @@ -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(), +]; diff --git a/packages/data-source-account/src/lib/providers/facade.ts b/packages/data-source-account/src/lib/providers/facade.ts new file mode 100644 index 0000000..68c4029 --- /dev/null +++ b/packages/data-source-account/src/lib/providers/facade.ts @@ -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], + }; +} diff --git a/packages/data-source-account/src/lib/providers/index.ts b/packages/data-source-account/src/lib/providers/index.ts index 50a893b..a5408d2 100644 --- a/packages/data-source-account/src/lib/providers/index.ts +++ b/packages/data-source-account/src/lib/providers/index.ts @@ -1,2 +1,5 @@ export * from './crypto'; +export * from './facade'; export * from './jwt'; +export * from './repository'; +export * from './use-case'; diff --git a/packages/data-source-account/src/lib/providers/repository.ts b/packages/data-source-account/src/lib/providers/repository.ts new file mode 100644 index 0000000..6fae926 --- /dev/null +++ b/packages/data-source-account/src/lib/providers/repository.ts @@ -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) { + return { + provide: UserRepository, + useFactory(repository: Repository) { + return new Repository(repository); + }, + inject: [getRepositoryToken(UserEntity)], + }; +} + +export function provideUserRepositoryTest(Repository: UserRepository) { + return { + provide: UserRepository, + useValue: Repository, + }; +} diff --git a/packages/data-source-account/src/lib/providers/use-case.ts b/packages/data-source-account/src/lib/providers/use-case.ts new file mode 100644 index 0000000..4d62da7 --- /dev/null +++ b/packages/data-source-account/src/lib/providers/use-case.ts @@ -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], + }; +} diff --git a/packages/data-source-account/src/lib/repositories/user.ts b/packages/data-source-account/src/lib/repositories/user.ts index eca7e45..efe4d61 100644 --- a/packages/data-source-account/src/lib/repositories/user.ts +++ b/packages/data-source-account/src/lib/repositories/user.ts @@ -1,15 +1,35 @@ -import { UserRepository } from '@platform/domain-account'; -import { FindParams } from '@platform/util-shared'; +import { User, UserRepository } from '@platform/domain-account'; +import { FindParams, Paged } from '@platform/util-shared'; +import { Repository, FindManyOptions } from 'typeorm'; import { UserEntity } from '../entities'; import { CreateUserDto } from '../dtos'; export class UserRepositoryImpl implements UserRepository { + constructor(private readonly repository: Repository) {} + createOne(entity: CreateUserDto): Promise { - throw new Error('Method not implemented.'); + return this.repository.save(entity); } - find(params: FindParams): Promise { - throw new Error('Method not implemented.'); + async find(params: FindParams): Promise> { + const { + page = 1, + size = 10, + prop = 'id', + sort = 'ASC', + props = {}, + } = params; + + const order = { [prop]: sort.toUpperCase() }; + const options: FindManyOptions = { + order, + skip: (page - 1) * size, + take: size, + where: props as UserEntity, + }; + const [data, total] = await this.repository.findAndCount(options); + + return { data, total }; } findOne(params: Partial): Promise { diff --git a/packages/data-source-account/src/public-api.ts b/packages/data-source-account/src/public-api.ts index db87143..4e62a72 100644 --- a/packages/data-source-account/src/public-api.ts +++ b/packages/data-source-account/src/public-api.ts @@ -1,4 +1,4 @@ -export * from './lib/data-source-account.providers'; +export * from './lib/providers'; export * from './lib/repositories'; export * from './lib/providers'; export * from './lib/entities'; diff --git a/packages/domain-account/readme.md b/packages/domain-account/readme.md index 73dcf45..6bf7161 100644 --- a/packages/domain-account/readme.md +++ b/packages/domain-account/readme.md @@ -26,7 +26,7 @@ Nesta camada, elas são contratos definidos e que serão implementados na camada ## Ports -Em arquitetura, são abstrações que definem pontos de entrada e saída, permitindo que diferentes partes do software funcionem de forma desacoplada. Como as interfaces, eles definem contratos descrevendo as operações que a aplicaçãopode executar, como comandos de entrada ou comunicação de serviços de terceiros. Também como as interfaces de entidade, eles exigem alguém que os implemente um adaptador de forma concreta, não necessariamente na camada de acesso a dados, podendo variar dependendo das camadas onde são utilizados. Isso facilita mudanças de soluções / tecnologias com alterações mínimas ao invés de grandes reescritas de código. +Em arquitetura, são abstrações que definem pontos de entrada e saída, permitindo que diferentes partes do software funcionem de forma desacoplada. Como as interfaces, eles definem contratos descrevendo as operações que a aplicação pode executar, como comandos de entrada ou comunicação em serviços de terceiros. Também como as interfaces de entidade, eles exigem alguém que os implemente um adaptador de forma concreta, não necessariamente na camada de acesso a dados, podendo variar dependendo das camadas onde são utilizados. Isso facilita mudanças de soluções / tecnologias com alterações mínimas ao invés de grandes reescritas de código. ## Repositories diff --git a/packages/domain-account/src/lib/repositories/user.ts b/packages/domain-account/src/lib/repositories/user.ts index ca0eb66..c85cece 100644 --- a/packages/domain-account/src/lib/repositories/user.ts +++ b/packages/domain-account/src/lib/repositories/user.ts @@ -1,5 +1,6 @@ import { Find, + Paged, FindOne, CreateOne, FindParams, @@ -19,7 +20,7 @@ export abstract class UserRepository { abstract createOne(entity: CreateUser): Promise; - abstract find(params: FindParams): Promise; + abstract find(params: FindParams): Promise>; abstract findOne(params: Partial): Promise; diff --git a/packages/domain-account/src/lib/services/user.ts b/packages/domain-account/src/lib/services/user.ts index 992ef54..8eb4785 100644 --- a/packages/domain-account/src/lib/services/user.ts +++ b/packages/domain-account/src/lib/services/user.ts @@ -4,6 +4,7 @@ import { FindParams, RemoveOne, UpdateOne, + Paged, } from '@platform/util-shared'; import { User } from '../entities'; import { Observable } from 'rxjs'; @@ -14,7 +15,7 @@ export abstract class UserService { abstract createOne(entity: CreateUser): Observable; - abstract find(params: FindParams): Observable; + abstract find(params: FindParams): Observable>; abstract updateOne(id: string, entity: Partial): Observable; diff --git a/packages/domain-account/src/lib/use-cases/user/index.ts b/packages/domain-account/src/lib/use-cases/user/index.ts index f452271..0ce2755 100644 --- a/packages/domain-account/src/lib/use-cases/user/index.ts +++ b/packages/domain-account/src/lib/use-cases/user/index.ts @@ -1,5 +1,6 @@ export * from './server/create-user'; export * from './server/find-users'; +export * from './server/sign-up'; export * from './server/sign-in'; export * from './client/create-user'; diff --git a/packages/domain-account/src/lib/use-cases/user/server/find-users.ts b/packages/domain-account/src/lib/use-cases/user/server/find-users.ts index 76b28f9..53f75df 100644 --- a/packages/domain-account/src/lib/use-cases/user/server/find-users.ts +++ b/packages/domain-account/src/lib/use-cases/user/server/find-users.ts @@ -1,13 +1,13 @@ -import { FindParams, UseCase } from '@platform/util-shared'; +import { FindParams, Paged, UseCase } from '@platform/util-shared'; import { UserRepository } from '../../../repositories'; import { User } from '../../../entities'; export class FindUsersServerUseCase - implements UseCase, User[]> + implements UseCase, Paged> { constructor(private readonly userRepository: UserRepository) {} - async execute(data: FindParams): Promise { + async execute(data: FindParams): Promise> { return this.userRepository.find(data); } } diff --git a/packages/domain-account/src/lib/use-cases/user/server/sign-up.ts b/packages/domain-account/src/lib/use-cases/user/server/sign-up.ts new file mode 100644 index 0000000..8f6f664 --- /dev/null +++ b/packages/domain-account/src/lib/use-cases/user/server/sign-up.ts @@ -0,0 +1,26 @@ +import { BadRequestException, UseCase } from '@platform/util-shared'; +import { UserRepository } from '../../../repositories'; +import { CryptoService } from '../../../ports'; +import { User } from '../../../entities'; +import { SignUp } from '../../../dtos'; + +export class SignUpServerUseCase implements UseCase { + constructor( + private readonly userRepository: UserRepository, + private readonly cryptoService: CryptoService + ) {} + + async execute({ password: pass, ...signUp }: SignUp): Promise { + try { + const password = this.cryptoService.hash(pass); + + return this.userRepository.createOne({ + ...signUp, + roles: ['member'], + password, + }); + } catch { + throw new BadRequestException(); + } + } +} diff --git a/packages/resource-account/src/lib/controllers/auth.controller.ts b/packages/resource-account/src/lib/controllers/auth.controller.ts index 8a04b59..a5ac654 100644 --- a/packages/resource-account/src/lib/controllers/auth.controller.ts +++ b/packages/resource-account/src/lib/controllers/auth.controller.ts @@ -1,19 +1,39 @@ -import { Body, Controller, Post, UnauthorizedException } from '@nestjs/common'; -import { AuthFacade, SignInDto } from '@platform/data-source-account'; +import { + Body, + Post, + Controller, + BadRequestException, + UnauthorizedException, +} from '@nestjs/common'; +import { + SignInDto, + SignUpDto, + AuthFacade, +} from '@platform/data-source-account'; @Controller('auth') export class AuthController { constructor(private readonly authFacade: AuthFacade) {} @Post('sign-in') - async createAuth(@Body() data: SignInDto) { + async signIn(@Body() data: SignInDto) { try { const res = await this.authFacade.signIn(data); console.log(res); - return res - + return res; } catch (err) { throw new UnauthorizedException(err); } } + + @Post('sign-up') + async signUp(@Body() data: SignUpDto) { + try { + const res = await this.authFacade.signUp(data); + console.log(res); + return res; + } catch (err) { + throw new BadRequestException(err); + } + } } diff --git a/packages/resource-account/src/lib/controllers/users.controller.spec.ts b/packages/resource-account/src/lib/controllers/users.controller.spec.ts index 55ac7c0..c86d2ad 100644 --- a/packages/resource-account/src/lib/controllers/users.controller.spec.ts +++ b/packages/resource-account/src/lib/controllers/users.controller.spec.ts @@ -1,6 +1,20 @@ -import { dataSourceAccountProviders } from '@platform/data-source-account'; +import { + provideJwtService, + dataSourceAccountProviders, + provideUserRepositoryTest, +} from '@platform/data-source-account'; import { Test, TestingModule } from '@nestjs/testing'; import { UsersController } from './users.controller'; +import { JwtModule, JwtService } from '@nestjs/jwt'; +import { TypeOrmModule } from '@nestjs/typeorm'; + +const userRepository = { + createOne: jest.fn(), + find: jest.fn(), + findOne: jest.fn(), + updateOne: jest.fn(), + removeOne: jest.fn() +} describe('UsersController', () => { let controller: UsersController; @@ -8,7 +22,15 @@ describe('UsersController', () => { beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ controllers: [UsersController], - providers: [...dataSourceAccountProviders] + imports: [ + JwtModule, + TypeOrmModule, + ], + providers: [ + provideJwtService(JwtService), + ...dataSourceAccountProviders, + provideUserRepositoryTest(userRepository) + ], }).compile(); controller = module.get(UsersController); diff --git a/packages/resource-account/src/lib/controllers/users.controller.ts b/packages/resource-account/src/lib/controllers/users.controller.ts index dbdb129..195ca23 100644 --- a/packages/resource-account/src/lib/controllers/users.controller.ts +++ b/packages/resource-account/src/lib/controllers/users.controller.ts @@ -11,10 +11,7 @@ import { @Controller('users') export class UsersController { - constructor(private readonly userFacade: UserFacade) { - console.log(userFacade['findUsersUseCase']); - - } + constructor(private readonly userFacade: UserFacade) {} @Get() find( diff --git a/packages/resource-account/src/lib/resource-account.module.ts b/packages/resource-account/src/lib/resource-account.module.ts index f00b641..878cc33 100644 --- a/packages/resource-account/src/lib/resource-account.module.ts +++ b/packages/resource-account/src/lib/resource-account.module.ts @@ -8,9 +8,6 @@ import { JwtModule, JwtService } from '@nestjs/jwt'; import { UsersController, AuthController } from './controllers'; import { Module } from '@nestjs/common'; -console.log(dataSourceAccountProviders); - - @Module({ controllers: [AuthController, UsersController], imports: [ diff --git a/packages/util-shared/src/lib/exceptions/bad-request.ts b/packages/util-shared/src/lib/exceptions/bad-request.ts new file mode 100644 index 0000000..084abcb --- /dev/null +++ b/packages/util-shared/src/lib/exceptions/bad-request.ts @@ -0,0 +1,7 @@ +import { HttpException } from './http-exception'; + +export class BadRequestException extends HttpException { + constructor(message = 'BadRequest', statusCode = 400) { + super(message, statusCode); + } +} diff --git a/packages/util-shared/src/lib/exceptions/index.ts b/packages/util-shared/src/lib/exceptions/index.ts index d08f063..82f17a6 100644 --- a/packages/util-shared/src/lib/exceptions/index.ts +++ b/packages/util-shared/src/lib/exceptions/index.ts @@ -1,2 +1,3 @@ +export * from './bad-request'; export * from './http-exception'; export * from './unauthorized'; diff --git a/packages/util-shared/src/lib/interfaces/find.ts b/packages/util-shared/src/lib/interfaces/find.ts index 8208f14..0f42421 100644 --- a/packages/util-shared/src/lib/interfaces/find.ts +++ b/packages/util-shared/src/lib/interfaces/find.ts @@ -1,7 +1,8 @@ import { FindParams } from './find-params'; import { Entity } from './entity'; import { Observable } from 'rxjs'; +import { Paged } from './paged'; export interface Find { - find(params: FindParams): Promise | Observable; + find(params: FindParams): Promise> | Observable>; } diff --git a/packages/util-shared/src/lib/interfaces/index.ts b/packages/util-shared/src/lib/interfaces/index.ts index 30efe90..1260190 100644 --- a/packages/util-shared/src/lib/interfaces/index.ts +++ b/packages/util-shared/src/lib/interfaces/index.ts @@ -4,6 +4,7 @@ export * from './find-all'; export * from './find-one'; export * from './find-params'; export * from './find'; +export * from './paged'; export * from './remove-one'; export * from './update-one'; export * from './use-case'; diff --git a/packages/util-shared/src/lib/interfaces/paged.ts b/packages/util-shared/src/lib/interfaces/paged.ts new file mode 100644 index 0000000..143bc3c --- /dev/null +++ b/packages/util-shared/src/lib/interfaces/paged.ts @@ -0,0 +1,4 @@ +export interface Paged { + data: T[]; + total: number; +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed2113c..c169042 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ dependencies: '@nestjs/platform-express': specifier: ^10.0.2 version: 10.4.1(@nestjs/common@10.4.1)(@nestjs/core@10.4.1) + '@nestjs/swagger': + specifier: ^7.4.0 + version: 7.4.0(@nestjs/common@10.4.1)(@nestjs/core@10.4.1)(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.1.14) '@nestjs/typeorm': specifier: ^10.0.2 version: 10.0.2(@nestjs/common@10.4.1)(@nestjs/core@10.4.1)(reflect-metadata@0.1.14)(rxjs@7.8.1)(typeorm@0.3.20) @@ -1972,6 +1975,10 @@ packages: - supports-color dev: false + /@microsoft/tsdoc@0.15.0: + resolution: {integrity: sha512-HZpPoABogPvjeJOdzCOSJsXeL/SMCBgBZMVC3X3d7YYp2gf31MfxhUoYUNwf1ERPJOnQc0wkFn9trqI6ZEdZuA==} + dev: false + /@module-federation/bridge-react-webpack-plugin@0.2.8: resolution: {integrity: sha512-6G1qTo1HWvRcN5fzE+SZgvgzSPoq5YqNx8hFL8BttJmnd3wj4SUOFiikAsXhdVrzSK+Zuzg6pipkiLH1m+pbtw==} dependencies: @@ -2194,6 +2201,25 @@ packages: jsonwebtoken: 9.0.2 dev: false + /@nestjs/mapped-types@2.0.5(@nestjs/common@10.4.1)(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.1.14): + resolution: {integrity: sha512-bSJv4pd6EY99NX9CjBIyn4TVDoSit82DUZlL4I3bqNfy5Gt+gXTa86i3I/i0iIV9P4hntcGM5GyO+FhZAhxtyg==} + peerDependencies: + '@nestjs/common': ^8.0.0 || ^9.0.0 || ^10.0.0 + class-transformer: ^0.4.0 || ^0.5.0 + class-validator: ^0.13.0 || ^0.14.0 + reflect-metadata: ^0.1.12 || ^0.2.0 + peerDependenciesMeta: + class-transformer: + optional: true + class-validator: + optional: true + dependencies: + '@nestjs/common': 10.4.1(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.1.14)(rxjs@7.8.1) + class-transformer: 0.5.1 + class-validator: 0.14.1 + reflect-metadata: 0.1.14 + dev: false + /@nestjs/platform-express@10.4.1(@nestjs/common@10.4.1)(@nestjs/core@10.4.1): resolution: {integrity: sha512-ccfqIDAq/bg1ShLI5KGtaLaYGykuAdvCi57ohewH7eKJSIpWY1DQjbgKlFfXokALYUq1YOMGqjeZ244OWHfDQg==} peerDependencies: @@ -2239,6 +2265,36 @@ packages: - chokidar dev: true + /@nestjs/swagger@7.4.0(@nestjs/common@10.4.1)(@nestjs/core@10.4.1)(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.1.14): + resolution: {integrity: sha512-dCiwKkRxcR7dZs5jtrGspBAe/nqJd1AYzOBTzw9iCdbq3BGrLpwokelk6lFZPe4twpTsPQqzNKBwKzVbI6AR/g==} + peerDependencies: + '@fastify/static': ^6.0.0 || ^7.0.0 + '@nestjs/common': ^9.0.0 || ^10.0.0 + '@nestjs/core': ^9.0.0 || ^10.0.0 + class-transformer: '*' + class-validator: '*' + reflect-metadata: ^0.1.12 || ^0.2.0 + peerDependenciesMeta: + '@fastify/static': + optional: true + class-transformer: + optional: true + class-validator: + optional: true + dependencies: + '@microsoft/tsdoc': 0.15.0 + '@nestjs/common': 10.4.1(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.1.14)(rxjs@7.8.1) + '@nestjs/core': 10.4.1(@nestjs/common@10.4.1)(@nestjs/platform-express@10.4.1)(reflect-metadata@0.1.14)(rxjs@7.8.1) + '@nestjs/mapped-types': 2.0.5(@nestjs/common@10.4.1)(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.1.14) + class-transformer: 0.5.1 + class-validator: 0.14.1 + js-yaml: 4.1.0 + lodash: 4.17.21 + path-to-regexp: 3.2.0 + reflect-metadata: 0.1.14 + swagger-ui-dist: 5.17.14 + dev: false + /@nestjs/testing@10.4.1(@nestjs/common@10.4.1)(@nestjs/core@10.4.1)(@nestjs/platform-express@10.4.1): resolution: {integrity: sha512-pR+su5+YGqCLH0RhhVkPowQK7FCORU0/PWAywPK7LScAOtD67ZoviZ7hAU4vnGdwkg4HCB0D7W8Bkg19CGU8Xw==} peerDependencies: @@ -3951,7 +4007,6 @@ packages: /argparse@2.0.1: resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} - dev: true /array-flatten@1.1.1: resolution: {integrity: sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==} @@ -7100,7 +7155,6 @@ packages: hasBin: true dependencies: argparse: 2.0.1 - dev: true /jsdom@20.0.3: resolution: {integrity: sha512-SYhBvTh89tTfCD/CRdSOm13mOBa42iTaTyfyEWBdKcGdPxPtLFBXuHR8XHb33YNYaP+lLbmSvBTsnoesCNJEsQ==} @@ -7491,7 +7545,6 @@ packages: /lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} - dev: true /log-symbols@4.1.0: resolution: {integrity: sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==} @@ -9540,6 +9593,10 @@ packages: picocolors: 1.1.0 dev: true + /swagger-ui-dist@5.17.14: + resolution: {integrity: sha512-CVbSfaLpstV65OnSjbXfVd6Sta3q3F7Cj/yYuvHMp1P90LztOLs6PfUnKEVAeiIVQt9u2SaPwv0LiH/OyMjHRw==} + dev: false + /symbol-tree@3.2.4: resolution: {integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==} dev: true