diff --git a/.vscode/settings.json b/.vscode/settings.json index 0974368..56184be 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,5 @@ "cSpell.words": [ "nestjs", "supergraph", - "usecase" ] } \ No newline at end of file diff --git a/README.md b/README.md index 5a66768..fe8cfde 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ You can use `npx nx list` to get a list of installed plugins. Then, run `npx nx | Layer | Description | | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| usecase | Define business use cases and encapsulate business logic. | +| use-case(application) | Define business use cases and encapsulate business logic. | | entity(domain) | Define core business entities and business rules.
Maintain entity independence from database and framework. | | repository(domain) | Interfaces (or abstract classes), which define methods for manipulating data without concern for specific database implementations.
By defining this interface, we can decouple database access: the specific details of data access will be done by implementation classes, such as specific implementations using tools like Mongoose, TypeORM, Prisma, and so on. | diff --git a/libs/user/usecase/README.md b/libs/user/usecase/README.md deleted file mode 100644 index 55f764c..0000000 --- a/libs/user/usecase/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# user-usecase - -This library was generated with [Nx](https://nx.dev). - -## Running unit tests - -Run `nx test user-usecase` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/user/usecase/project.json b/libs/user/usecase/project.json deleted file mode 100644 index 721c75a..0000000 --- a/libs/user/usecase/project.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "user-usecase", - "$schema": "../../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "libs/user/usecase/src", - "projectType": "library", - "tags": [], - "// targets": "to see all targets run: nx show project user-usecase --web", - "targets": {} -} diff --git a/libs/user/usecase/src/index.ts b/libs/user/usecase/src/index.ts deleted file mode 100644 index 4a77ee3..0000000 --- a/libs/user/usecase/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './lib/user-usecase'; diff --git a/libs/user/usecase/tsconfig.json b/libs/user/usecase/tsconfig.json deleted file mode 100644 index 0dc79ca..0000000 --- a/libs/user/usecase/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "extends": "../../../tsconfig.base.json", - "compilerOptions": { - "module": "commonjs", - "forceConsistentCasingInFileNames": true, - "strict": true, - "noImplicitOverride": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - "noPropertyAccessFromIndexSignature": true - }, - "files": [], - "include": [], - "references": [ - { - "path": "./tsconfig.lib.json" - }, - { - "path": "./tsconfig.spec.json" - } - ] -} diff --git a/libs/users/application/README.md b/libs/users/application/README.md new file mode 100644 index 0000000..408ecfe --- /dev/null +++ b/libs/users/application/README.md @@ -0,0 +1,7 @@ +# users-application + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test users-application` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/user/usecase/eslint.config.js b/libs/users/application/eslint.config.js similarity index 100% rename from libs/user/usecase/eslint.config.js rename to libs/users/application/eslint.config.js diff --git a/libs/user/usecase/jest.config.ts b/libs/users/application/jest.config.ts similarity index 69% rename from libs/user/usecase/jest.config.ts rename to libs/users/application/jest.config.ts index f265dce..8db2d4c 100644 --- a/libs/user/usecase/jest.config.ts +++ b/libs/users/application/jest.config.ts @@ -1,10 +1,10 @@ export default { - displayName: 'user-usecase', + displayName: 'users-application', preset: '../../../jest.preset.js', testEnvironment: 'node', transform: { '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], }, moduleFileExtensions: ['ts', 'js', 'html'], - coverageDirectory: '../../../coverage/libs/user/usecase', + coverageDirectory: '../../../coverage/libs/users/application', }; diff --git a/libs/users/application/project.json b/libs/users/application/project.json new file mode 100644 index 0000000..2300a8a --- /dev/null +++ b/libs/users/application/project.json @@ -0,0 +1,9 @@ +{ + "name": "users-application", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/users/application/src", + "projectType": "library", + "tags": [], + "// targets": "to see all targets run: nx show project users-application --web", + "targets": {} +} diff --git a/libs/users/application/src/index.ts b/libs/users/application/src/index.ts new file mode 100644 index 0000000..edb676a --- /dev/null +++ b/libs/users/application/src/index.ts @@ -0,0 +1 @@ +export * from './lib/use-case/get-user.use-case'; diff --git a/libs/user/usecase/src/lib/get-user.usecase.spec.ts b/libs/users/application/src/lib/use-case/get-user.use-case.spec.ts similarity index 72% rename from libs/user/usecase/src/lib/get-user.usecase.spec.ts rename to libs/users/application/src/lib/use-case/get-user.use-case.spec.ts index 0b2ae94..9425eec 100644 --- a/libs/user/usecase/src/lib/get-user.usecase.spec.ts +++ b/libs/users/application/src/lib/use-case/get-user.use-case.spec.ts @@ -1,8 +1,8 @@ -import { GetUserUsecase } from './get-user.usecase'; +import { GetUserUseCase } from './get-user.use-case'; import { UserRepository } from '@user/domain'; -describe('GetUserUsecase', () => { - let getUserUsecase: GetUserUsecase; +describe('GetUserUseCase', () => { + let getUserUseCase: GetUserUseCase; let userRepository: jest.Mocked; beforeEach(() => { @@ -10,7 +10,7 @@ describe('GetUserUsecase', () => { findById: jest.fn(), } as unknown as jest.Mocked; - getUserUsecase = new GetUserUsecase(userRepository); + getUserUseCase = new GetUserUseCase(userRepository); }); describe('execute', () => { @@ -18,7 +18,7 @@ describe('GetUserUsecase', () => { const user = { id: '1', name: 'John Doe' }; userRepository.findById.mockResolvedValue(user); - const result = await getUserUsecase.execute('1'); + const result = await getUserUseCase.execute('1'); expect(result).toEqual(user); expect(userRepository.findById).toHaveBeenCalledWith('1'); @@ -27,7 +27,7 @@ describe('GetUserUsecase', () => { it('should return null when user is not found', async () => { userRepository.findById.mockResolvedValue(null); - const result = await getUserUsecase.execute('1'); + const result = await getUserUseCase.execute('1'); expect(result).toBeNull(); expect(userRepository.findById).toHaveBeenCalledWith('1'); diff --git a/libs/user/usecase/src/lib/get-user.usecase.ts b/libs/users/application/src/lib/use-case/get-user.use-case.ts similarity index 88% rename from libs/user/usecase/src/lib/get-user.usecase.ts rename to libs/users/application/src/lib/use-case/get-user.use-case.ts index 9012a7f..b5c8b0f 100644 --- a/libs/user/usecase/src/lib/get-user.usecase.ts +++ b/libs/users/application/src/lib/use-case/get-user.use-case.ts @@ -1,6 +1,6 @@ import { User, UserRepository } from '@user/domain'; -export class GetUserUsecase { +export class GetUserUseCase { constructor(private readonly userRepository: UserRepository) {} async execute(id: string): Promise { diff --git a/libs/users/application/tsconfig.json b/libs/users/application/tsconfig.json new file mode 100644 index 0000000..25f7201 --- /dev/null +++ b/libs/users/application/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "module": "commonjs" + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/user/usecase/tsconfig.lib.json b/libs/users/application/tsconfig.lib.json similarity index 100% rename from libs/user/usecase/tsconfig.lib.json rename to libs/users/application/tsconfig.lib.json diff --git a/libs/user/usecase/tsconfig.spec.json b/libs/users/application/tsconfig.spec.json similarity index 100% rename from libs/user/usecase/tsconfig.spec.json rename to libs/users/application/tsconfig.spec.json diff --git a/tsconfig.base.json b/tsconfig.base.json index 4acfc6a..32783aa 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -18,7 +18,7 @@ "@libs/config": ["libs/config/src/index.ts"], "@prompt/domain": ["libs/prompt/domain/src/index.ts"], "@user/domain": ["libs/user/domain/src/index.ts"], - "@user/usecase": ["libs/user/usecase/src/index.ts"] + "@users/application": ["libs/users/application/src/index.ts"] } }, "exclude": ["node_modules", "tmp"]