Merge branch 'refactoing' into 'main'

Refactoring

See merge request v3/services/user!9
This commit is contained in:
Sylvain Briat 2023-01-24 15:05:18 +00:00
commit 67e7eab013
7 changed files with 13 additions and 13 deletions

9
package-lock.json generated
View File

@ -25,6 +25,7 @@
"@types/supertest": "^2.0.11", "@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0", "@typescript-eslint/parser": "^5.0.0",
"class-transformer": "^0.5.1",
"dotenv-cli": "^6.0.0" "dotenv-cli": "^6.0.0"
}, },
"devDependencies": { "devDependencies": {
@ -3633,9 +3634,7 @@
"node_modules/class-transformer": { "node_modules/class-transformer": {
"version": "0.5.1", "version": "0.5.1",
"resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz",
"integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw=="
"optional": true,
"peer": true
}, },
"node_modules/class-validator": { "node_modules/class-validator": {
"version": "0.14.0", "version": "0.14.0",
@ -11679,9 +11678,7 @@
"class-transformer": { "class-transformer": {
"version": "0.5.1", "version": "0.5.1",
"resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz",
"integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw=="
"optional": true,
"peer": true
}, },
"class-validator": { "class-validator": {
"version": "0.14.0", "version": "0.14.0",

View File

@ -42,6 +42,7 @@
"@types/supertest": "^2.0.11", "@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0", "@typescript-eslint/parser": "^5.0.0",
"class-transformer": "^0.5.1",
"dotenv-cli": "^6.0.0" "dotenv-cli": "^6.0.0"
}, },
"devDependencies": { "devDependencies": {
@ -70,7 +71,11 @@
"json", "json",
"ts" "ts"
], ],
"modulePathIgnorePatterns": [".controller.ts",".module.ts","main.ts"], "modulePathIgnorePatterns": [
".controller.ts",
".module.ts",
"main.ts"
],
"rootDir": "src", "rootDir": "src",
"testRegex": ".*\\.spec\\.ts$", "testRegex": ".*\\.spec\\.ts$",
"transform": { "transform": {

View File

@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime'; import { PrismaClientKnownRequestError } from '@prisma/client/runtime';
import { DatabaseException } from '../../exceptions/DatabaseException'; import { DatabaseException } from '../../exceptions/database.exception';
import { ICollection } from '../../interfaces/collection.interface'; import { ICollection } from '../../interfaces/collection.interface';
import { IRepository } from '../../interfaces/repository.interface'; import { IRepository } from '../../interfaces/repository.interface';
import { PrismaService } from './prisma-service'; import { PrismaService } from './prisma-service';
@ -74,8 +74,6 @@ export abstract class PrismaRepository<T> implements IRepository<T> {
} }
} }
// TODO : using any is not good, but needed for nested entities
// TODO : Refactor for good clean architecture ?
async create(entity: Partial<T> | any, include?: any): Promise<T> { async create(entity: Partial<T> | any, include?: any): Promise<T> {
try { try {
const res = await this._prisma[this._model].create({ const res = await this._prisma[this._model].create({

View File

@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from '@nestjs/testing';
import { PrismaService } from '../../src/adapters/secondaries/prisma-service'; import { PrismaService } from '../../src/adapters/secondaries/prisma-service';
import { PrismaRepository } from '../../src/adapters/secondaries/prisma-repository.abstract'; import { PrismaRepository } from '../../src/adapters/secondaries/prisma-repository.abstract';
import { DatabaseException } from '../../src/exceptions/DatabaseException'; import { DatabaseException } from '../../src/exceptions/database.exception';
class FakeEntity { class FakeEntity {
uuid?: string; uuid?: string;

View File

@ -3,7 +3,7 @@ import { InjectMapper } from '@automapper/nestjs';
import { Controller, UsePipes } from '@nestjs/common'; import { Controller, UsePipes } from '@nestjs/common';
import { CommandBus, QueryBus } from '@nestjs/cqrs'; import { CommandBus, QueryBus } from '@nestjs/cqrs';
import { GrpcMethod, RpcException } from '@nestjs/microservices'; import { GrpcMethod, RpcException } from '@nestjs/microservices';
import { DatabaseException } from '../../../database/src/exceptions/DatabaseException'; import { DatabaseException } from '../../../database/src/exceptions/database.exception';
import { CreateUserCommand } from '../../commands/create-user.command'; import { CreateUserCommand } from '../../commands/create-user.command';
import { DeleteUserCommand } from '../../commands/delete-user.command'; import { DeleteUserCommand } from '../../commands/delete-user.command';
import { UpdateUserCommand } from '../../commands/update-user.command'; import { UpdateUserCommand } from '../../commands/update-user.command';

View File

@ -1,7 +1,7 @@
import { TestingModule, Test } from '@nestjs/testing'; import { TestingModule, Test } from '@nestjs/testing';
import { DatabaseModule } from '../../../database/database.module'; import { DatabaseModule } from '../../../database/database.module';
import { PrismaService } from '../../../database/src/adapters/secondaries/prisma-service'; import { PrismaService } from '../../../database/src/adapters/secondaries/prisma-service';
import { DatabaseException } from '../../../database/src/exceptions/DatabaseException'; import { DatabaseException } from '../../../database/src/exceptions/database.exception';
import { UsersRepository } from '../../adapters/secondaries/users.repository'; import { UsersRepository } from '../../adapters/secondaries/users.repository';
import { User } from '../../domain/entities/user'; import { User } from '../../domain/entities/user';