From d8c433c84705b293d57dbda448bc7c88e7c0843d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Fri, 13 Dec 2024 21:28:32 +0100 Subject: [PATCH 01/11] Create account bounded context #172 --- .../_dependencyInjection/commandHandlers.ts | 4 +++ .../_dependencyInjection/controllers.ts | 15 +++++++++ .../_dependencyInjection/entitySchemas.ts | 3 ++ .../_dependencyInjection/queryHandlers.ts | 4 +++ .../_dependencyInjection/repositories.ts | 10 ++++++ src/account/account.module.ts | 16 ++++++++++ .../v1/auth/loginPostController.ts | 2 +- .../app/controllers/v1/auth/loginPostDto.ts | 0 .../v1/auth/loginPostResponseDto.ts | 0 .../controllers/v1/auth/meGetController.ts | 2 +- .../controllers/v1/auth/meGetResponseDto.ts | 0 .../v1/auth/refreshTokenPostController.ts | 2 +- .../v1/auth/refreshTokenPostDto.ts | 0 .../v1/auth/refreshTokenPostResponseDto.ts | 0 .../v1/auth/signupPostController.ts | 4 +-- .../app/controllers/v1/auth/signupPostDto.ts | 0 .../controllers/v1/user/userGetController.ts | 4 +-- .../controllers/v1/user/userGetResponse.ts | 0 .../controllers/v1/user/userPutController.ts | 4 +-- .../app/controllers/v1/user/userPutDto.ts | 0 .../auth/command/signupUserCommand.ts | 0 .../auth/command/signupUserCommandHandler.ts | 10 +++--- .../auth/query/getUserSocialLoginQuery.ts | 0 .../query/getUserSocialLoginQueryHandler.ts | 2 +- .../query/getUserSocialLoginQueryResponse.ts | 0 .../user/command/updateUserCommand.ts | 0 .../user/command/updateUserCommandHandler.ts | 8 ++--- .../application/user/query/findUserQuery.ts | 0 .../user/query/findUserQueryHandler.ts | 4 +-- .../user/query/findUserResponse.ts | 2 +- .../domain/user/user.ts | 4 +-- .../domain/user/userAlreadyExistsException.ts | 0 .../domain/user/userCreatedEvent.ts | 0 .../domain/user/userDoesNotExistsException.ts | 0 .../domain/user/userId.ts | 0 .../domain/user/userRepository.ts | 0 .../domain/user/userUpdatedEvent.ts | 0 .../persistence/mikroOrm/config.ts | 32 +++++++++++++++++++ .../persistence/mikroOrm/entities/user.ts | 6 ++-- .../persistence/mikroOrm/migrations/.gitkeep | 0 .../repositories/mikroOrmUserRepository.ts | 6 ++-- .../persistence/mikroOrm/types/.gitkeep | 0 src/app.module.ts | 3 +- .../_dependencyInjection/commandHandlers.ts | 4 --- .../_dependencyInjection/controllers.ts | 12 ------- .../_dependencyInjection/entitySchemas.ts | 3 +- .../_dependencyInjection/queryHandlers.ts | 4 --- .../_dependencyInjection/repositories.ts | 6 ---- .../term/command/addLikeTermCommandHandler.ts | 8 ++--- .../term/command/dislikeTermCommandHandler.ts | 8 ++--- .../createExpressionCommandHandler.ts | 2 +- .../command/word/createWordCommandHandler.ts | 2 +- .../command/word/updateWordCommandHandler.ts | 2 +- .../query/findSuggestionsTermQueryHandler.ts | 2 +- .../query/findSuggestionsTermReadModel.ts | 2 +- .../domain/term/expression/expression.ts | 2 +- src/languages/domain/term/term.ts | 2 +- src/languages/domain/term/termLike.ts | 2 +- src/languages/domain/term/word/word.ts | 2 +- .../persistence/mikroOrm/entities/term.ts | 2 +- .../mongoFindSuggestionsTermReadModel.ts | 8 ++--- .../persistence/mikroOrm/types/userIdType.ts | 2 +- .../auth/getUserAcceptance.test.ts | 6 ++-- .../auth/signupAcceptance.test.ts | 0 .../languages/term/getTermAcceptance.test.ts | 2 +- .../term/updateWordAcceptance.test.ts | 2 +- .../v1/auth/signupPostController.test.ts | 4 +-- .../v1/user/userGetController.test.ts | 4 +-- .../command/signupUserCommandHandler.test.ts | 18 +++++------ .../auth/command/signupUserCommandMother.ts | 2 +- .../getUserSocialLoginQueryHandler.test.ts | 4 +-- .../query/getUserSocialLoginQueryMother.ts | 2 +- .../domain/user/userCreatedEventMother.ts | 4 +-- .../domain/user/userIdMother.ts | 2 +- .../domain/user/userMother.ts | 4 +-- .../domain/user/userRepositoryMock.ts | 6 ++-- .../command/addLikeTermCommandHandler.test.ts | 8 ++--- .../term/command/addLikeTermCommandMother.ts | 2 +- .../command/dislikeTermCommandHandler.test.ts | 8 ++--- .../term/command/dislikeTermCommandMother.ts | 2 +- .../word/updateWordCommandHandler.test.ts | 2 +- .../query/findSuggestionsTermReadModelMock.ts | 2 +- .../term/expression/expressionMother.ts | 4 +-- .../domain/term/termDislikedEventMother.ts | 2 +- .../domain/term/termLikeAddedEventMother.ts | 2 +- .../languages/domain/term/termLikeMother.ts | 4 +-- .../languages/domain/term/word/wordMother.ts | 4 +-- 87 files changed, 190 insertions(+), 132 deletions(-) create mode 100644 src/account/_dependencyInjection/commandHandlers.ts create mode 100644 src/account/_dependencyInjection/controllers.ts create mode 100644 src/account/_dependencyInjection/entitySchemas.ts create mode 100644 src/account/_dependencyInjection/queryHandlers.ts create mode 100644 src/account/_dependencyInjection/repositories.ts create mode 100644 src/account/account.module.ts rename src/{languages => account}/app/controllers/v1/auth/loginPostController.ts (92%) rename src/{languages => account}/app/controllers/v1/auth/loginPostDto.ts (100%) rename src/{languages => account}/app/controllers/v1/auth/loginPostResponseDto.ts (100%) rename src/{languages => account}/app/controllers/v1/auth/meGetController.ts (93%) rename src/{languages => account}/app/controllers/v1/auth/meGetResponseDto.ts (100%) rename src/{languages => account}/app/controllers/v1/auth/refreshTokenPostController.ts (95%) rename src/{languages => account}/app/controllers/v1/auth/refreshTokenPostDto.ts (100%) rename src/{languages => account}/app/controllers/v1/auth/refreshTokenPostResponseDto.ts (100%) rename src/{languages => account}/app/controllers/v1/auth/signupPostController.ts (84%) rename src/{languages => account}/app/controllers/v1/auth/signupPostDto.ts (100%) rename src/{languages => account}/app/controllers/v1/user/userGetController.ts (85%) rename src/{languages => account}/app/controllers/v1/user/userGetResponse.ts (100%) rename src/{languages => account}/app/controllers/v1/user/userPutController.ts (87%) rename src/{languages => account}/app/controllers/v1/user/userPutDto.ts (100%) rename src/{languages => account}/application/auth/command/signupUserCommand.ts (100%) rename src/{languages => account}/application/auth/command/signupUserCommandHandler.ts (75%) rename src/{languages => account}/application/auth/query/getUserSocialLoginQuery.ts (100%) rename src/{languages => account}/application/auth/query/getUserSocialLoginQueryHandler.ts (93%) rename src/{languages => account}/application/auth/query/getUserSocialLoginQueryResponse.ts (100%) rename src/{languages => account}/application/user/command/updateUserCommand.ts (100%) rename src/{languages => account}/application/user/command/updateUserCommandHandler.ts (78%) rename src/{languages => account}/application/user/query/findUserQuery.ts (100%) rename src/{languages => account}/application/user/query/findUserQueryHandler.ts (83%) rename src/{languages => account}/application/user/query/findUserResponse.ts (81%) rename src/{languages => account}/domain/user/user.ts (90%) rename src/{languages => account}/domain/user/userAlreadyExistsException.ts (100%) rename src/{languages => account}/domain/user/userCreatedEvent.ts (100%) rename src/{languages => account}/domain/user/userDoesNotExistsException.ts (100%) rename src/{languages => account}/domain/user/userId.ts (100%) rename src/{languages => account}/domain/user/userRepository.ts (100%) rename src/{languages => account}/domain/user/userUpdatedEvent.ts (100%) create mode 100644 src/account/infrastructure/persistence/mikroOrm/config.ts rename src/{languages => account}/infrastructure/persistence/mikroOrm/entities/user.ts (70%) create mode 100644 src/account/infrastructure/persistence/mikroOrm/migrations/.gitkeep rename src/{languages => account}/infrastructure/persistence/mikroOrm/repositories/mikroOrmUserRepository.ts (81%) create mode 100644 src/account/infrastructure/persistence/mikroOrm/types/.gitkeep rename src/{languages => shared}/infrastructure/persistence/mikroOrm/types/userIdType.ts (81%) rename test/acceptance/{languages => account}/auth/getUserAcceptance.test.ts (89%) rename test/acceptance/{languages => account}/auth/signupAcceptance.test.ts (100%) rename test/unit/{languages => account}/app/controllers/v1/auth/signupPostController.test.ts (85%) rename test/unit/{languages => account}/app/controllers/v1/user/userGetController.test.ts (84%) rename test/unit/{languages => account}/application/auth/command/signupUserCommandHandler.test.ts (77%) rename test/unit/{languages => account}/application/auth/command/signupUserCommandMother.ts (87%) rename test/unit/{languages => account}/application/auth/query/getUserSocialLoginQueryHandler.test.ts (91%) rename test/unit/{languages => account}/application/auth/query/getUserSocialLoginQueryMother.ts (86%) rename test/unit/{languages => account}/domain/user/userCreatedEventMother.ts (67%) rename test/unit/{languages => account}/domain/user/userIdMother.ts (73%) rename test/unit/{languages => account}/domain/user/userMother.ts (85%) rename test/unit/{languages => account}/domain/user/userRepositoryMock.ts (84%) diff --git a/src/account/_dependencyInjection/commandHandlers.ts b/src/account/_dependencyInjection/commandHandlers.ts new file mode 100644 index 00000000..69a8da17 --- /dev/null +++ b/src/account/_dependencyInjection/commandHandlers.ts @@ -0,0 +1,4 @@ +import UpdateUserCommandHandler from '@src/account/application/user/command/updateUserCommandHandler'; +import SignupUserCommandHandler from '@src/account/application/auth/command/signupUserCommandHandler'; + +export const commands = [SignupUserCommandHandler, UpdateUserCommandHandler]; diff --git a/src/account/_dependencyInjection/controllers.ts b/src/account/_dependencyInjection/controllers.ts new file mode 100644 index 00000000..1e1db12e --- /dev/null +++ b/src/account/_dependencyInjection/controllers.ts @@ -0,0 +1,15 @@ +import RefreshTokenPostController from '@src/account/app/controllers/v1/auth/refreshTokenPostController'; +import UserPutController from '@src/account/app/controllers/v1/user/userPutController'; +import SignupPostController from '@src/account/app/controllers/v1/auth/signupPostController'; +import LoginPostController from '@src/account/app/controllers/v1/auth/loginPostController'; +import MeGetController from '@src/account/app/controllers/v1/auth/meGetController'; +import UserGetController from '@src/account/app/controllers/v1/user/userGetController'; + +export const controllers = [ + LoginPostController, + SignupPostController, + RefreshTokenPostController, + MeGetController, + UserGetController, + UserPutController, +]; diff --git a/src/account/_dependencyInjection/entitySchemas.ts b/src/account/_dependencyInjection/entitySchemas.ts new file mode 100644 index 00000000..b2088fb1 --- /dev/null +++ b/src/account/_dependencyInjection/entitySchemas.ts @@ -0,0 +1,3 @@ +import { UserSchema } from '@src/account/infrastructure/persistence/mikroOrm/entities/user'; + +export const entitySchemas = [UserSchema]; diff --git a/src/account/_dependencyInjection/queryHandlers.ts b/src/account/_dependencyInjection/queryHandlers.ts new file mode 100644 index 00000000..3ee44b70 --- /dev/null +++ b/src/account/_dependencyInjection/queryHandlers.ts @@ -0,0 +1,4 @@ +import FindUserQueryHandler from '@src/account/application/user/query/findUserQueryHandler'; +import GetUserSocialLoginQueryHandler from '@src/account/application/auth/query/getUserSocialLoginQueryHandler'; + +export const queries = [GetUserSocialLoginQueryHandler, FindUserQueryHandler]; diff --git a/src/account/_dependencyInjection/repositories.ts b/src/account/_dependencyInjection/repositories.ts new file mode 100644 index 00000000..72239826 --- /dev/null +++ b/src/account/_dependencyInjection/repositories.ts @@ -0,0 +1,10 @@ +import { USER_REPOSITORY } from '@src/account/domain/user/userRepository'; + +import MikroOrmUserRepository from '@src/account/infrastructure/persistence/mikroOrm/repositories/mikroOrmUserRepository'; + +export const repositories = [ + { + provide: USER_REPOSITORY, + useClass: MikroOrmUserRepository, + }, +]; diff --git a/src/account/account.module.ts b/src/account/account.module.ts new file mode 100644 index 00000000..de36f8ae --- /dev/null +++ b/src/account/account.module.ts @@ -0,0 +1,16 @@ +import { Module } from '@nestjs/common'; +import { MikroOrmModule } from '@mikro-orm/nestjs'; +import mikroOrmConfiguration from './infrastructure/persistence/mikroOrm/config'; +import { entitySchemas } from '@src/account/_dependencyInjection/entitySchemas'; +import { controllers } from '@src/account/_dependencyInjection/controllers'; +import { commands } from '@src/account/_dependencyInjection/commandHandlers'; +import { queries } from '@src/account/_dependencyInjection/queryHandlers'; +import { repositories } from '@src/account/_dependencyInjection/repositories'; + +@Module({ + imports: [MikroOrmModule.forRoot(mikroOrmConfiguration), MikroOrmModule.forFeature(entitySchemas)], + exports: [], + controllers: [...controllers], + providers: [...commands, ...queries, ...repositories], +}) +export class AccountModule {} diff --git a/src/languages/app/controllers/v1/auth/loginPostController.ts b/src/account/app/controllers/v1/auth/loginPostController.ts similarity index 92% rename from src/languages/app/controllers/v1/auth/loginPostController.ts rename to src/account/app/controllers/v1/auth/loginPostController.ts index ec8a75b9..c73f787a 100644 --- a/src/languages/app/controllers/v1/auth/loginPostController.ts +++ b/src/account/app/controllers/v1/auth/loginPostController.ts @@ -1,4 +1,4 @@ -import GetUserSocialLoginQuery from '@src/languages/application/auth/query/getUserSocialLoginQuery'; +import GetUserSocialLoginQuery from '@src/account/application/auth/query/getUserSocialLoginQuery'; import { Uuid } from '@src/shared/domain/valueObjects/uuid'; import { Body, Controller, HttpCode, Inject, Post } from '@nestjs/common'; import LoginPostDto from './loginPostDto'; diff --git a/src/languages/app/controllers/v1/auth/loginPostDto.ts b/src/account/app/controllers/v1/auth/loginPostDto.ts similarity index 100% rename from src/languages/app/controllers/v1/auth/loginPostDto.ts rename to src/account/app/controllers/v1/auth/loginPostDto.ts diff --git a/src/languages/app/controllers/v1/auth/loginPostResponseDto.ts b/src/account/app/controllers/v1/auth/loginPostResponseDto.ts similarity index 100% rename from src/languages/app/controllers/v1/auth/loginPostResponseDto.ts rename to src/account/app/controllers/v1/auth/loginPostResponseDto.ts diff --git a/src/languages/app/controllers/v1/auth/meGetController.ts b/src/account/app/controllers/v1/auth/meGetController.ts similarity index 93% rename from src/languages/app/controllers/v1/auth/meGetController.ts rename to src/account/app/controllers/v1/auth/meGetController.ts index 4ba22c20..6719bbaa 100644 --- a/src/languages/app/controllers/v1/auth/meGetController.ts +++ b/src/account/app/controllers/v1/auth/meGetController.ts @@ -10,7 +10,7 @@ import { ApiUnauthorizedResponse, } from '@nestjs/swagger'; import { QUERY_BUS, QueryBus } from '@src/shared/domain/bus/queryBus/queryBus'; -import FindUserQuery from '@src/languages/application/user/query/findUserQuery'; +import FindUserQuery from '@src/account/application/user/query/findUserQuery'; @ApiTags('Auth') @Controller() diff --git a/src/languages/app/controllers/v1/auth/meGetResponseDto.ts b/src/account/app/controllers/v1/auth/meGetResponseDto.ts similarity index 100% rename from src/languages/app/controllers/v1/auth/meGetResponseDto.ts rename to src/account/app/controllers/v1/auth/meGetResponseDto.ts diff --git a/src/languages/app/controllers/v1/auth/refreshTokenPostController.ts b/src/account/app/controllers/v1/auth/refreshTokenPostController.ts similarity index 95% rename from src/languages/app/controllers/v1/auth/refreshTokenPostController.ts rename to src/account/app/controllers/v1/auth/refreshTokenPostController.ts index 12137ab5..7a2c1aa5 100644 --- a/src/languages/app/controllers/v1/auth/refreshTokenPostController.ts +++ b/src/account/app/controllers/v1/auth/refreshTokenPostController.ts @@ -11,7 +11,7 @@ import { import RefreshTokenPostDto from './refreshTokenPostDto'; import RefreshTokenPostResponseDto from './refreshTokenPostResponseDto'; import { QUERY_BUS, QueryBus } from '@src/shared/domain/bus/queryBus/queryBus'; -import FindUserQuery from '@src/languages/application/user/query/findUserQuery'; +import FindUserQuery from '@src/account/application/user/query/findUserQuery'; @ApiTags('Auth') @Controller() diff --git a/src/languages/app/controllers/v1/auth/refreshTokenPostDto.ts b/src/account/app/controllers/v1/auth/refreshTokenPostDto.ts similarity index 100% rename from src/languages/app/controllers/v1/auth/refreshTokenPostDto.ts rename to src/account/app/controllers/v1/auth/refreshTokenPostDto.ts diff --git a/src/languages/app/controllers/v1/auth/refreshTokenPostResponseDto.ts b/src/account/app/controllers/v1/auth/refreshTokenPostResponseDto.ts similarity index 100% rename from src/languages/app/controllers/v1/auth/refreshTokenPostResponseDto.ts rename to src/account/app/controllers/v1/auth/refreshTokenPostResponseDto.ts diff --git a/src/languages/app/controllers/v1/auth/signupPostController.ts b/src/account/app/controllers/v1/auth/signupPostController.ts similarity index 84% rename from src/languages/app/controllers/v1/auth/signupPostController.ts rename to src/account/app/controllers/v1/auth/signupPostController.ts index 00cd56a3..68bd25e8 100644 --- a/src/languages/app/controllers/v1/auth/signupPostController.ts +++ b/src/account/app/controllers/v1/auth/signupPostController.ts @@ -1,8 +1,8 @@ import { Body, Controller, HttpCode, Inject, Post } from '@nestjs/common'; import { ApiBadRequestResponse, ApiInternalServerErrorResponse, ApiTags } from '@nestjs/swagger'; -import SignupPostDto from '@src/languages/app/controllers/v1/auth/signupPostDto'; +import SignupPostDto from '@src/account/app/controllers/v1/auth/signupPostDto'; import { COMMAND_BUS, CommandBus } from '@src/shared/domain/bus/commandBus/commandBus'; -import SignupUserCommand from '@src/languages/application/auth/command/signupUserCommand'; +import SignupUserCommand from '@src/account/application/auth/command/signupUserCommand'; import { Uuid } from '@src/shared/domain/valueObjects/uuid'; @ApiTags('Auth') diff --git a/src/languages/app/controllers/v1/auth/signupPostDto.ts b/src/account/app/controllers/v1/auth/signupPostDto.ts similarity index 100% rename from src/languages/app/controllers/v1/auth/signupPostDto.ts rename to src/account/app/controllers/v1/auth/signupPostDto.ts diff --git a/src/languages/app/controllers/v1/user/userGetController.ts b/src/account/app/controllers/v1/user/userGetController.ts similarity index 85% rename from src/languages/app/controllers/v1/user/userGetController.ts rename to src/account/app/controllers/v1/user/userGetController.ts index 9d86ae27..abaf1b37 100644 --- a/src/languages/app/controllers/v1/user/userGetController.ts +++ b/src/account/app/controllers/v1/user/userGetController.ts @@ -8,8 +8,8 @@ import { import { Controller, Get, HttpCode, Inject, Param, UseGuards } from '@nestjs/common'; import { NestJwtAuthGuard } from '@src/shared/guards/nestJwtAuthGuard'; import { QUERY_BUS, QueryBus } from '@src/shared/domain/bus/queryBus/queryBus'; -import FindUserQuery from '@src/languages/application/user/query/findUserQuery'; -import UserGetResponse from '@src/languages/app/controllers/v1/user/userGetResponse'; +import FindUserQuery from '@src/account/application/user/query/findUserQuery'; +import UserGetResponse from '@src/account/app/controllers/v1/user/userGetResponse'; @ApiTags('Users') @Controller() diff --git a/src/languages/app/controllers/v1/user/userGetResponse.ts b/src/account/app/controllers/v1/user/userGetResponse.ts similarity index 100% rename from src/languages/app/controllers/v1/user/userGetResponse.ts rename to src/account/app/controllers/v1/user/userGetResponse.ts diff --git a/src/languages/app/controllers/v1/user/userPutController.ts b/src/account/app/controllers/v1/user/userPutController.ts similarity index 87% rename from src/languages/app/controllers/v1/user/userPutController.ts rename to src/account/app/controllers/v1/user/userPutController.ts index 1da201e6..3303d823 100644 --- a/src/languages/app/controllers/v1/user/userPutController.ts +++ b/src/account/app/controllers/v1/user/userPutController.ts @@ -9,8 +9,8 @@ import { import { Request } from 'express'; import { COMMAND_BUS, CommandBus } from '@src/shared/domain/bus/commandBus/commandBus'; import { NestJwtAuthGuard } from '@src/shared/guards/nestJwtAuthGuard'; -import UserPutDto from '@src/languages/app/controllers/v1/user/userPutDto'; -import UpdateUserCommand from '@src/languages/application/user/command/updateUserCommand'; +import UserPutDto from '@src/account/app/controllers/v1/user/userPutDto'; +import UpdateUserCommand from '@src/account/application/user/command/updateUserCommand'; @ApiTags('Users') @Controller() diff --git a/src/languages/app/controllers/v1/user/userPutDto.ts b/src/account/app/controllers/v1/user/userPutDto.ts similarity index 100% rename from src/languages/app/controllers/v1/user/userPutDto.ts rename to src/account/app/controllers/v1/user/userPutDto.ts diff --git a/src/languages/application/auth/command/signupUserCommand.ts b/src/account/application/auth/command/signupUserCommand.ts similarity index 100% rename from src/languages/application/auth/command/signupUserCommand.ts rename to src/account/application/auth/command/signupUserCommand.ts diff --git a/src/languages/application/auth/command/signupUserCommandHandler.ts b/src/account/application/auth/command/signupUserCommandHandler.ts similarity index 75% rename from src/languages/application/auth/command/signupUserCommandHandler.ts rename to src/account/application/auth/command/signupUserCommandHandler.ts index 5127ebad..6017c4a1 100644 --- a/src/languages/application/auth/command/signupUserCommandHandler.ts +++ b/src/account/application/auth/command/signupUserCommandHandler.ts @@ -1,11 +1,11 @@ import { CommandHandler, ICommandHandler } from '@src/shared/domain/bus/commandBus/commandHandler'; -import SignupUserCommand from '@src/languages/application/auth/command/signupUserCommand'; +import SignupUserCommand from '@src/account/application/auth/command/signupUserCommand'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; -import UserRepository, { USER_REPOSITORY } from '@src/languages/domain/user/userRepository'; +import UserRepository, { USER_REPOSITORY } from '@src/account/domain/user/userRepository'; import { EVENT_BUS, EventBus } from '@src/shared/domain/bus/eventBus/eventBus'; -import UserId from '@src/languages/domain/user/userId'; -import UserAlreadyExistsException from '@src/languages/domain/user/userAlreadyExistsException'; -import User from '@src/languages/domain/user/user'; +import UserId from '@src/account/domain/user/userId'; +import UserAlreadyExistsException from '@src/account/domain/user/userAlreadyExistsException'; +import User from '@src/account/domain/user/user'; import Email from '@src/shared/domain/valueObjects/email'; @CommandHandler(SignupUserCommand) diff --git a/src/languages/application/auth/query/getUserSocialLoginQuery.ts b/src/account/application/auth/query/getUserSocialLoginQuery.ts similarity index 100% rename from src/languages/application/auth/query/getUserSocialLoginQuery.ts rename to src/account/application/auth/query/getUserSocialLoginQuery.ts diff --git a/src/languages/application/auth/query/getUserSocialLoginQueryHandler.ts b/src/account/application/auth/query/getUserSocialLoginQueryHandler.ts similarity index 93% rename from src/languages/application/auth/query/getUserSocialLoginQueryHandler.ts rename to src/account/application/auth/query/getUserSocialLoginQueryHandler.ts index 2e0b78d7..dc7e0505 100644 --- a/src/languages/application/auth/query/getUserSocialLoginQueryHandler.ts +++ b/src/account/application/auth/query/getUserSocialLoginQueryHandler.ts @@ -7,7 +7,7 @@ import { } from '@src/shared/domain/auth/socialAuthenticationVerifier'; import { IQueryHandler, QueryHandler } from '@src/shared/domain/bus/queryBus/queryHandler'; import { USER_AUTHENTICATOR, UserAuthenticator } from '@src/shared/domain/auth/userAuthenticator'; -import GetUserSocialLoginQueryResponse from '@src/languages/application/auth/query/getUserSocialLoginQueryResponse'; +import GetUserSocialLoginQueryResponse from '@src/account/application/auth/query/getUserSocialLoginQueryResponse'; @QueryHandler(GetUserSocialLoginQuery) export default class GetUserSocialLoginQueryHandler implements IQueryHandler { diff --git a/src/languages/application/auth/query/getUserSocialLoginQueryResponse.ts b/src/account/application/auth/query/getUserSocialLoginQueryResponse.ts similarity index 100% rename from src/languages/application/auth/query/getUserSocialLoginQueryResponse.ts rename to src/account/application/auth/query/getUserSocialLoginQueryResponse.ts diff --git a/src/languages/application/user/command/updateUserCommand.ts b/src/account/application/user/command/updateUserCommand.ts similarity index 100% rename from src/languages/application/user/command/updateUserCommand.ts rename to src/account/application/user/command/updateUserCommand.ts diff --git a/src/languages/application/user/command/updateUserCommandHandler.ts b/src/account/application/user/command/updateUserCommandHandler.ts similarity index 78% rename from src/languages/application/user/command/updateUserCommandHandler.ts rename to src/account/application/user/command/updateUserCommandHandler.ts index a8f63f2a..be41dd75 100644 --- a/src/languages/application/user/command/updateUserCommandHandler.ts +++ b/src/account/application/user/command/updateUserCommandHandler.ts @@ -1,11 +1,11 @@ -import UserRepository, { USER_REPOSITORY } from '@src/languages/domain/user/userRepository'; +import UserRepository, { USER_REPOSITORY } from '@src/account/domain/user/userRepository'; import UpdateUserCommand from './updateUserCommand'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import { CommandHandler, ICommandHandler } from '@src/shared/domain/bus/commandBus/commandHandler'; import { EVENT_BUS, EventBus } from '@src/shared/domain/bus/eventBus/eventBus'; -import User from '@src/languages/domain/user/user'; -import UserDoesNotExistsException from '@src/languages/domain/user/userDoesNotExistsException'; +import User from '@src/account/domain/user/user'; +import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; @CommandHandler(UpdateUserCommand) export default class UpdateUserCommandHandler implements ICommandHandler { diff --git a/src/languages/application/user/query/findUserQuery.ts b/src/account/application/user/query/findUserQuery.ts similarity index 100% rename from src/languages/application/user/query/findUserQuery.ts rename to src/account/application/user/query/findUserQuery.ts diff --git a/src/languages/application/user/query/findUserQueryHandler.ts b/src/account/application/user/query/findUserQueryHandler.ts similarity index 83% rename from src/languages/application/user/query/findUserQueryHandler.ts rename to src/account/application/user/query/findUserQueryHandler.ts index af1e9169..030a86de 100644 --- a/src/languages/application/user/query/findUserQueryHandler.ts +++ b/src/account/application/user/query/findUserQueryHandler.ts @@ -1,7 +1,7 @@ -import UserRepository, { USER_REPOSITORY } from '@src/languages/domain/user/userRepository'; +import UserRepository, { USER_REPOSITORY } from '@src/account/domain/user/userRepository'; import FindUserQuery from './findUserQuery'; import QueryResponse from '@src/shared/domain/bus/queryBus/queryResponse'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import FindUserResponse from './findUserResponse'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import { IQueryHandler, QueryHandler } from '@src/shared/domain/bus/queryBus/queryHandler'; diff --git a/src/languages/application/user/query/findUserResponse.ts b/src/account/application/user/query/findUserResponse.ts similarity index 81% rename from src/languages/application/user/query/findUserResponse.ts rename to src/account/application/user/query/findUserResponse.ts index 78102817..a6a38fad 100644 --- a/src/languages/application/user/query/findUserResponse.ts +++ b/src/account/application/user/query/findUserResponse.ts @@ -1,4 +1,4 @@ -import User, { UserPrimitives } from '@src/languages/domain/user/user'; +import User, { UserPrimitives } from '@src/account/domain/user/user'; import QueryResponse from '@src/shared/domain/bus/queryBus/queryResponse'; export default class FindUserResponse extends QueryResponse { diff --git a/src/languages/domain/user/user.ts b/src/account/domain/user/user.ts similarity index 90% rename from src/languages/domain/user/user.ts rename to src/account/domain/user/user.ts index 0e62e4b7..e369e245 100644 --- a/src/languages/domain/user/user.ts +++ b/src/account/domain/user/user.ts @@ -1,8 +1,8 @@ import { AggregateRoot } from '@src/shared/domain/aggregate/aggregateRoot'; import UserId from './userId'; import Email from '@src/shared/domain/valueObjects/email'; -import UserUpdatedEvent from '@src/languages/domain/user/userUpdatedEvent'; -import UserCreatedEvent from '@src/languages/domain/user/userCreatedEvent'; +import UserUpdatedEvent from '@src/account/domain/user/userUpdatedEvent'; +import UserCreatedEvent from '@src/account/domain/user/userCreatedEvent'; export type UserPrimitives = { id: string; diff --git a/src/languages/domain/user/userAlreadyExistsException.ts b/src/account/domain/user/userAlreadyExistsException.ts similarity index 100% rename from src/languages/domain/user/userAlreadyExistsException.ts rename to src/account/domain/user/userAlreadyExistsException.ts diff --git a/src/languages/domain/user/userCreatedEvent.ts b/src/account/domain/user/userCreatedEvent.ts similarity index 100% rename from src/languages/domain/user/userCreatedEvent.ts rename to src/account/domain/user/userCreatedEvent.ts diff --git a/src/languages/domain/user/userDoesNotExistsException.ts b/src/account/domain/user/userDoesNotExistsException.ts similarity index 100% rename from src/languages/domain/user/userDoesNotExistsException.ts rename to src/account/domain/user/userDoesNotExistsException.ts diff --git a/src/languages/domain/user/userId.ts b/src/account/domain/user/userId.ts similarity index 100% rename from src/languages/domain/user/userId.ts rename to src/account/domain/user/userId.ts diff --git a/src/languages/domain/user/userRepository.ts b/src/account/domain/user/userRepository.ts similarity index 100% rename from src/languages/domain/user/userRepository.ts rename to src/account/domain/user/userRepository.ts diff --git a/src/languages/domain/user/userUpdatedEvent.ts b/src/account/domain/user/userUpdatedEvent.ts similarity index 100% rename from src/languages/domain/user/userUpdatedEvent.ts rename to src/account/domain/user/userUpdatedEvent.ts diff --git a/src/account/infrastructure/persistence/mikroOrm/config.ts b/src/account/infrastructure/persistence/mikroOrm/config.ts new file mode 100644 index 00000000..094454cb --- /dev/null +++ b/src/account/infrastructure/persistence/mikroOrm/config.ts @@ -0,0 +1,32 @@ +import { Migrator } from '@mikro-orm/migrations'; +import { defineConfig, PostgreSqlDriver } from '@mikro-orm/postgresql'; + +import { config as loadEnv } from 'dotenv'; +import dotenvExpand from 'dotenv-expand'; +import path from 'path'; +import { entitySchemas } from '@src/account/_dependencyInjection/entitySchemas'; + +const env = loadEnv(); +dotenvExpand.expand(env); + +const migrationPath = path.join(__dirname, '/migrations'); + +export default defineConfig({ + entities: entitySchemas, + entitiesTs: entitySchemas, + driver: PostgreSqlDriver, + clientUrl: process.env.POSTGRESQL_DB_URL, + debug: process.env.ENV != 'production', + extensions: [Migrator], + ignoreUndefinedInQuery: true, + forceUndefined: false, + migrations: { + path: migrationPath, + glob: '!(*.d).{js,ts}', + pathTs: migrationPath, + tableName: 'mikro_orm_migrations', + transactional: true, + allOrNothing: true, + snapshot: false, + }, +}); diff --git a/src/languages/infrastructure/persistence/mikroOrm/entities/user.ts b/src/account/infrastructure/persistence/mikroOrm/entities/user.ts similarity index 70% rename from src/languages/infrastructure/persistence/mikroOrm/entities/user.ts rename to src/account/infrastructure/persistence/mikroOrm/entities/user.ts index ddc7b549..67521ae2 100644 --- a/src/languages/infrastructure/persistence/mikroOrm/entities/user.ts +++ b/src/account/infrastructure/persistence/mikroOrm/entities/user.ts @@ -1,7 +1,7 @@ import { EntitySchema } from '@mikro-orm/core'; -import User from '@src/languages/domain/user/user'; -import { UserIdType } from '../../mikroOrm/types/userIdType'; -import { EmailType } from '../../../../../shared/infrastructure/persistence/mikroOrm/types/emailType'; +import User from '@src/account/domain/user/user'; +import { UserIdType } from '@src/shared/infrastructure/persistence/mikroOrm/types/userIdType'; +import { EmailType } from '@src/shared/infrastructure/persistence/mikroOrm/types/emailType'; export const UserSchema = new EntitySchema({ class: User, diff --git a/src/account/infrastructure/persistence/mikroOrm/migrations/.gitkeep b/src/account/infrastructure/persistence/mikroOrm/migrations/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/src/languages/infrastructure/persistence/mikroOrm/repositories/mikroOrmUserRepository.ts b/src/account/infrastructure/persistence/mikroOrm/repositories/mikroOrmUserRepository.ts similarity index 81% rename from src/languages/infrastructure/persistence/mikroOrm/repositories/mikroOrmUserRepository.ts rename to src/account/infrastructure/persistence/mikroOrm/repositories/mikroOrmUserRepository.ts index 775b4b3c..b557f4d5 100644 --- a/src/languages/infrastructure/persistence/mikroOrm/repositories/mikroOrmUserRepository.ts +++ b/src/account/infrastructure/persistence/mikroOrm/repositories/mikroOrmUserRepository.ts @@ -1,6 +1,6 @@ -import UserRepository from '@src/languages/domain/user/userRepository'; -import User from '@src/languages/domain/user/user'; -import UserId from '@src/languages/domain/user/userId'; +import UserRepository from '@src/account/domain/user/userRepository'; +import User from '@src/account/domain/user/user'; +import UserId from '@src/account/domain/user/userId'; import { Injectable } from '@nestjs/common'; import Email from '@src/shared/domain/valueObjects/email'; import { EntityManager, EntityRepository } from '@mikro-orm/core'; diff --git a/src/account/infrastructure/persistence/mikroOrm/types/.gitkeep b/src/account/infrastructure/persistence/mikroOrm/types/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/src/app.module.ts b/src/app.module.ts index cd8a602e..a5f499f1 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,8 +1,9 @@ import { Module } from '@nestjs/common'; import { LanguageModule } from './languages/language.module'; import { SharedModule } from './shared/shared.module'; +import { AccountModule } from '@src/account/account.module'; @Module({ - imports: [SharedModule, LanguageModule], + imports: [SharedModule, AccountModule, LanguageModule], }) export class AppModule {} diff --git a/src/languages/_dependencyInjection/commandHandlers.ts b/src/languages/_dependencyInjection/commandHandlers.ts index 4e95dcae..16740ddc 100644 --- a/src/languages/_dependencyInjection/commandHandlers.ts +++ b/src/languages/_dependencyInjection/commandHandlers.ts @@ -1,18 +1,14 @@ import CreateCountryCommandHandler from '@src/languages/application/country/command/createCountryCommandHandler'; import CreateExpressionCommandHandler from '@src/languages/application/term/command/expression/createExpressionCommandHandler'; import DeleteTermCommandHandler from '@src/languages/application/term/command/deleteTermCommandHandler'; -import UpdateUserCommandHandler from '@src/languages/application/user/command/updateUserCommandHandler'; import CreateWordCommandHandler from '@src/languages/application/term/command/word/createWordCommandHandler'; import AddLikeTermCommandHandler from '@src/languages/application/term/command/addLikeTermCommandHandler'; import DislikeTermCommandHandler from '@src/languages/application/term/command/dislikeTermCommandHandler'; import UpdateWordCommandHandler from '@src/languages/application/term/command/word/updateWordCommandHandler'; -import SignupUserCommandHandler from '@src/languages/application/auth/command/signupUserCommandHandler'; export const commands = [ - SignupUserCommandHandler, CreateCountryCommandHandler, CreateExpressionCommandHandler, - UpdateUserCommandHandler, CreateWordCommandHandler, UpdateWordCommandHandler, DeleteTermCommandHandler, diff --git a/src/languages/_dependencyInjection/controllers.ts b/src/languages/_dependencyInjection/controllers.ts index b125fdbb..b63402c2 100644 --- a/src/languages/_dependencyInjection/controllers.ts +++ b/src/languages/_dependencyInjection/controllers.ts @@ -1,6 +1,3 @@ -import LoginPostController from '@src/languages/app/controllers/v1/auth/loginPostController'; -import RefreshTokenPostController from '@src/languages/app/controllers/v1/auth/refreshTokenPostController'; -import MeGetController from '@src/languages/app/controllers/v1/auth/meGetController'; import SearchTermsGetController from '@src/languages/app/controllers/v1/terms/searchTermsGetController'; import FindSuggestionsTermGetController from '@src/languages/app/controllers/v1/terms/findSuggestionsTermGetController'; import WordPostController from '@src/languages/app/controllers/v1/terms/words/wordPostController'; @@ -8,21 +5,14 @@ import ExpressionPostController from '@src/languages/app/controllers/v1/terms/ex import CountriesGetController from '@src/languages/app/controllers/v1/countries/countriesGetController'; import CountryGetController from '@src/languages/app/controllers/v1/countries/countryGetController'; import CountryPostController from '@src/languages/app/controllers/v1/countries/countryPostController'; -import UserPutController from '@src/languages/app/controllers/v1/user/userPutController'; import { SearchTermsSseController } from '@src/languages/app/controllers/v1/terms/searchTermsSseController'; import { HealthController } from '@src/languages/app/controllers/v1/health/healthGetController'; import LikeTermPostController from '@src/languages/app/controllers/v1/terms/likeTermPostController'; import DislikeTermPostController from '@src/languages/app/controllers/v1/terms/dislikeTermPostController'; import WordPutController from '@src/languages/app/controllers/v1/terms/words/wordPutController'; import TermGetController from '@src/languages/app/controllers/v1/terms/termGetController'; -import SignupPostController from '@src/languages/app/controllers/v1/auth/signupPostController'; -import UserGetController from '@src/languages/app/controllers/v1/user/userGetController'; export const controllers = [ - LoginPostController, - SignupPostController, - RefreshTokenPostController, - MeGetController, SearchTermsGetController, FindSuggestionsTermGetController, TermGetController, @@ -31,8 +21,6 @@ export const controllers = [ CountriesGetController, CountryGetController, CountryPostController, - UserGetController, - UserPutController, SearchTermsSseController, HealthController, LikeTermPostController, diff --git a/src/languages/_dependencyInjection/entitySchemas.ts b/src/languages/_dependencyInjection/entitySchemas.ts index 19f065df..bee4898b 100644 --- a/src/languages/_dependencyInjection/entitySchemas.ts +++ b/src/languages/_dependencyInjection/entitySchemas.ts @@ -1,7 +1,6 @@ import { CountrySchema } from '@src/languages/infrastructure/persistence/mikroOrm/entities/country'; import { ExpressionSchema } from '@src/languages/infrastructure/persistence/mikroOrm/entities/expression'; import { TermSchema } from '@src/languages/infrastructure/persistence/mikroOrm/entities/term'; -import { UserSchema } from '@src/languages/infrastructure/persistence/mikroOrm/entities/user'; import { WordSchema } from '@src/languages/infrastructure/persistence/mikroOrm/entities/word'; -export const entitySchemas = [UserSchema, CountrySchema, TermSchema, ExpressionSchema, WordSchema]; +export const entitySchemas = [CountrySchema, TermSchema, ExpressionSchema, WordSchema]; diff --git a/src/languages/_dependencyInjection/queryHandlers.ts b/src/languages/_dependencyInjection/queryHandlers.ts index 561f78db..b2caeee7 100644 --- a/src/languages/_dependencyInjection/queryHandlers.ts +++ b/src/languages/_dependencyInjection/queryHandlers.ts @@ -1,17 +1,13 @@ import FindCountryQueryHandler from '@src/languages/application/country/query/findCountryQueryHandler'; import FindCountriesQueryHandler from '@src/languages/application/country/query/findCountriesQueryHandler'; import SearchTermQueryHandler from '@src/languages/application/term/query/searchTermQueryHandler'; -import FindUserQueryHandler from '@src/languages/application/user/query/findUserQueryHandler'; import FindSuggestionsTermQueryHandler from '@src/languages/application/term/query/findSuggestionsTermQueryHandler'; import FindTermQueryHandler from '@src/languages/application/term/query/findTermQueryHandler'; -import GetUserSocialLoginQueryHandler from '@src/languages/application/auth/query/getUserSocialLoginQueryHandler'; export const queries = [ - GetUserSocialLoginQueryHandler, FindCountryQueryHandler, FindCountriesQueryHandler, SearchTermQueryHandler, - FindUserQueryHandler, FindSuggestionsTermQueryHandler, FindTermQueryHandler, ]; diff --git a/src/languages/_dependencyInjection/repositories.ts b/src/languages/_dependencyInjection/repositories.ts index 1e2edf08..5207cecb 100644 --- a/src/languages/_dependencyInjection/repositories.ts +++ b/src/languages/_dependencyInjection/repositories.ts @@ -1,7 +1,5 @@ import { COUNTRY_REPOSITORY } from '@src/languages/domain/country/countryRepository'; -import { USER_REPOSITORY } from '@src/languages/domain/user/userRepository'; import { TERM_REPOSITORY } from '@src/languages/domain/term/termRepository'; -import MikroOrmUserRepository from '@src/languages/infrastructure/persistence/mikroOrm/repositories/mikroOrmUserRepository'; import MikroOrmCountryRepository from '../infrastructure/persistence/mikroOrm/repositories/mikroOrmCountryRepository'; import MikroOrmTermRepository from '../infrastructure/persistence/mikroOrm/repositories/mikroOrmTermRepository'; @@ -14,8 +12,4 @@ export const repositories = [ provide: TERM_REPOSITORY, useClass: MikroOrmTermRepository, }, - { - provide: USER_REPOSITORY, - useClass: MikroOrmUserRepository, - }, ]; diff --git a/src/languages/application/term/command/addLikeTermCommandHandler.ts b/src/languages/application/term/command/addLikeTermCommandHandler.ts index 1aa4a854..22137a51 100644 --- a/src/languages/application/term/command/addLikeTermCommandHandler.ts +++ b/src/languages/application/term/command/addLikeTermCommandHandler.ts @@ -1,14 +1,14 @@ import { CommandHandler, ICommandHandler } from '@src/shared/domain/bus/commandBus/commandHandler'; import AddLikeTermCommand from '@src/languages/application/term/command/addLikeTermCommand'; import TermId from '@src/languages/domain/term/termId'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import TermRepository, { TERM_REPOSITORY } from '@src/languages/domain/term/termRepository'; import Term from '@src/languages/domain/term/term'; import TermDoesNotExistsException from '@src/languages/domain/term/termDoesNotExistsException'; -import UserRepository, { USER_REPOSITORY } from '@src/languages/domain/user/userRepository'; -import UserDoesNotExistsException from '@src/languages/domain/user/userDoesNotExistsException'; -import User from '@src/languages/domain/user/user'; +import UserRepository, { USER_REPOSITORY } from '@src/account/domain/user/userRepository'; +import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; +import User from '@src/account/domain/user/user'; import { ASYNC_EVENT_BUS, EventBus } from '@src/shared/domain/bus/eventBus/eventBus'; @CommandHandler(AddLikeTermCommand) diff --git a/src/languages/application/term/command/dislikeTermCommandHandler.ts b/src/languages/application/term/command/dislikeTermCommandHandler.ts index 6059e1fe..43efacdf 100644 --- a/src/languages/application/term/command/dislikeTermCommandHandler.ts +++ b/src/languages/application/term/command/dislikeTermCommandHandler.ts @@ -1,14 +1,14 @@ import { CommandHandler, ICommandHandler } from '@src/shared/domain/bus/commandBus/commandHandler'; import TermId from '@src/languages/domain/term/termId'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import DislikeTermCommand from '@src/languages/application/term/command/dislikeTermCommand'; import Term from '@src/languages/domain/term/term'; import TermDoesNotExistsException from '@src/languages/domain/term/termDoesNotExistsException'; -import User from '@src/languages/domain/user/user'; -import UserDoesNotExistsException from '@src/languages/domain/user/userDoesNotExistsException'; +import User from '@src/account/domain/user/user'; +import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import TermRepository, { TERM_REPOSITORY } from '@src/languages/domain/term/termRepository'; -import UserRepository, { USER_REPOSITORY } from '@src/languages/domain/user/userRepository'; +import UserRepository, { USER_REPOSITORY } from '@src/account/domain/user/userRepository'; import { ASYNC_EVENT_BUS, EventBus } from '@src/shared/domain/bus/eventBus/eventBus'; @CommandHandler(DislikeTermCommand) diff --git a/src/languages/application/term/command/expression/createExpressionCommandHandler.ts b/src/languages/application/term/command/expression/createExpressionCommandHandler.ts index b9b49a61..aabe09e9 100644 --- a/src/languages/application/term/command/expression/createExpressionCommandHandler.ts +++ b/src/languages/application/term/command/expression/createExpressionCommandHandler.ts @@ -3,7 +3,7 @@ import CreateExpressionCommand from './createExpressionCommand'; import Expression from '@src/languages/domain/term/expression/expression'; import CountryId from '@src/languages/domain/country/countryId'; import ExpressionTermCollection from '@src/languages/domain/term/expression/expressionTermCollection'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import { CommandHandler, ICommandHandler } from '@src/shared/domain/bus/commandBus/commandHandler'; import TermRepository, { TERM_REPOSITORY } from '@src/languages/domain/term/termRepository'; diff --git a/src/languages/application/term/command/word/createWordCommandHandler.ts b/src/languages/application/term/command/word/createWordCommandHandler.ts index 9bbe82c7..07518183 100644 --- a/src/languages/application/term/command/word/createWordCommandHandler.ts +++ b/src/languages/application/term/command/word/createWordCommandHandler.ts @@ -2,7 +2,7 @@ import { ASYNC_EVENT_BUS, EventBus } from '@src/shared/domain/bus/eventBus/event import CreateWordCommand from './createWordCommand'; import Word from '@src/languages/domain/term/word/word'; import CountryId from '@src/languages/domain/country/countryId'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import WordTermCollection from '@src/languages/domain/term/word/wordTermCollection'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import { CommandHandler, ICommandHandler } from '@src/shared/domain/bus/commandBus/commandHandler'; diff --git a/src/languages/application/term/command/word/updateWordCommandHandler.ts b/src/languages/application/term/command/word/updateWordCommandHandler.ts index e5b8a0b2..6f248fa2 100644 --- a/src/languages/application/term/command/word/updateWordCommandHandler.ts +++ b/src/languages/application/term/command/word/updateWordCommandHandler.ts @@ -1,7 +1,7 @@ import { CommandHandler, ICommandHandler } from '@src/shared/domain/bus/commandBus/commandHandler'; import UpdateWordCommand from '@src/languages/application/term/command/word/updateWordCommand'; import TermId from '@src/languages/domain/term/termId'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import CountryId from '@src/languages/domain/country/countryId'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import TermRepository, { TERM_REPOSITORY } from '@src/languages/domain/term/termRepository'; diff --git a/src/languages/application/term/query/findSuggestionsTermQueryHandler.ts b/src/languages/application/term/query/findSuggestionsTermQueryHandler.ts index f123212e..105157da 100644 --- a/src/languages/application/term/query/findSuggestionsTermQueryHandler.ts +++ b/src/languages/application/term/query/findSuggestionsTermQueryHandler.ts @@ -6,7 +6,7 @@ import FindSuggestionsTermQuery from '@src/languages/application/term/query/find import FindSuggestionsTermReadModel, { FIND_SUGGESTIONS_TERM_READ_MODEL, } from '@src/languages/application/term/query/findSuggestionsTermReadModel'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; @QueryHandler(FindSuggestionsTermQuery) export default class FindSuggestionsTermQueryHandler implements IQueryHandler { diff --git a/src/languages/application/term/query/findSuggestionsTermReadModel.ts b/src/languages/application/term/query/findSuggestionsTermReadModel.ts index 9f0c5f39..0baf2873 100644 --- a/src/languages/application/term/query/findSuggestionsTermReadModel.ts +++ b/src/languages/application/term/query/findSuggestionsTermReadModel.ts @@ -1,5 +1,5 @@ import { TermView } from '@src/languages/application/term/query/termView'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; interface FindSuggestionsTermReadModel { find(userId: UserId): Promise; diff --git a/src/languages/domain/term/expression/expression.ts b/src/languages/domain/term/expression/expression.ts index b7f36f29..26b26bed 100644 --- a/src/languages/domain/term/expression/expression.ts +++ b/src/languages/domain/term/expression/expression.ts @@ -1,5 +1,5 @@ import CountryId from '../../country/countryId'; -import UserId from '../../user/userId'; +import UserId from '@src/account/domain/user/userId'; import ExpressionTermCollection from './expressionTermCollection'; import ExpressionCreatedEvent from './expressionCreatedEvent'; import Term from '@src/languages/domain/term/term'; diff --git a/src/languages/domain/term/term.ts b/src/languages/domain/term/term.ts index e1594645..8ebaad1f 100644 --- a/src/languages/domain/term/term.ts +++ b/src/languages/domain/term/term.ts @@ -1,7 +1,7 @@ import TermType from '@src/languages/domain/term/termType'; import TermId from '@src/languages/domain/term/termId'; import CountryId from '@src/languages/domain/country/countryId'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import { AggregateRoot } from '@src/shared/domain/aggregate/aggregateRoot'; import TermLike from '@src/languages/domain/term/termLike'; import TermLikeAddedEvent from '@src/languages/domain/term/termLikeAddedEvent'; diff --git a/src/languages/domain/term/termLike.ts b/src/languages/domain/term/termLike.ts index 42584208..aa3b9573 100644 --- a/src/languages/domain/term/termLike.ts +++ b/src/languages/domain/term/termLike.ts @@ -1,4 +1,4 @@ -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import TermId from '@src/languages/domain/term/termId'; import TermLikeId from '@src/languages/domain/term/termLikeId'; diff --git a/src/languages/domain/term/word/word.ts b/src/languages/domain/term/word/word.ts index 6d112308..0a55f1f1 100644 --- a/src/languages/domain/term/word/word.ts +++ b/src/languages/domain/term/word/word.ts @@ -1,5 +1,5 @@ import CountryId from '../../country/countryId'; -import UserId from '../../user/userId'; +import UserId from '@src/account/domain/user/userId'; import WordCreatedEvent from './wordCreatedEvent'; import WordTermCollection from './wordTermCollection'; import Term from '@src/languages/domain/term/term'; diff --git a/src/languages/infrastructure/persistence/mikroOrm/entities/term.ts b/src/languages/infrastructure/persistence/mikroOrm/entities/term.ts index bfdf70bc..dd6d2244 100644 --- a/src/languages/infrastructure/persistence/mikroOrm/entities/term.ts +++ b/src/languages/infrastructure/persistence/mikroOrm/entities/term.ts @@ -3,9 +3,9 @@ import { EntitySchema } from '@mikro-orm/core'; import Term from '@src/languages/domain/term/term'; import { TermIdType } from '../types/termIdType'; import { CountryIdType } from '../types/countryIdType'; -import { UserIdType } from '../types/userIdType'; import { LikesCollectionType } from '../types/likesCollectionType'; import { TermTypeType } from '../types/termTypeType'; +import { UserIdType } from '@src/shared/infrastructure/persistence/mikroOrm/types/userIdType'; export const TermSchema = new EntitySchema({ class: Term, diff --git a/src/languages/infrastructure/persistence/mongo/readModels/mongoFindSuggestionsTermReadModel.ts b/src/languages/infrastructure/persistence/mongo/readModels/mongoFindSuggestionsTermReadModel.ts index 8cdb30b7..fa5c1df6 100644 --- a/src/languages/infrastructure/persistence/mongo/readModels/mongoFindSuggestionsTermReadModel.ts +++ b/src/languages/infrastructure/persistence/mongo/readModels/mongoFindSuggestionsTermReadModel.ts @@ -1,12 +1,12 @@ import FindSuggestionsTermReadModel from '@src/languages/application/term/query/findSuggestionsTermReadModel'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import { TermView } from '@src/languages/application/term/query/termView'; -import UserRepository, { USER_REPOSITORY } from '@src/languages/domain/user/userRepository'; +import UserRepository, { USER_REPOSITORY } from '@src/account/domain/user/userRepository'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import { Document } from 'mongodb'; import MongoConnection, { MONGO_CLIENT } from '@src/shared/infrastructure/persistence/mongo/mongoConnection'; -import User from '@src/languages/domain/user/user'; -import UserDoesNotExistsException from '@src/languages/domain/user/userDoesNotExistsException'; +import User from '@src/account/domain/user/user'; +import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; export default class MongoFindSuggestionsTermReadModel implements FindSuggestionsTermReadModel { constructor( diff --git a/src/languages/infrastructure/persistence/mikroOrm/types/userIdType.ts b/src/shared/infrastructure/persistence/mikroOrm/types/userIdType.ts similarity index 81% rename from src/languages/infrastructure/persistence/mikroOrm/types/userIdType.ts rename to src/shared/infrastructure/persistence/mikroOrm/types/userIdType.ts index b4eb6aca..f2be15b8 100644 --- a/src/languages/infrastructure/persistence/mikroOrm/types/userIdType.ts +++ b/src/shared/infrastructure/persistence/mikroOrm/types/userIdType.ts @@ -1,4 +1,4 @@ -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import { ValueObjectType } from '@src/shared/infrastructure/persistence/mikroOrm/types/valueObjectType'; export class UserIdType extends ValueObjectType { diff --git a/test/acceptance/languages/auth/getUserAcceptance.test.ts b/test/acceptance/account/auth/getUserAcceptance.test.ts similarity index 89% rename from test/acceptance/languages/auth/getUserAcceptance.test.ts rename to test/acceptance/account/auth/getUserAcceptance.test.ts index 870e585b..ac1e0e0e 100644 --- a/test/acceptance/languages/auth/getUserAcceptance.test.ts +++ b/test/acceptance/account/auth/getUserAcceptance.test.ts @@ -3,9 +3,9 @@ import { INestApplication } from '@nestjs/common'; import request = require('supertest'); import { MikroORM } from '@mikro-orm/core'; import { createApplication, truncateTables } from '@test/acceptance/createApplication'; -import { UserPrimitives } from '@src/languages/domain/user/user'; -import { UserMother } from '@test/unit/languages/domain/user/userMother'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import { UserPrimitives } from '@src/account/domain/user/user'; +import { UserMother } from '@test/unit/account/domain/user/userMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; describe('Get user feature', () => { let app: INestApplication; diff --git a/test/acceptance/languages/auth/signupAcceptance.test.ts b/test/acceptance/account/auth/signupAcceptance.test.ts similarity index 100% rename from test/acceptance/languages/auth/signupAcceptance.test.ts rename to test/acceptance/account/auth/signupAcceptance.test.ts diff --git a/test/acceptance/languages/term/getTermAcceptance.test.ts b/test/acceptance/languages/term/getTermAcceptance.test.ts index 3edb7078..9c4e3381 100644 --- a/test/acceptance/languages/term/getTermAcceptance.test.ts +++ b/test/acceptance/languages/term/getTermAcceptance.test.ts @@ -6,7 +6,7 @@ import { createApplication, truncateTables, USER_ID_LOGGED } from '@test/accepta import WordMother from '@test/unit/languages/domain/term/word/wordMother'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; import { WordPrimitives } from '@src/languages/domain/term/word/word'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; describe('Get term feature', () => { let app: INestApplication; diff --git a/test/acceptance/languages/term/updateWordAcceptance.test.ts b/test/acceptance/languages/term/updateWordAcceptance.test.ts index b1354e79..16bd4a1f 100644 --- a/test/acceptance/languages/term/updateWordAcceptance.test.ts +++ b/test/acceptance/languages/term/updateWordAcceptance.test.ts @@ -8,7 +8,7 @@ import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; import { CountryIdMother } from '@test/unit/languages/domain/country/countryIdMother'; import WordTermMother from '@test/unit/languages/domain/term/word/wordTermMother'; import WordTermCollectionMother from '@test/unit/languages/domain/term/word/wordTermCollectionMother'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; describe('Update word feature', () => { let app: INestApplication; diff --git a/test/unit/languages/app/controllers/v1/auth/signupPostController.test.ts b/test/unit/account/app/controllers/v1/auth/signupPostController.test.ts similarity index 85% rename from test/unit/languages/app/controllers/v1/auth/signupPostController.test.ts rename to test/unit/account/app/controllers/v1/auth/signupPostController.test.ts index fa7b2a48..e9fb10b4 100644 --- a/test/unit/languages/app/controllers/v1/auth/signupPostController.test.ts +++ b/test/unit/account/app/controllers/v1/auth/signupPostController.test.ts @@ -1,7 +1,7 @@ import { beforeAll, describe, it, expect, jest } from '@jest/globals'; -import SignupPostController from '@src/languages/app/controllers/v1/auth/signupPostController'; +import SignupPostController from '@src/account/app/controllers/v1/auth/signupPostController'; import { CommandBus } from '@src/shared/domain/bus/commandBus/commandBus'; -import { SignupUserCommandMother } from '@test/unit/languages/application/auth/command/signupUserCommandMother'; +import { SignupUserCommandMother } from '@test/unit/account/application/auth/command/signupUserCommandMother'; describe('Given a SignupPostController to handle', () => { let sut: SignupPostController; diff --git a/test/unit/languages/app/controllers/v1/user/userGetController.test.ts b/test/unit/account/app/controllers/v1/user/userGetController.test.ts similarity index 84% rename from test/unit/languages/app/controllers/v1/user/userGetController.test.ts rename to test/unit/account/app/controllers/v1/user/userGetController.test.ts index 130e358f..89e2e0a7 100644 --- a/test/unit/languages/app/controllers/v1/user/userGetController.test.ts +++ b/test/unit/account/app/controllers/v1/user/userGetController.test.ts @@ -1,6 +1,6 @@ import { beforeAll, describe, it, expect, jest } from '@jest/globals'; -import UserGetController from '@src/languages/app/controllers/v1/user/userGetController'; -import { UserMother } from '@test/unit/languages/domain/user/userMother'; +import UserGetController from '@src/account/app/controllers/v1/user/userGetController'; +import { UserMother } from '@test/unit/account/domain/user/userMother'; import { QueryBus } from '@src/shared/domain/bus/queryBus/queryBus'; describe('Given a UserGetController to handle', () => { diff --git a/test/unit/languages/application/auth/command/signupUserCommandHandler.test.ts b/test/unit/account/application/auth/command/signupUserCommandHandler.test.ts similarity index 77% rename from test/unit/languages/application/auth/command/signupUserCommandHandler.test.ts rename to test/unit/account/application/auth/command/signupUserCommandHandler.test.ts index 01cbc354..176e559d 100644 --- a/test/unit/languages/application/auth/command/signupUserCommandHandler.test.ts +++ b/test/unit/account/application/auth/command/signupUserCommandHandler.test.ts @@ -1,14 +1,14 @@ import { beforeEach, beforeAll, describe, expect, it, jest } from '@jest/globals'; import { EventBusMock } from '@test/unit/shared/domain/buses/eventBus/eventBusMock'; -import SignupUserCommandHandler from '@src/languages/application/auth/command/signupUserCommandHandler'; -import { SignupUserCommandMother } from '@test/unit/languages/application/auth/command/signupUserCommandMother'; -import SignupUserCommand from '@src/languages/application/auth/command/signupUserCommand'; -import { UserRepositoryMock } from '@test/unit/languages/domain/user/userRepositoryMock'; -import { UserMother } from '@test/unit/languages/domain/user/userMother'; -import UserAlreadyExistsException from '@src/languages/domain/user/userAlreadyExistsException'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; -import UserCreatedEvent from '@src/languages/domain/user/userCreatedEvent'; -import { UserCreatedEventMother } from '@test/unit/languages/domain/user/userCreatedEventMother'; +import SignupUserCommandHandler from '@src/account/application/auth/command/signupUserCommandHandler'; +import { SignupUserCommandMother } from '@test/unit/account/application/auth/command/signupUserCommandMother'; +import SignupUserCommand from '@src/account/application/auth/command/signupUserCommand'; +import { UserRepositoryMock } from '@test/unit/account/domain/user/userRepositoryMock'; +import { UserMother } from '@test/unit/account/domain/user/userMother'; +import UserAlreadyExistsException from '@src/account/domain/user/userAlreadyExistsException'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; +import UserCreatedEvent from '@src/account/domain/user/userCreatedEvent'; +import { UserCreatedEventMother } from '@test/unit/account/domain/user/userCreatedEventMother'; describe('Given a SignupUserCommandHandler to handle', () => { let userRepository: UserRepositoryMock; diff --git a/test/unit/languages/application/auth/command/signupUserCommandMother.ts b/test/unit/account/application/auth/command/signupUserCommandMother.ts similarity index 87% rename from test/unit/languages/application/auth/command/signupUserCommandMother.ts rename to test/unit/account/application/auth/command/signupUserCommandMother.ts index b652cc29..9a920890 100644 --- a/test/unit/languages/application/auth/command/signupUserCommandMother.ts +++ b/test/unit/account/application/auth/command/signupUserCommandMother.ts @@ -1,5 +1,5 @@ import faker from 'faker'; -import SignupUserCommand from '@src/languages/application/auth/command/signupUserCommand'; +import SignupUserCommand from '@src/account/application/auth/command/signupUserCommand'; interface SignupUserCommandProps { id?: string; diff --git a/test/unit/languages/application/auth/query/getUserSocialLoginQueryHandler.test.ts b/test/unit/account/application/auth/query/getUserSocialLoginQueryHandler.test.ts similarity index 91% rename from test/unit/languages/application/auth/query/getUserSocialLoginQueryHandler.test.ts rename to test/unit/account/application/auth/query/getUserSocialLoginQueryHandler.test.ts index dcf5d874..1a8acf85 100644 --- a/test/unit/languages/application/auth/query/getUserSocialLoginQueryHandler.test.ts +++ b/test/unit/account/application/auth/query/getUserSocialLoginQueryHandler.test.ts @@ -1,9 +1,9 @@ import { beforeEach, beforeAll, describe, expect, it, jest } from '@jest/globals'; -import GetUserSocialLoginQueryHandler from '@src/languages/application/auth/query/getUserSocialLoginQueryHandler'; +import GetUserSocialLoginQueryHandler from '@src/account/application/auth/query/getUserSocialLoginQueryHandler'; import { GetUserSocialLoginQueryMother } from './getUserSocialLoginQueryMother'; import LoginException from '@src/shared/domain/auth/loginException'; import { SocialAuthenticationVerifierMock } from '@test/unit/shared/domain/auth/socialAuthenticationVerifierMock'; -import GetUserSocialLoginQuery from '@src/languages/application/auth/query/getUserSocialLoginQuery'; +import GetUserSocialLoginQuery from '@src/account/application/auth/query/getUserSocialLoginQuery'; import { UserAuthenticatorMock } from '@test/unit/shared/domain/auth/userAuthenticatorMock'; describe('Given a GetUserSocialLoginQueryHandler to handle', () => { diff --git a/test/unit/languages/application/auth/query/getUserSocialLoginQueryMother.ts b/test/unit/account/application/auth/query/getUserSocialLoginQueryMother.ts similarity index 86% rename from test/unit/languages/application/auth/query/getUserSocialLoginQueryMother.ts rename to test/unit/account/application/auth/query/getUserSocialLoginQueryMother.ts index c596b54c..6684c742 100644 --- a/test/unit/languages/application/auth/query/getUserSocialLoginQueryMother.ts +++ b/test/unit/account/application/auth/query/getUserSocialLoginQueryMother.ts @@ -1,4 +1,4 @@ -import GetUserSocialLoginQuery from '@src/languages/application/auth/query/getUserSocialLoginQuery'; +import GetUserSocialLoginQuery from '@src/account/application/auth/query/getUserSocialLoginQuery'; import faker from 'faker'; interface GetUserSocialLoginQueryProps { diff --git a/test/unit/languages/domain/user/userCreatedEventMother.ts b/test/unit/account/domain/user/userCreatedEventMother.ts similarity index 67% rename from test/unit/languages/domain/user/userCreatedEventMother.ts rename to test/unit/account/domain/user/userCreatedEventMother.ts index dc9a1052..d61d9774 100644 --- a/test/unit/languages/domain/user/userCreatedEventMother.ts +++ b/test/unit/account/domain/user/userCreatedEventMother.ts @@ -1,6 +1,6 @@ import { expect } from '@jest/globals'; -import SignupUserCommand from '@src/languages/application/auth/command/signupUserCommand'; -import UserCreatedEvent from '@src/languages/domain/user/userCreatedEvent'; +import SignupUserCommand from '@src/account/application/auth/command/signupUserCommand'; +import UserCreatedEvent from '@src/account/domain/user/userCreatedEvent'; export class UserCreatedEventMother { static createFromSignupUserCommand(command: SignupUserCommand): UserCreatedEvent { diff --git a/test/unit/languages/domain/user/userIdMother.ts b/test/unit/account/domain/user/userIdMother.ts similarity index 73% rename from test/unit/languages/domain/user/userIdMother.ts rename to test/unit/account/domain/user/userIdMother.ts index 20278fe6..6910af43 100644 --- a/test/unit/languages/domain/user/userIdMother.ts +++ b/test/unit/account/domain/user/userIdMother.ts @@ -1,4 +1,4 @@ -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import faker from 'faker'; export class UserIdMother { diff --git a/test/unit/languages/domain/user/userMother.ts b/test/unit/account/domain/user/userMother.ts similarity index 85% rename from test/unit/languages/domain/user/userMother.ts rename to test/unit/account/domain/user/userMother.ts index f549601c..a7935d49 100644 --- a/test/unit/languages/domain/user/userMother.ts +++ b/test/unit/account/domain/user/userMother.ts @@ -1,5 +1,5 @@ -import User from '@src/languages/domain/user/user'; -import UserId from '@src/languages/domain/user/userId'; +import User from '@src/account/domain/user/user'; +import UserId from '@src/account/domain/user/userId'; import faker from 'faker'; import { UserIdMother } from './userIdMother'; diff --git a/test/unit/languages/domain/user/userRepositoryMock.ts b/test/unit/account/domain/user/userRepositoryMock.ts similarity index 84% rename from test/unit/languages/domain/user/userRepositoryMock.ts rename to test/unit/account/domain/user/userRepositoryMock.ts index 68fe6692..e38b16ef 100644 --- a/test/unit/languages/domain/user/userRepositoryMock.ts +++ b/test/unit/account/domain/user/userRepositoryMock.ts @@ -1,6 +1,6 @@ -import User from '@src/languages/domain/user/user'; -import UserRepository from '@src/languages/domain/user/userRepository'; -import UserId from '@src/languages/domain/user/userId'; +import User from '@src/account/domain/user/user'; +import UserRepository from '@src/account/domain/user/userRepository'; +import UserId from '@src/account/domain/user/userId'; import Email from '@src/shared/domain/valueObjects/email'; export class UserRepositoryMock implements UserRepository { diff --git a/test/unit/languages/application/term/command/addLikeTermCommandHandler.test.ts b/test/unit/languages/application/term/command/addLikeTermCommandHandler.test.ts index 31b59265..a5e4c2e5 100644 --- a/test/unit/languages/application/term/command/addLikeTermCommandHandler.test.ts +++ b/test/unit/languages/application/term/command/addLikeTermCommandHandler.test.ts @@ -6,11 +6,11 @@ import InvalidArgumentException from '@src/shared/domain/exceptions/invalidArgum import { TermRepositoryMock } from '@test/unit/languages/domain/term/termRepositoryMock'; import WordMother from '@test/unit/languages/domain/term/word/wordMother'; import TermDoesNotExistsException from '@src/languages/domain/term/termDoesNotExistsException'; -import { UserRepositoryMock } from '@test/unit/languages/domain/user/userRepositoryMock'; -import UserDoesNotExistsException from '@src/languages/domain/user/userDoesNotExistsException'; +import { UserRepositoryMock } from '@test/unit/account/domain/user/userRepositoryMock'; +import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; -import { UserMother } from '@test/unit/languages/domain/user/userMother'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import { UserMother } from '@test/unit/account/domain/user/userMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; import { EventBusMock } from '@test/unit/shared/domain/buses/eventBus/eventBusMock'; import { TermLikeAddedEventMother } from '@test/unit/languages/domain/term/termLikeAddedEventMother'; import TermLikeMother from '@test/unit/languages/domain/term/termLikeMother'; diff --git a/test/unit/languages/application/term/command/addLikeTermCommandMother.ts b/test/unit/languages/application/term/command/addLikeTermCommandMother.ts index 975ada70..41e37d4c 100644 --- a/test/unit/languages/application/term/command/addLikeTermCommandMother.ts +++ b/test/unit/languages/application/term/command/addLikeTermCommandMother.ts @@ -1,6 +1,6 @@ import AddLikeTermCommand from '@src/languages/application/term/command/addLikeTermCommand'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; interface AddLikeTermCommandProps { termId?: string; diff --git a/test/unit/languages/application/term/command/dislikeTermCommandHandler.test.ts b/test/unit/languages/application/term/command/dislikeTermCommandHandler.test.ts index ab6d84af..8bb99a8d 100644 --- a/test/unit/languages/application/term/command/dislikeTermCommandHandler.test.ts +++ b/test/unit/languages/application/term/command/dislikeTermCommandHandler.test.ts @@ -4,13 +4,13 @@ import DislikeTermCommandHandler from '@src/languages/application/term/command/d import { DislikeTermCommandMother } from '@test/unit/languages/application/term/command/dislikeTermCommandMother'; import DislikeTermCommand from '@src/languages/application/term/command/dislikeTermCommand'; import { TermRepositoryMock } from '@test/unit/languages/domain/term/termRepositoryMock'; -import { UserRepositoryMock } from '@test/unit/languages/domain/user/userRepositoryMock'; +import { UserRepositoryMock } from '@test/unit/account/domain/user/userRepositoryMock'; import TermDoesNotExistsException from '@src/languages/domain/term/termDoesNotExistsException'; import WordMother from '@test/unit/languages/domain/term/word/wordMother'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; -import UserDoesNotExistsException from '@src/languages/domain/user/userDoesNotExistsException'; -import { UserMother } from '@test/unit/languages/domain/user/userMother'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; +import { UserMother } from '@test/unit/account/domain/user/userMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; import { EventBusMock } from '@test/unit/shared/domain/buses/eventBus/eventBusMock'; import { TermDislikedEventMother } from '@test/unit/languages/domain/term/termDislikedEventMother'; import Word from '@src/languages/domain/term/word/word'; diff --git a/test/unit/languages/application/term/command/dislikeTermCommandMother.ts b/test/unit/languages/application/term/command/dislikeTermCommandMother.ts index 59b12ccb..2f709937 100644 --- a/test/unit/languages/application/term/command/dislikeTermCommandMother.ts +++ b/test/unit/languages/application/term/command/dislikeTermCommandMother.ts @@ -1,6 +1,6 @@ import DislikeTermCommand from '@src/languages/application/term/command/dislikeTermCommand'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; interface DislikeTermCommandProps { termId?: string; diff --git a/test/unit/languages/application/term/command/word/updateWordCommandHandler.test.ts b/test/unit/languages/application/term/command/word/updateWordCommandHandler.test.ts index 5eef7e9f..777ce4e3 100644 --- a/test/unit/languages/application/term/command/word/updateWordCommandHandler.test.ts +++ b/test/unit/languages/application/term/command/word/updateWordCommandHandler.test.ts @@ -6,7 +6,7 @@ import UpdateWordCommand from '@src/languages/application/term/command/word/upda import TermDoesNotExistsException from '@src/languages/domain/term/termDoesNotExistsException'; import { TermRepositoryMock } from '@test/unit/languages/domain/term/termRepositoryMock'; import WordMother from '@test/unit/languages/domain/term/word/wordMother'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; import TermDoesNotBelongToUserException from '@src/languages/domain/term/termDoesNotBelongToUserException'; import Word from '@src/languages/domain/term/word/word'; diff --git a/test/unit/languages/application/term/query/findSuggestionsTermReadModelMock.ts b/test/unit/languages/application/term/query/findSuggestionsTermReadModelMock.ts index 560214c4..148625e3 100644 --- a/test/unit/languages/application/term/query/findSuggestionsTermReadModelMock.ts +++ b/test/unit/languages/application/term/query/findSuggestionsTermReadModelMock.ts @@ -1,5 +1,5 @@ import { TermView } from '@src/languages/application/term/query/termView'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import FindSuggestionsTermReadModel from '@src/languages/application/term/query/findSuggestionsTermReadModel'; export class FindSuggestionsTermReadModelMock implements FindSuggestionsTermReadModel { diff --git a/test/unit/languages/domain/term/expression/expressionMother.ts b/test/unit/languages/domain/term/expression/expressionMother.ts index 8782ddef..1fab56ec 100644 --- a/test/unit/languages/domain/term/expression/expressionMother.ts +++ b/test/unit/languages/domain/term/expression/expressionMother.ts @@ -1,4 +1,4 @@ -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import { CountryIdMother } from '../../country/countryIdMother'; import CreateExpressionCommand from '@src/languages/application/term/command/expression/createExpressionCommand'; import Expression from '@src/languages/domain/term/expression/expression'; @@ -8,7 +8,7 @@ import ExpressionTermCollectionMother from './expressionTermCollectionMother'; import faker from 'faker'; import CountryId from '@src/languages/domain/country/countryId'; import ExpressionTermCollection from '@src/languages/domain/term/expression/expressionTermCollection'; -import { UserIdMother } from '../../user/userIdMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; import TermId from '@src/languages/domain/term/termId'; import TermType, { TermTypeEnum } from '@src/languages/domain/term/termType'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; diff --git a/test/unit/languages/domain/term/termDislikedEventMother.ts b/test/unit/languages/domain/term/termDislikedEventMother.ts index b4b10d9e..a6408c78 100644 --- a/test/unit/languages/domain/term/termDislikedEventMother.ts +++ b/test/unit/languages/domain/term/termDislikedEventMother.ts @@ -1,7 +1,7 @@ import { expect } from '@jest/globals'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; import TermDislikedEvent from '@src/languages/domain/term/termDislikedEvent'; type TermLikeAddedEventProps = { diff --git a/test/unit/languages/domain/term/termLikeAddedEventMother.ts b/test/unit/languages/domain/term/termLikeAddedEventMother.ts index e52d0c19..1f33a20a 100644 --- a/test/unit/languages/domain/term/termLikeAddedEventMother.ts +++ b/test/unit/languages/domain/term/termLikeAddedEventMother.ts @@ -1,7 +1,7 @@ import { expect } from '@jest/globals'; import TermLikeAddedEvent from '@src/languages/domain/term/termLikeAddedEvent'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; import faker from 'faker'; type TermLikeAddedEventProps = { diff --git a/test/unit/languages/domain/term/termLikeMother.ts b/test/unit/languages/domain/term/termLikeMother.ts index 3c640989..67941077 100644 --- a/test/unit/languages/domain/term/termLikeMother.ts +++ b/test/unit/languages/domain/term/termLikeMother.ts @@ -1,7 +1,7 @@ import faker from 'faker'; -import { UserIdMother } from '@test/unit/languages/domain/user/userIdMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; import TermLike from '@src/languages/domain/term/termLike'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import TermId from '@src/languages/domain/term/termId'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; import TermLikeId from '@src/languages/domain/term/termLikeId'; diff --git a/test/unit/languages/domain/term/word/wordMother.ts b/test/unit/languages/domain/term/word/wordMother.ts index a5f23d67..cc2d8516 100644 --- a/test/unit/languages/domain/term/word/wordMother.ts +++ b/test/unit/languages/domain/term/word/wordMother.ts @@ -1,13 +1,13 @@ import CreateWordCommand from '@src/languages/application/term/command/word/createWordCommand'; import Word from '@src/languages/domain/term/word/word'; -import UserId from '@src/languages/domain/user/userId'; +import UserId from '@src/account/domain/user/userId'; import { CountryIdMother } from '../../country/countryIdMother'; import WordTermCollectionMother from './wordTermCollectionMother'; import WordTerm from '@src/languages/domain/term/word/wordTerm'; import WordTermMother, { WordTermMotherProps } from './wordTermMother'; import CountryId from '@src/languages/domain/country/countryId'; import WordTermCollection from '@src/languages/domain/term/word/wordTermCollection'; -import { UserIdMother } from '../../user/userIdMother'; +import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; import faker from 'faker'; import TermId from '@src/languages/domain/term/termId'; import TermType, { TermTypeEnum } from '@src/languages/domain/term/termType'; From cbe5bbe5720ecacde9bca5893e603149d41f74f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Sat, 14 Dec 2024 16:06:31 +0100 Subject: [PATCH 02/11] Add nest axios #172 --- package-lock.json | 33 ++++++++++++++++++++++++++------- package.json | 3 ++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index ca8c9bac..28a0e8f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@mikro-orm/migrations": "^6.3.8", "@mikro-orm/nestjs": "^6.0.2", "@mikro-orm/postgresql": "^6.3.8", + "@nestjs/axios": "^3.1.3", "@nestjs/common": "^10.3.10", "@nestjs/config": "^3.2.3", "@nestjs/core": "^10.4.4", @@ -25,7 +26,7 @@ "@nestjs/swagger": "^7.4.2", "amqp-connection-manager": "^4.1.14", "amqplib": "^0.10.3", - "axios": "^1.7.4", + "axios": "^1.7.9", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "dotenv": "^16.4.5", @@ -2259,6 +2260,17 @@ "sparse-bitfield": "^3.0.3" } }, + "node_modules/@nestjs/axios": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/@nestjs/axios/-/axios-3.1.3.tgz", + "integrity": "sha512-RZ/63c1tMxGLqyG3iOCVt7A72oy4x1eM6QEhd4KzCYpaVWW0igq0WSREeRoEZhIxRcZfDfIIkvsOMiM7yfVGZQ==", + "license": "MIT", + "peerDependencies": { + "@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0", + "axios": "^1.3.1", + "rxjs": "^6.0.0 || ^7.0.0" + } + }, "node_modules/@nestjs/cli": { "version": "10.4.8", "resolved": "https://registry.npmjs.org/@nestjs/cli/-/cli-10.4.8.tgz", @@ -4399,9 +4411,10 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.7.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", - "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", + "version": "1.7.9", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", + "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", + "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -13213,6 +13226,12 @@ "sparse-bitfield": "^3.0.3" } }, + "@nestjs/axios": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/@nestjs/axios/-/axios-3.1.3.tgz", + "integrity": "sha512-RZ/63c1tMxGLqyG3iOCVt7A72oy4x1eM6QEhd4KzCYpaVWW0igq0WSREeRoEZhIxRcZfDfIIkvsOMiM7yfVGZQ==", + "requires": {} + }, "@nestjs/cli": { "version": "10.4.8", "resolved": "https://registry.npmjs.org/@nestjs/cli/-/cli-10.4.8.tgz", @@ -14781,9 +14800,9 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "axios": { - "version": "1.7.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", - "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", + "version": "1.7.9", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", + "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", "requires": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/package.json b/package.json index 074275e3..8117e478 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@mikro-orm/migrations": "^6.3.8", "@mikro-orm/nestjs": "^6.0.2", "@mikro-orm/postgresql": "^6.3.8", + "@nestjs/axios": "^3.1.3", "@nestjs/common": "^10.3.10", "@nestjs/config": "^3.2.3", "@nestjs/core": "^10.4.4", @@ -72,7 +73,7 @@ "@nestjs/swagger": "^7.4.2", "amqp-connection-manager": "^4.1.14", "amqplib": "^0.10.3", - "axios": "^1.7.4", + "axios": "^1.7.9", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "dotenv": "^16.4.5", From 63ab1518f50e7e5a50c7278a71f21a29103d306f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Mon, 16 Dec 2024 21:01:17 +0100 Subject: [PATCH 03/11] Add collaborator domain #172 --- .env.example | 1 + .env.test | 1 + .../_dependencyInjection/repositories.ts | 6 +++ .../_dependencyInjection/services.ts | 5 ++ .../term/command/addLikeTermCommandHandler.ts | 28 ++++++----- .../term/command/dislikeTermCommandHandler.ts | 28 ++++++----- .../domain/collaborator/collaborator.ts | 36 +++++++++++++ .../collaboratorDoesNotExistsException.ts | 7 +++ .../domain/collaborator/collaboratorId.ts | 11 ++++ .../collaborator/collaboratorRepository.ts | 10 ++++ .../http/TranslatingCollaboratorRepository.ts | 14 ++++++ .../http/collaboratorTranslator.ts | 9 ++++ .../http/httpCollaboratorAdapter.ts | 18 +++++++ .../mongoFindSuggestionsTermReadModel.ts | 25 ++++++---- src/languages/language.module.ts | 19 ++++++- .../command/addLikeTermCommandHandler.test.ts | 50 ++++++++++--------- .../command/dislikeTermCommandHandler.test.ts | 48 +++++++++--------- .../collaborator/collaboratorIdMother.ts | 8 +++ .../domain/collaborator/collaboratorMother.ts | 24 +++++++++ .../collaboratorRepositoryMock.ts | 25 ++++++++++ 20 files changed, 287 insertions(+), 86 deletions(-) create mode 100644 src/languages/_dependencyInjection/services.ts create mode 100644 src/languages/domain/collaborator/collaborator.ts create mode 100644 src/languages/domain/collaborator/collaboratorDoesNotExistsException.ts create mode 100644 src/languages/domain/collaborator/collaboratorId.ts create mode 100644 src/languages/domain/collaborator/collaboratorRepository.ts create mode 100644 src/languages/infrastructure/persistence/http/TranslatingCollaboratorRepository.ts create mode 100644 src/languages/infrastructure/persistence/http/collaboratorTranslator.ts create mode 100644 src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts create mode 100644 test/unit/languages/domain/collaborator/collaboratorIdMother.ts create mode 100644 test/unit/languages/domain/collaborator/collaboratorMother.ts create mode 100644 test/unit/languages/domain/collaborator/collaboratorRepositoryMock.ts diff --git a/.env.example b/.env.example index ad219648..c6baa0d8 100644 --- a/.env.example +++ b/.env.example @@ -15,3 +15,4 @@ RABBITMQ_DEFAULT_USER=app RABBITMQ_DEFAULT_PASS=rabbit_app RABBITMQ_EVENTS_QUEUE='events_queue' RABBITMQ_HOST="amqp://${RABBITMQ_DEFAULT_USER}:${RABBITMQ_DEFAULT_PASS}@rabbitmq:5672" +SERVER_URL=http://localhost:4000 diff --git a/.env.test b/.env.test index 7816764c..3cf89f74 100644 --- a/.env.test +++ b/.env.test @@ -15,3 +15,4 @@ RABBITMQ_DEFAULT_USER=app RABBITMQ_DEFAULT_PASS=rabbit_app RABBITMQ_EVENTS_QUEUE='events_queue' RABBITMQ_HOST="amqp://app:rabbit_app@localhost:5672" +SERVER_URL=http://localhost:4000 diff --git a/src/languages/_dependencyInjection/repositories.ts b/src/languages/_dependencyInjection/repositories.ts index 5207cecb..356d2fc9 100644 --- a/src/languages/_dependencyInjection/repositories.ts +++ b/src/languages/_dependencyInjection/repositories.ts @@ -2,6 +2,8 @@ import { COUNTRY_REPOSITORY } from '@src/languages/domain/country/countryReposit import { TERM_REPOSITORY } from '@src/languages/domain/term/termRepository'; import MikroOrmCountryRepository from '../infrastructure/persistence/mikroOrm/repositories/mikroOrmCountryRepository'; import MikroOrmTermRepository from '../infrastructure/persistence/mikroOrm/repositories/mikroOrmTermRepository'; +import { COLLABORATOR_REPOSITORY } from '@src/languages/domain/collaborator/collaboratorRepository'; +import { TranslatingCollaboratorRepository } from '@src/languages/infrastructure/persistence/http/TranslatingCollaboratorRepository'; export const repositories = [ { @@ -12,4 +14,8 @@ export const repositories = [ provide: TERM_REPOSITORY, useClass: MikroOrmTermRepository, }, + { + provide: COLLABORATOR_REPOSITORY, + useClass: TranslatingCollaboratorRepository, + }, ]; diff --git a/src/languages/_dependencyInjection/services.ts b/src/languages/_dependencyInjection/services.ts new file mode 100644 index 00000000..0b35a596 --- /dev/null +++ b/src/languages/_dependencyInjection/services.ts @@ -0,0 +1,5 @@ +import { HttpCollaboratorAdapter } from '@src/languages/infrastructure/persistence/http/httpCollaboratorAdapter'; + +export const services = [ + HttpCollaboratorAdapter +]; \ No newline at end of file diff --git a/src/languages/application/term/command/addLikeTermCommandHandler.ts b/src/languages/application/term/command/addLikeTermCommandHandler.ts index 22137a51..9b9ebd0d 100644 --- a/src/languages/application/term/command/addLikeTermCommandHandler.ts +++ b/src/languages/application/term/command/addLikeTermCommandHandler.ts @@ -1,32 +1,34 @@ import { CommandHandler, ICommandHandler } from '@src/shared/domain/bus/commandBus/commandHandler'; import AddLikeTermCommand from '@src/languages/application/term/command/addLikeTermCommand'; import TermId from '@src/languages/domain/term/termId'; -import UserId from '@src/account/domain/user/userId'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import TermRepository, { TERM_REPOSITORY } from '@src/languages/domain/term/termRepository'; import Term from '@src/languages/domain/term/term'; import TermDoesNotExistsException from '@src/languages/domain/term/termDoesNotExistsException'; -import UserRepository, { USER_REPOSITORY } from '@src/account/domain/user/userRepository'; -import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; -import User from '@src/account/domain/user/user'; import { ASYNC_EVENT_BUS, EventBus } from '@src/shared/domain/bus/eventBus/eventBus'; +import CollaboratorRepository, { + COLLABORATOR_REPOSITORY, +} from '@src/languages/domain/collaborator/collaboratorRepository'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; +import Collaborator from '@src/languages/domain/collaborator/collaborator'; +import CollaboratorDoesNotExistsException from '@src/languages/domain/collaborator/collaboratorDoesNotExistsException'; @CommandHandler(AddLikeTermCommand) export default class AddLikeTermCommandHandler implements ICommandHandler { constructor( @Inject(TERM_REPOSITORY) private readonly termRepository: TermRepository, - @Inject(USER_REPOSITORY) private readonly userRepository: UserRepository, + @Inject(COLLABORATOR_REPOSITORY) private readonly collaboratorRepository: CollaboratorRepository, @Inject(ASYNC_EVENT_BUS) private readonly eventBus: EventBus, ) {} async execute(command: AddLikeTermCommand): Promise { const termId = TermId.of(command.termId); - const userId = UserId.of(command.userId); + const collaboratorId = CollaboratorId.of(command.userId); const term = await this.getTerm(termId); - const user = await this.getUser(userId); + const collaborator = await this.getCollaborator(collaboratorId); - term.addLike(userId, user.getName(), user.getPhoto()); + term.addLike(collaboratorId, collaborator.getName(), collaborator.getPhoto()); this.termRepository.save(term); @@ -42,12 +44,12 @@ export default class AddLikeTermCommandHandler implements ICommandHandler { - const user = await this.userRepository.findById(userId); - if (!user) { - throw new UserDoesNotExistsException(userId.toString()); + private async getCollaborator(collaboratorId: CollaboratorId): Promise { + const collaborator = await this.collaboratorRepository.findById(collaboratorId); + if (!collaborator) { + throw new CollaboratorDoesNotExistsException(collaboratorId.toString()); } - return user; + return collaborator; } } diff --git a/src/languages/application/term/command/dislikeTermCommandHandler.ts b/src/languages/application/term/command/dislikeTermCommandHandler.ts index 43efacdf..786bd100 100644 --- a/src/languages/application/term/command/dislikeTermCommandHandler.ts +++ b/src/languages/application/term/command/dislikeTermCommandHandler.ts @@ -1,32 +1,34 @@ import { CommandHandler, ICommandHandler } from '@src/shared/domain/bus/commandBus/commandHandler'; import TermId from '@src/languages/domain/term/termId'; -import UserId from '@src/account/domain/user/userId'; import DislikeTermCommand from '@src/languages/application/term/command/dislikeTermCommand'; import Term from '@src/languages/domain/term/term'; import TermDoesNotExistsException from '@src/languages/domain/term/termDoesNotExistsException'; -import User from '@src/account/domain/user/user'; -import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import TermRepository, { TERM_REPOSITORY } from '@src/languages/domain/term/termRepository'; -import UserRepository, { USER_REPOSITORY } from '@src/account/domain/user/userRepository'; import { ASYNC_EVENT_BUS, EventBus } from '@src/shared/domain/bus/eventBus/eventBus'; +import CollaboratorRepository, { + COLLABORATOR_REPOSITORY, +} from '@src/languages/domain/collaborator/collaboratorRepository'; +import Collaborator from '@src/languages/domain/collaborator/collaborator'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; +import CollaboratorDoesNotExistsException from '@src/languages/domain/collaborator/collaboratorDoesNotExistsException'; @CommandHandler(DislikeTermCommand) export default class DislikeTermCommandHandler implements ICommandHandler { constructor( @Inject(TERM_REPOSITORY) private readonly termRepository: TermRepository, - @Inject(USER_REPOSITORY) private readonly userRepository: UserRepository, + @Inject(COLLABORATOR_REPOSITORY) private readonly collaboratorRepository: CollaboratorRepository, @Inject(ASYNC_EVENT_BUS) private readonly eventBus: EventBus, ) {} async execute(command: DislikeTermCommand): Promise { const termId = TermId.of(command.termId); - const userId = UserId.of(command.userId); + const collaboratorId = CollaboratorId.of(command.userId); const term = await this.getTerm(termId); - const user = await this.getUser(userId); + const collaborator = await this.getCollaborator(collaboratorId); - term.dislike(userId, user.getName(), user.getPhoto()); + term.dislike(collaboratorId, collaborator.getName(), collaborator.getPhoto()); this.termRepository.save(term); @@ -42,12 +44,12 @@ export default class DislikeTermCommandHandler implements ICommandHandler { - const user = await this.userRepository.findById(userId); - if (!user) { - throw new UserDoesNotExistsException(userId.toString()); + private async getCollaborator(collaboratorId: CollaboratorId): Promise { + const collaborator = await this.collaboratorRepository.findById(collaboratorId); + if (!collaborator) { + throw new CollaboratorDoesNotExistsException(collaboratorId.toString()); } - return user; + return collaborator; } } diff --git a/src/languages/domain/collaborator/collaborator.ts b/src/languages/domain/collaborator/collaborator.ts new file mode 100644 index 00000000..d4fcac8d --- /dev/null +++ b/src/languages/domain/collaborator/collaborator.ts @@ -0,0 +1,36 @@ +import { AggregateRoot } from '@src/shared/domain/aggregate/aggregateRoot'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; + +export type CollaboratorPrimitives = { + id: string; + name: string; + photo: string; + interests: string[]; +}; + +export default class Collaborator extends AggregateRoot { + constructor(private id: CollaboratorId, private name: string, private photo: string, private interests: string[]) { + super(); + } + + public getName(): string { + return this.name; + } + + public getPhoto(): string { + return this.photo; + } + + public getInterests(): string[] { + return this.interests; + } + + toPrimitives(): CollaboratorPrimitives { + return { + id: this.id.toString(), + name: this.name, + photo: this.photo, + interests: this.interests, + }; + } +} diff --git a/src/languages/domain/collaborator/collaboratorDoesNotExistsException.ts b/src/languages/domain/collaborator/collaboratorDoesNotExistsException.ts new file mode 100644 index 00000000..4958d91d --- /dev/null +++ b/src/languages/domain/collaborator/collaboratorDoesNotExistsException.ts @@ -0,0 +1,7 @@ +import NotFoundException from '@src/shared/domain/exceptions/notFoundException'; + +export default class CollaboratorDoesNotExistsException extends NotFoundException { + constructor(collaboratorId: string) { + super(`Collaborator ${collaboratorId} does not exists`, 'collaborator_does_not_exists'); + } +} diff --git a/src/languages/domain/collaborator/collaboratorId.ts b/src/languages/domain/collaborator/collaboratorId.ts new file mode 100644 index 00000000..f4d9fc47 --- /dev/null +++ b/src/languages/domain/collaborator/collaboratorId.ts @@ -0,0 +1,11 @@ +import { Uuid } from '@src/shared/domain/valueObjects/uuid'; + +export default class CollaboratorId extends Uuid { + static of(value: string): CollaboratorId { + return super.of(value) as CollaboratorId; + } + + static fromPrimitives(value: string): CollaboratorId { + return super.fromPrimitives(value) as CollaboratorId; + } +} diff --git a/src/languages/domain/collaborator/collaboratorRepository.ts b/src/languages/domain/collaborator/collaboratorRepository.ts new file mode 100644 index 00000000..9d17c701 --- /dev/null +++ b/src/languages/domain/collaborator/collaboratorRepository.ts @@ -0,0 +1,10 @@ +import Collaborator from '@src/languages/domain/collaborator/collaborator'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; + +interface CollaboratorRepository { + findById(id: CollaboratorId): Promise; +} + +export default CollaboratorRepository; + +export const COLLABORATOR_REPOSITORY = Symbol('CollaboratorRepository'); diff --git a/src/languages/infrastructure/persistence/http/TranslatingCollaboratorRepository.ts b/src/languages/infrastructure/persistence/http/TranslatingCollaboratorRepository.ts new file mode 100644 index 00000000..801124fa --- /dev/null +++ b/src/languages/infrastructure/persistence/http/TranslatingCollaboratorRepository.ts @@ -0,0 +1,14 @@ +import CollaboratorRepository from '@src/languages/domain/collaborator/collaboratorRepository'; +import Collaborator from '@src/languages/domain/collaborator/collaborator'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; +import { Injectable } from '@nestjs/common'; +import { HttpCollaboratorAdapter } from '@src/languages/infrastructure/persistence/http/httpCollaboratorAdapter'; + +@Injectable() +export class TranslatingCollaboratorRepository implements CollaboratorRepository { + constructor(private readonly httpCollaboratorAdapter: HttpCollaboratorAdapter) {} + + async findById(id: CollaboratorId): Promise { + return this.httpCollaboratorAdapter.toCollaborator(id); + } +} diff --git a/src/languages/infrastructure/persistence/http/collaboratorTranslator.ts b/src/languages/infrastructure/persistence/http/collaboratorTranslator.ts new file mode 100644 index 00000000..e608cbff --- /dev/null +++ b/src/languages/infrastructure/persistence/http/collaboratorTranslator.ts @@ -0,0 +1,9 @@ +import Collaborator from '@src/languages/domain/collaborator/collaborator'; +import { AxiosResponse } from 'axios'; + +export class CollaboratorTranslator { + static toCollaborator(collaboratorResponse: AxiosResponse): Collaborator { + const collaborator = collaboratorResponse.data; + return new Collaborator(collaborator.id, collaborator.name, collaborator.photo, collaborator.interests); + } +} diff --git a/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts b/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts new file mode 100644 index 00000000..26322082 --- /dev/null +++ b/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts @@ -0,0 +1,18 @@ +import { Injectable } from '@nestjs/common'; +import { HttpService } from '@nestjs/axios'; +import { firstValueFrom } from 'rxjs'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; +import Collaborator from '@src/languages/domain/collaborator/collaborator'; +import { CollaboratorTranslator } from '@src/languages/infrastructure/persistence/http/collaboratorTranslator'; + +@Injectable() +export class HttpCollaboratorAdapter { + URL = '/users/{id}'; + constructor(private readonly httpService: HttpService) {} + + async toCollaborator(id: CollaboratorId): Promise { + const { data } = await firstValueFrom(this.httpService.get(this.URL.replace('{id}', id.toString))); + + return CollaboratorTranslator.toCollaborator(data); + } +} diff --git a/src/languages/infrastructure/persistence/mongo/readModels/mongoFindSuggestionsTermReadModel.ts b/src/languages/infrastructure/persistence/mongo/readModels/mongoFindSuggestionsTermReadModel.ts index fa5c1df6..68df87e0 100644 --- a/src/languages/infrastructure/persistence/mongo/readModels/mongoFindSuggestionsTermReadModel.ts +++ b/src/languages/infrastructure/persistence/mongo/readModels/mongoFindSuggestionsTermReadModel.ts @@ -1,26 +1,29 @@ import FindSuggestionsTermReadModel from '@src/languages/application/term/query/findSuggestionsTermReadModel'; import UserId from '@src/account/domain/user/userId'; import { TermView } from '@src/languages/application/term/query/termView'; -import UserRepository, { USER_REPOSITORY } from '@src/account/domain/user/userRepository'; import { Inject } from '@src/shared/domain/injector/inject.decorator'; import { Document } from 'mongodb'; import MongoConnection, { MONGO_CLIENT } from '@src/shared/infrastructure/persistence/mongo/mongoConnection'; -import User from '@src/account/domain/user/user'; -import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; +import CollaboratorRepository, { + COLLABORATOR_REPOSITORY, +} from '@src/languages/domain/collaborator/collaboratorRepository'; +import Collaborator from '@src/languages/domain/collaborator/collaborator'; +import CollaboratorDoesNotExistsException from '@src/languages/domain/collaborator/collaboratorDoesNotExistsException'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; export default class MongoFindSuggestionsTermReadModel implements FindSuggestionsTermReadModel { constructor( @Inject(MONGO_CLIENT) private readonly mongo: MongoConnection, - @Inject(USER_REPOSITORY) private readonly userRepository: UserRepository, + @Inject(COLLABORATOR_REPOSITORY) private readonly collaboratorRepository: CollaboratorRepository, ) {} async find(userId: UserId): Promise { - const user = await this.getUser(userId); + const collaborator = await this.getCollaborator(userId); const result = await this.mongo.db .collection('terms') .find({ - $or: [{ hashtags: user.getInterests() }], + $or: [{ hashtags: collaborator.getInterests() }], }) .project({ _id: 0 }) .sort(['createdAt', -1]) @@ -43,12 +46,12 @@ export default class MongoFindSuggestionsTermReadModel implements FindSuggestion }); } - async getUser(userId: UserId): Promise { - const user = await this.userRepository.findById(userId); - if (null === user) { - throw new UserDoesNotExistsException(userId.toString()); + async getCollaborator(collaboratorId: CollaboratorId): Promise { + const collaborator = await this.collaboratorRepository.findById(collaboratorId); + if (null === collaborator) { + throw new CollaboratorDoesNotExistsException(collaboratorId.toString()); } - return user; + return collaborator; } } diff --git a/src/languages/language.module.ts b/src/languages/language.module.ts index 839056fb..9048f804 100644 --- a/src/languages/language.module.ts +++ b/src/languages/language.module.ts @@ -9,11 +9,26 @@ import { readModels } from '@src/languages/_dependencyInjection/readModels'; import { MikroOrmModule } from '@mikro-orm/nestjs'; import { entitySchemas } from '@src/languages/_dependencyInjection/entitySchemas'; import mikroOrmConfiguration from './infrastructure/persistence/mikroOrm/config'; +import { HttpModule } from '@nestjs/axios'; +import { ConfigModule, ConfigService } from '@nestjs/config'; +import { services } from '@src/languages/_dependencyInjection/services'; @Module({ - imports: [MikroOrmModule.forRoot(mikroOrmConfiguration), MikroOrmModule.forFeature(entitySchemas)], + imports: [ + MikroOrmModule.forRoot(mikroOrmConfiguration), + MikroOrmModule.forFeature(entitySchemas), + ConfigModule.forRoot(), + HttpModule.registerAsync({ + imports: [ConfigModule], + inject: [ConfigService], + useFactory: (configService: ConfigService) => ({ + baseURL: configService.get('SERVER_URL'), + timeout: 5000, + }), + }), + ], exports: [], controllers: [...controllers], - providers: [...commands, ...queries, ...events, ...projections, ...repositories, ...readModels], + providers: [...commands, ...queries, ...events, ...projections, ...services, ...repositories, ...readModels], }) export class LanguageModule {} diff --git a/test/unit/languages/application/term/command/addLikeTermCommandHandler.test.ts b/test/unit/languages/application/term/command/addLikeTermCommandHandler.test.ts index a5e4c2e5..f4aedc2e 100644 --- a/test/unit/languages/application/term/command/addLikeTermCommandHandler.test.ts +++ b/test/unit/languages/application/term/command/addLikeTermCommandHandler.test.ts @@ -6,42 +6,42 @@ import InvalidArgumentException from '@src/shared/domain/exceptions/invalidArgum import { TermRepositoryMock } from '@test/unit/languages/domain/term/termRepositoryMock'; import WordMother from '@test/unit/languages/domain/term/word/wordMother'; import TermDoesNotExistsException from '@src/languages/domain/term/termDoesNotExistsException'; -import { UserRepositoryMock } from '@test/unit/account/domain/user/userRepositoryMock'; -import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; -import { UserMother } from '@test/unit/account/domain/user/userMother'; -import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; import { EventBusMock } from '@test/unit/shared/domain/buses/eventBus/eventBusMock'; import { TermLikeAddedEventMother } from '@test/unit/languages/domain/term/termLikeAddedEventMother'; import TermLikeMother from '@test/unit/languages/domain/term/termLikeMother'; import Word from '@src/languages/domain/term/word/word'; import { TermLikeIdMother } from '@test/unit/languages/domain/term/termLikeIdMother'; +import { CollaboratorRepositoryMock } from '@test/unit/languages/domain/collaborator/collaboratorRepositoryMock'; +import { CollaboratorMother } from '@test/unit/languages/domain/collaborator/collaboratorMother'; +import { CollaboratorIdMother } from '@test/unit/languages/domain/collaborator/collaboratorIdMother'; +import CollaboratorDoesNotExistsException from '@src/languages/domain/collaborator/collaboratorDoesNotExistsException'; describe('Given a AddLikeTermCommandHandler to handle', () => { let termRepository: TermRepositoryMock; - let userRepository: UserRepositoryMock; + let collaboratorRepository: CollaboratorRepositoryMock; let eventBus: EventBusMock; let handler: AddLikeTermCommandHandler; - const USER_ID = '0a8008d5-ab68-4c10-8476-668b5b540e0f'; + const COLLABORATOR_ID = '0a8008d5-ab68-4c10-8476-668b5b540e0f'; const TERM_ID = '7abe3a96-d603-4e87-b69e-e9fb372294de'; const TERM_LIKE_ID = '98d173b4-8b60-5cde-8688-8cc8dd9f07b8'; const prepareDependencies = () => { termRepository = new TermRepositoryMock(); - userRepository = new UserRepositoryMock(); + collaboratorRepository = new CollaboratorRepositoryMock(); eventBus = new EventBusMock(); }; const initHandler = () => { - handler = new AddLikeTermCommandHandler(termRepository, userRepository, eventBus); + handler = new AddLikeTermCommandHandler(termRepository, collaboratorRepository, eventBus); jest.useFakeTimers(); }; const clean = () => { termRepository.clean(); - userRepository.clean(); + collaboratorRepository.clean(); eventBus.clean(); }; @@ -81,7 +81,7 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { }); }); - describe('When the user id is invalid ', () => { + describe('When the collaborator id is invalid ', () => { let command: AddLikeTermCommand; function startScenario() { @@ -135,11 +135,11 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { }); }); - describe('When the user does not exists ', () => { + describe('When the collaborator does not exists ', () => { let command: AddLikeTermCommand; function startScenario() { - command = AddLikeTermCommandMother.random({ termId: TERM_ID, userId: USER_ID }); + command = AddLikeTermCommandMother.random({ termId: TERM_ID, userId: COLLABORATOR_ID }); const term = WordMother.random({ id: TermIdMother.random(TERM_ID) }); termRepository.add(term); @@ -148,7 +148,7 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { beforeEach(startScenario); it('then should thrown an exception', async () => { - await expect(handler.execute(command)).rejects.toThrowError(UserDoesNotExistsException); + await expect(handler.execute(command)).rejects.toThrowError(CollaboratorDoesNotExistsException); }); it('then should not add the like', async () => { @@ -165,28 +165,28 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { }); }); - describe('When an user add a like to a term that already exists', () => { + describe('When an collaborator add a like to a term that already exists', () => { let command: AddLikeTermCommand; let term: Word; function startScenario() { - command = AddLikeTermCommandMother.random({ termId: TERM_ID, userId: USER_ID }); + command = AddLikeTermCommandMother.random({ termId: TERM_ID, userId: COLLABORATOR_ID }); term = WordMother.random({ id: TermIdMother.random(TERM_ID), likes: [ TermLikeMother.random({ id: TermLikeIdMother.random(TERM_LIKE_ID), - userId: UserIdMother.random(USER_ID), + userId: CollaboratorIdMother.random(COLLABORATOR_ID), termId: TermIdMother.random(TERM_ID), name: 'test', photo: '', }), ], }); - const user = UserMother.random({ id: UserIdMother.random(USER_ID) }); + const collaborator = CollaboratorMother.random({ id: CollaboratorIdMother.random(COLLABORATOR_ID) }); termRepository.add(term); - userRepository.add(user); + collaboratorRepository.add(collaborator); } beforeEach(startScenario); @@ -208,22 +208,26 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { }); }); - describe('When an user add a like to a term ', () => { + describe('When an collaborator add a like to a term ', () => { let command: AddLikeTermCommand; let term: Word; const NAME = 'Name test'; const PHOTO = 'http://link'; function startScenario() { - command = AddLikeTermCommandMother.random({ termId: TERM_ID, userId: USER_ID }); + command = AddLikeTermCommandMother.random({ termId: TERM_ID, userId: COLLABORATOR_ID }); term = WordMother.random({ id: TermIdMother.random(TERM_ID), likes: [], }); - const user = UserMother.random({ id: UserIdMother.random(USER_ID), name: NAME, photo: PHOTO }); + const user = CollaboratorMother.random({ + id: CollaboratorIdMother.random(COLLABORATOR_ID), + name: NAME, + photo: PHOTO, + }); termRepository.add(term); - userRepository.add(user); + collaboratorRepository.add(user); } beforeEach(startScenario); @@ -243,7 +247,7 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { expect(eventBus.domainEvents()).toHaveLength(1); expect(eventBus.domainEvents()[0]).toEqual({ - ...TermLikeAddedEventMother.random({ termId: TERM_ID, userId: USER_ID, name: NAME, photo: PHOTO }), + ...TermLikeAddedEventMother.random({ termId: TERM_ID, userId: COLLABORATOR_ID, name: NAME, photo: PHOTO }), }); }); }); diff --git a/test/unit/languages/application/term/command/dislikeTermCommandHandler.test.ts b/test/unit/languages/application/term/command/dislikeTermCommandHandler.test.ts index 8bb99a8d..b52df675 100644 --- a/test/unit/languages/application/term/command/dislikeTermCommandHandler.test.ts +++ b/test/unit/languages/application/term/command/dislikeTermCommandHandler.test.ts @@ -4,44 +4,44 @@ import DislikeTermCommandHandler from '@src/languages/application/term/command/d import { DislikeTermCommandMother } from '@test/unit/languages/application/term/command/dislikeTermCommandMother'; import DislikeTermCommand from '@src/languages/application/term/command/dislikeTermCommand'; import { TermRepositoryMock } from '@test/unit/languages/domain/term/termRepositoryMock'; -import { UserRepositoryMock } from '@test/unit/account/domain/user/userRepositoryMock'; import TermDoesNotExistsException from '@src/languages/domain/term/termDoesNotExistsException'; import WordMother from '@test/unit/languages/domain/term/word/wordMother'; import { TermIdMother } from '@test/unit/languages/domain/term/termIdMother'; -import UserDoesNotExistsException from '@src/account/domain/user/userDoesNotExistsException'; -import { UserMother } from '@test/unit/account/domain/user/userMother'; -import { UserIdMother } from '@test/unit/account/domain/user/userIdMother'; import { EventBusMock } from '@test/unit/shared/domain/buses/eventBus/eventBusMock'; import { TermDislikedEventMother } from '@test/unit/languages/domain/term/termDislikedEventMother'; import Word from '@src/languages/domain/term/word/word'; import TermLikeMother from '@test/unit/languages/domain/term/termLikeMother'; import { TermLikeIdMother } from '@test/unit/languages/domain/term/termLikeIdMother'; +import { CollaboratorRepositoryMock } from '@test/unit/languages/domain/collaborator/collaboratorRepositoryMock'; +import CollaboratorDoesNotExistsException from '@src/languages/domain/collaborator/collaboratorDoesNotExistsException'; +import { CollaboratorIdMother } from '@test/unit/languages/domain/collaborator/collaboratorIdMother'; +import { CollaboratorMother } from '@test/unit/languages/domain/collaborator/collaboratorMother'; describe('Given a DislikeTermCommandHandler to handle', () => { let termRepository: TermRepositoryMock; - let userRepository: UserRepositoryMock; + let collaboratorRepository: CollaboratorRepositoryMock; let eventBus: EventBusMock; let handler: DislikeTermCommandHandler; - const USER_ID = '0a8008d5-ab68-4c10-8476-668b5b540e0f'; + const COLLABORATOR_ID = '0a8008d5-ab68-4c10-8476-668b5b540e0f'; const TERM_ID = '7abe3a96-d603-4e87-b69e-e9fb372294de'; const TERM_LIKE_ID = '98d173b4-8b60-5cde-8688-8cc8dd9f07b8'; const prepareDependencies = () => { termRepository = new TermRepositoryMock(); - userRepository = new UserRepositoryMock(); + collaboratorRepository = new CollaboratorRepositoryMock(); eventBus = new EventBusMock(); }; const initHandler = () => { - handler = new DislikeTermCommandHandler(termRepository, userRepository, eventBus); + handler = new DislikeTermCommandHandler(termRepository, collaboratorRepository, eventBus); jest.useFakeTimers(); }; const clean = () => { termRepository.clean(); - userRepository.clean(); + collaboratorRepository.clean(); eventBus.clean(); }; @@ -81,7 +81,7 @@ describe('Given a DislikeTermCommandHandler to handle', () => { }); }); - describe('When the user id is invalid ', () => { + describe('When the collaborator id is invalid ', () => { let command: DislikeTermCommand; function startScenario() { @@ -135,11 +135,11 @@ describe('Given a DislikeTermCommandHandler to handle', () => { }); }); - describe('When the user does not exists ', () => { + describe('When the collaborator does not exists ', () => { let command: DislikeTermCommand; function startScenario() { - command = DislikeTermCommandMother.random({ termId: TERM_ID, userId: USER_ID }); + command = DislikeTermCommandMother.random({ termId: TERM_ID, userId: COLLABORATOR_ID }); const term = WordMother.random({ id: TermIdMother.random(TERM_ID) }); termRepository.add(term); @@ -148,7 +148,7 @@ describe('Given a DislikeTermCommandHandler to handle', () => { beforeEach(startScenario); it('then should thrown an exception', async () => { - await expect(handler.execute(command)).rejects.toThrowError(UserDoesNotExistsException); + await expect(handler.execute(command)).rejects.toThrowError(CollaboratorDoesNotExistsException); }); it('then should not dislike the term', async () => { @@ -165,27 +165,27 @@ describe('Given a DislikeTermCommandHandler to handle', () => { }); }); - describe('When an user dislike a term that the like does not exist', () => { + describe('When an collaborator dislike a term that the like does not exist', () => { let command: DislikeTermCommand; let term: Word; function startScenario() { - command = DislikeTermCommandMother.random({ termId: TERM_ID, userId: USER_ID }); + command = DislikeTermCommandMother.random({ termId: TERM_ID, userId: COLLABORATOR_ID }); term = WordMother.random({ id: TermIdMother.random(TERM_ID), likes: [ TermLikeMother.random({ - userId: UserIdMother.random('1cee3a96-d603-4e88-b69e-e9fb372294da'), + userId: CollaboratorIdMother.random('1cee3a96-d603-4e88-b69e-e9fb372294da'), termId: TermIdMother.random(TERM_ID), name: 'test', photo: '', }), ], }); - const user = UserMother.random({ id: UserIdMother.random(USER_ID) }); + const collaborator = CollaboratorMother.random({ id: CollaboratorIdMother.random(COLLABORATOR_ID) }); termRepository.add(term); - userRepository.add(user); + collaboratorRepository.add(collaborator); } beforeEach(startScenario); @@ -207,27 +207,27 @@ describe('Given a DislikeTermCommandHandler to handle', () => { }); }); - describe('When an user dislike a term that the like exist', () => { + describe('When an collaborator dislike a term that the like exist', () => { let command: DislikeTermCommand; let term: Word; function startScenario() { - command = DislikeTermCommandMother.random({ termId: TERM_ID, userId: USER_ID }); + command = DislikeTermCommandMother.random({ termId: TERM_ID, userId: COLLABORATOR_ID }); term = WordMother.random({ id: TermIdMother.random(TERM_ID), likes: [ TermLikeMother.random({ id: TermLikeIdMother.random(TERM_LIKE_ID), - userId: UserIdMother.random(USER_ID), + userId: CollaboratorIdMother.random(COLLABORATOR_ID), termId: TermIdMother.random(TERM_ID), name: 'test', }), ], }); - const user = UserMother.random({ id: UserIdMother.random(USER_ID) }); + const collaborator = CollaboratorMother.random({ id: CollaboratorIdMother.random(COLLABORATOR_ID) }); termRepository.add(term); - userRepository.add(user); + collaboratorRepository.add(collaborator); } beforeEach(startScenario); @@ -247,7 +247,7 @@ describe('Given a DislikeTermCommandHandler to handle', () => { expect(eventBus.domainEvents()).toHaveLength(1); expect(eventBus.domainEvents()[0]).toEqual({ - ...TermDislikedEventMother.random({ termId: TERM_ID, userId: USER_ID }), + ...TermDislikedEventMother.random({ termId: TERM_ID, userId: COLLABORATOR_ID }), }); }); }); diff --git a/test/unit/languages/domain/collaborator/collaboratorIdMother.ts b/test/unit/languages/domain/collaborator/collaboratorIdMother.ts new file mode 100644 index 00000000..1b092e78 --- /dev/null +++ b/test/unit/languages/domain/collaborator/collaboratorIdMother.ts @@ -0,0 +1,8 @@ +import faker from 'faker'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; + +export class CollaboratorIdMother { + static random(id?: string): CollaboratorId { + return CollaboratorId.of(id ?? faker.datatype.uuid()); + } +} diff --git a/test/unit/languages/domain/collaborator/collaboratorMother.ts b/test/unit/languages/domain/collaborator/collaboratorMother.ts new file mode 100644 index 00000000..3712a007 --- /dev/null +++ b/test/unit/languages/domain/collaborator/collaboratorMother.ts @@ -0,0 +1,24 @@ +import faker from 'faker'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; +import Collaborator from '@src/languages/domain/collaborator/collaborator'; +import { CollaboratorIdMother } from '@test/unit/languages/domain/collaborator/collaboratorIdMother'; + +interface CollaboratorMotherProps { + id?: CollaboratorId; + name?: string; + photo?: string; + interests?: string[]; +} + +export class CollaboratorMother { + static random(props?: CollaboratorMotherProps): Collaborator { + const { id, name, photo, interests } = props ?? {}; + + return new Collaborator( + id ?? CollaboratorIdMother.random(), + name ?? faker.name.findName(), + photo ?? faker.image.imageUrl(), + interests ?? ['test'], + ); + } +} diff --git a/test/unit/languages/domain/collaborator/collaboratorRepositoryMock.ts b/test/unit/languages/domain/collaborator/collaboratorRepositoryMock.ts new file mode 100644 index 00000000..53c0718d --- /dev/null +++ b/test/unit/languages/domain/collaborator/collaboratorRepositoryMock.ts @@ -0,0 +1,25 @@ +import CollaboratorRepository from '@src/languages/domain/collaborator/collaboratorRepository'; +import Collaborator from '@src/languages/domain/collaborator/collaborator'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; + +export class CollaboratorRepositoryMock implements CollaboratorRepository { + private collaborators: Collaborator[]; + + constructor() { + this.collaborators = []; + } + + add(collaborator: Collaborator): void { + this.collaborators.push(collaborator); + } + + clean(): void { + this.collaborators = []; + } + + async findById(_id: CollaboratorId): Promise { + const collaborator = this.collaborators.length > 0 ? this.collaborators[0] : null; + + return Promise.resolve(collaborator); + } +} From 4fc04e099fce55cfc1de6d1bbf66fc37ac01209d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Mon, 16 Dec 2024 21:43:18 +0100 Subject: [PATCH 04/11] Add collaboratorIdType #172 --- .../persistence/mikroOrm/entities/user.ts | 2 +- .../persistence/mikroOrm/types/.gitkeep | 0 .../persistence/mikroOrm/types/userIdType.ts | 0 .../persistence/mikroOrm/entities/term.ts | 4 ++-- .../persistence/mikroOrm/types/collaboratorIdType.ts | 12 ++++++++++++ 5 files changed, 15 insertions(+), 3 deletions(-) delete mode 100644 src/account/infrastructure/persistence/mikroOrm/types/.gitkeep rename src/{shared => account}/infrastructure/persistence/mikroOrm/types/userIdType.ts (100%) create mode 100644 src/languages/infrastructure/persistence/mikroOrm/types/collaboratorIdType.ts diff --git a/src/account/infrastructure/persistence/mikroOrm/entities/user.ts b/src/account/infrastructure/persistence/mikroOrm/entities/user.ts index 67521ae2..361ae688 100644 --- a/src/account/infrastructure/persistence/mikroOrm/entities/user.ts +++ b/src/account/infrastructure/persistence/mikroOrm/entities/user.ts @@ -1,6 +1,6 @@ import { EntitySchema } from '@mikro-orm/core'; import User from '@src/account/domain/user/user'; -import { UserIdType } from '@src/shared/infrastructure/persistence/mikroOrm/types/userIdType'; +import { UserIdType } from '@src/account/infrastructure/persistence/mikroOrm/types/userIdType'; import { EmailType } from '@src/shared/infrastructure/persistence/mikroOrm/types/emailType'; export const UserSchema = new EntitySchema({ diff --git a/src/account/infrastructure/persistence/mikroOrm/types/.gitkeep b/src/account/infrastructure/persistence/mikroOrm/types/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/shared/infrastructure/persistence/mikroOrm/types/userIdType.ts b/src/account/infrastructure/persistence/mikroOrm/types/userIdType.ts similarity index 100% rename from src/shared/infrastructure/persistence/mikroOrm/types/userIdType.ts rename to src/account/infrastructure/persistence/mikroOrm/types/userIdType.ts diff --git a/src/languages/infrastructure/persistence/mikroOrm/entities/term.ts b/src/languages/infrastructure/persistence/mikroOrm/entities/term.ts index dd6d2244..7aafa71d 100644 --- a/src/languages/infrastructure/persistence/mikroOrm/entities/term.ts +++ b/src/languages/infrastructure/persistence/mikroOrm/entities/term.ts @@ -5,7 +5,7 @@ import { TermIdType } from '../types/termIdType'; import { CountryIdType } from '../types/countryIdType'; import { LikesCollectionType } from '../types/likesCollectionType'; import { TermTypeType } from '../types/termTypeType'; -import { UserIdType } from '@src/shared/infrastructure/persistence/mikroOrm/types/userIdType'; +import { CollaboratorIdType } from '@src/languages/infrastructure/persistence/mikroOrm/types/collaboratorIdType'; export const TermSchema = new EntitySchema({ class: Term, @@ -27,7 +27,7 @@ export const TermSchema = new EntitySchema({ type: CountryIdType, }, userId: { - type: UserIdType, + type: CollaboratorIdType, }, likes: { type: LikesCollectionType, diff --git a/src/languages/infrastructure/persistence/mikroOrm/types/collaboratorIdType.ts b/src/languages/infrastructure/persistence/mikroOrm/types/collaboratorIdType.ts new file mode 100644 index 00000000..7ef72b4b --- /dev/null +++ b/src/languages/infrastructure/persistence/mikroOrm/types/collaboratorIdType.ts @@ -0,0 +1,12 @@ +import { ValueObjectType } from '@src/shared/infrastructure/persistence/mikroOrm/types/valueObjectType'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; + +export class CollaboratorIdType extends ValueObjectType { + constructor() { + super(CollaboratorId); + } + + getColumnType() { + return 'uuid'; + } +} From 34b71293178dde6d12db583d1539391924ca173d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Mon, 16 Dec 2024 21:47:10 +0100 Subject: [PATCH 05/11] Fix package.json #172 --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8117e478..1d29294b 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,9 @@ "useTsNode": true, "configPaths": [ "./src/languages/infrastructure/persistence/mikroOrm/config.ts", - "./dist/languages/infrastructure/persistence/mikroOrm/config.ts" + "./dist/languages/infrastructure/persistence/mikroOrm/config.ts", + "./src/account/infrastructure/persistence/mikroOrm/config.ts", + "./dist/account/infrastructure/persistence/mikroOrm/config.ts" ] } } From 7e4f8e84b8e2ee47c966c97fa8e0fb877f916235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Fri, 20 Dec 2024 21:35:35 +0100 Subject: [PATCH 06/11] Improve mikroOrm configuration --- src/account/account.module.ts | 8 ++--- src/app.module.ts | 4 ++- .../persistence/mikroOrm/config.ts | 31 ------------------- src/languages/language.module.ts | 8 ++--- .../mikroOrm/config.ts => mikroOrmConfig.ts} | 8 +++-- 5 files changed, 15 insertions(+), 44 deletions(-) delete mode 100644 src/languages/infrastructure/persistence/mikroOrm/config.ts rename src/{account/infrastructure/persistence/mikroOrm/config.ts => mikroOrmConfig.ts} (63%) diff --git a/src/account/account.module.ts b/src/account/account.module.ts index de36f8ae..ca15e34e 100644 --- a/src/account/account.module.ts +++ b/src/account/account.module.ts @@ -1,14 +1,14 @@ import { Module } from '@nestjs/common'; -import { MikroOrmModule } from '@mikro-orm/nestjs'; -import mikroOrmConfiguration from './infrastructure/persistence/mikroOrm/config'; -import { entitySchemas } from '@src/account/_dependencyInjection/entitySchemas'; + import { controllers } from '@src/account/_dependencyInjection/controllers'; import { commands } from '@src/account/_dependencyInjection/commandHandlers'; import { queries } from '@src/account/_dependencyInjection/queryHandlers'; import { repositories } from '@src/account/_dependencyInjection/repositories'; +import { MikroOrmModule } from '@mikro-orm/nestjs'; +import { entitySchemas as accountEntitySchemas } from '@src/account/_dependencyInjection/entitySchemas'; @Module({ - imports: [MikroOrmModule.forRoot(mikroOrmConfiguration), MikroOrmModule.forFeature(entitySchemas)], + imports: [MikroOrmModule.forFeature([...accountEntitySchemas])], exports: [], controllers: [...controllers], providers: [...commands, ...queries, ...repositories], diff --git a/src/app.module.ts b/src/app.module.ts index a5f499f1..6b559bf1 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -2,8 +2,10 @@ import { Module } from '@nestjs/common'; import { LanguageModule } from './languages/language.module'; import { SharedModule } from './shared/shared.module'; import { AccountModule } from '@src/account/account.module'; +import { MikroOrmModule } from '@mikro-orm/nestjs'; +import mikroOrmConfiguration from '@src/mikroOrmConfig'; @Module({ - imports: [SharedModule, AccountModule, LanguageModule], + imports: [SharedModule, MikroOrmModule.forRoot(mikroOrmConfiguration), AccountModule, LanguageModule], }) export class AppModule {} diff --git a/src/languages/infrastructure/persistence/mikroOrm/config.ts b/src/languages/infrastructure/persistence/mikroOrm/config.ts deleted file mode 100644 index eca4888d..00000000 --- a/src/languages/infrastructure/persistence/mikroOrm/config.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Migrator } from '@mikro-orm/migrations'; -import { defineConfig, PostgreSqlDriver } from '@mikro-orm/postgresql'; -import { entitySchemas } from '@src/languages/_dependencyInjection/entitySchemas'; -import { config as loadEnv } from 'dotenv'; -import dotenvExpand from 'dotenv-expand'; -import path from 'path'; - -const env = loadEnv(); -dotenvExpand.expand(env); - -const migrationPath = path.join(__dirname, '/migrations'); - -export default defineConfig({ - entities: entitySchemas, - entitiesTs: entitySchemas, - driver: PostgreSqlDriver, - clientUrl: process.env.POSTGRESQL_DB_URL, - debug: process.env.ENV != 'production', - extensions: [Migrator], - ignoreUndefinedInQuery: true, - forceUndefined: false, - migrations: { - path: migrationPath, - glob: '!(*.d).{js,ts}', - pathTs: migrationPath, - tableName: 'mikro_orm_migrations', - transactional: true, - allOrNothing: true, - snapshot: false, - }, -}); diff --git a/src/languages/language.module.ts b/src/languages/language.module.ts index 9048f804..02f047ff 100644 --- a/src/languages/language.module.ts +++ b/src/languages/language.module.ts @@ -6,18 +6,16 @@ import { queries } from '@src/languages/_dependencyInjection/queryHandlers'; import { events } from '@src/languages/_dependencyInjection/eventHandlers'; import { projections } from '@src/languages/_dependencyInjection/projectionHandlers'; import { readModels } from '@src/languages/_dependencyInjection/readModels'; -import { MikroOrmModule } from '@mikro-orm/nestjs'; -import { entitySchemas } from '@src/languages/_dependencyInjection/entitySchemas'; -import mikroOrmConfiguration from './infrastructure/persistence/mikroOrm/config'; import { HttpModule } from '@nestjs/axios'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { services } from '@src/languages/_dependencyInjection/services'; +import { MikroOrmModule } from '@mikro-orm/nestjs'; +import { entitySchemas as languagesEntitySchemas } from '@src/languages/_dependencyInjection/entitySchemas'; @Module({ imports: [ - MikroOrmModule.forRoot(mikroOrmConfiguration), - MikroOrmModule.forFeature(entitySchemas), ConfigModule.forRoot(), + MikroOrmModule.forFeature([...languagesEntitySchemas]), HttpModule.registerAsync({ imports: [ConfigModule], inject: [ConfigService], diff --git a/src/account/infrastructure/persistence/mikroOrm/config.ts b/src/mikroOrmConfig.ts similarity index 63% rename from src/account/infrastructure/persistence/mikroOrm/config.ts rename to src/mikroOrmConfig.ts index 094454cb..5f5b6ff8 100644 --- a/src/account/infrastructure/persistence/mikroOrm/config.ts +++ b/src/mikroOrmConfig.ts @@ -4,12 +4,14 @@ import { defineConfig, PostgreSqlDriver } from '@mikro-orm/postgresql'; import { config as loadEnv } from 'dotenv'; import dotenvExpand from 'dotenv-expand'; import path from 'path'; -import { entitySchemas } from '@src/account/_dependencyInjection/entitySchemas'; +import { entitySchemas as accountEntitySchemas } from '@src/account/_dependencyInjection/entitySchemas'; +import { entitySchemas as languagesEntitySchemas } from '@src/languages/_dependencyInjection/entitySchemas'; const env = loadEnv(); dotenvExpand.expand(env); -const migrationPath = path.join(__dirname, '/migrations'); +const migrationPath = path.join(__dirname, 'infrastructure/persistence/mikroOrm/migrations'); +const entitySchemas = [...accountEntitySchemas, ...languagesEntitySchemas]; export default defineConfig({ entities: entitySchemas, @@ -22,7 +24,7 @@ export default defineConfig({ forceUndefined: false, migrations: { path: migrationPath, - glob: '!(*.d).{js,ts}', + glob: '{account,languages}/*.{js,ts}', pathTs: migrationPath, tableName: 'mikro_orm_migrations', transactional: true, From ecc9b748c23b5af024168f406507482c16200d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Fri, 20 Dec 2024 21:37:25 +0100 Subject: [PATCH 07/11] Update mikro-orm path in package.json --- package.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 1d29294b..213cd2eb 100644 --- a/package.json +++ b/package.json @@ -93,10 +93,8 @@ "mikro-orm": { "useTsNode": true, "configPaths": [ - "./src/languages/infrastructure/persistence/mikroOrm/config.ts", - "./dist/languages/infrastructure/persistence/mikroOrm/config.ts", - "./src/account/infrastructure/persistence/mikroOrm/config.ts", - "./dist/account/infrastructure/persistence/mikroOrm/config.ts" + "./src/mikroOrmConfig.ts", + "./dist/mikroOrmConfig.ts" ] } } From a63ec914f0289ce7e6cf5d4b3c4d1a61e9ebc753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Fri, 20 Dec 2024 21:38:08 +0100 Subject: [PATCH 08/11] Fix linter --- src/languages/_dependencyInjection/services.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/languages/_dependencyInjection/services.ts b/src/languages/_dependencyInjection/services.ts index 0b35a596..ef90ee6f 100644 --- a/src/languages/_dependencyInjection/services.ts +++ b/src/languages/_dependencyInjection/services.ts @@ -1,5 +1,3 @@ import { HttpCollaboratorAdapter } from '@src/languages/infrastructure/persistence/http/httpCollaboratorAdapter'; -export const services = [ - HttpCollaboratorAdapter -]; \ No newline at end of file +export const services = [HttpCollaboratorAdapter]; From 105f7bd9b17d549bc641524fd56266929bfc4442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Fri, 20 Dec 2024 22:03:00 +0100 Subject: [PATCH 09/11] Fix httpCollaboratorAdapter.ts --- .../persistence/http/httpCollaboratorAdapter.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts b/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts index 26322082..e6b2ee06 100644 --- a/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts +++ b/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts @@ -7,11 +7,12 @@ import { CollaboratorTranslator } from '@src/languages/infrastructure/persistenc @Injectable() export class HttpCollaboratorAdapter { - URL = '/users/{id}'; + URL = '/api/v1/users/{id}'; constructor(private readonly httpService: HttpService) {} async toCollaborator(id: CollaboratorId): Promise { - const { data } = await firstValueFrom(this.httpService.get(this.URL.replace('{id}', id.toString))); + const { data } = await firstValueFrom(this.httpService.get(this.URL.replace('{id}', id.toString()))); + if (!data) return null; return CollaboratorTranslator.toCollaborator(data); } From 7eef85a0ad298dbd4dc8c0934e7427dd0ac581ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Fri, 20 Dec 2024 22:14:49 +0100 Subject: [PATCH 10/11] Improve types in collaboratorTranslator #172 --- .../persistence/http/collaboratorTranslator.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/languages/infrastructure/persistence/http/collaboratorTranslator.ts b/src/languages/infrastructure/persistence/http/collaboratorTranslator.ts index e608cbff..a6c7cc22 100644 --- a/src/languages/infrastructure/persistence/http/collaboratorTranslator.ts +++ b/src/languages/infrastructure/persistence/http/collaboratorTranslator.ts @@ -1,9 +1,15 @@ import Collaborator from '@src/languages/domain/collaborator/collaborator'; import { AxiosResponse } from 'axios'; +import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; export class CollaboratorTranslator { - static toCollaborator(collaboratorResponse: AxiosResponse): Collaborator { - const collaborator = collaboratorResponse.data; - return new Collaborator(collaborator.id, collaborator.name, collaborator.photo, collaborator.interests); + static toCollaborator(data: AxiosResponse): Collaborator { + const collaborator = data as unknown as { id: string; name: string; photo: string; interests: string[] }; + return new Collaborator( + CollaboratorId.fromPrimitives(collaborator.id), + collaborator.name, + collaborator.photo, + collaborator.interests, + ); } } From 85cfab56b1b3901c32be91a3db9c6fb64154cb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Fri, 20 Dec 2024 22:14:55 +0100 Subject: [PATCH 11/11] Add token #172 --- .../http/httpCollaboratorAdapter.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts b/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts index e6b2ee06..bc68f122 100644 --- a/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts +++ b/src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts @@ -4,14 +4,28 @@ import { firstValueFrom } from 'rxjs'; import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; import Collaborator from '@src/languages/domain/collaborator/collaborator'; import { CollaboratorTranslator } from '@src/languages/infrastructure/persistence/http/collaboratorTranslator'; +import { Inject } from '@src/shared/domain/injector/inject.decorator'; +import { USER_AUTHENTICATOR, UserAuthenticator } from '@src/shared/domain/auth/userAuthenticator'; @Injectable() export class HttpCollaboratorAdapter { URL = '/api/v1/users/{id}'; - constructor(private readonly httpService: HttpService) {} + constructor( + private readonly httpService: HttpService, + @Inject(USER_AUTHENTICATOR) private readonly userAuthenticator: UserAuthenticator, + ) {} async toCollaborator(id: CollaboratorId): Promise { - const { data } = await firstValueFrom(this.httpService.get(this.URL.replace('{id}', id.toString()))); + const m2mToken = this.userAuthenticator.sign({}); + + const { data } = await firstValueFrom( + this.httpService.get(this.URL.replace('{id}', id.toString()), { + headers: { + Authorization: `Bearer ${m2mToken.token}`, + }, + }), + ); + if (!data) return null; return CollaboratorTranslator.toCollaborator(data);