Merge branch 'refactorDatabaseModule' into 'main'
refactor database module See merge request v3/service/matcher!8
This commit is contained in:
commit
a14ac74d5b
|
@ -1,13 +1,13 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { MatcherRepository } from '../../../database/domain/matcher-repository';
|
||||
import { DatabaseRepository } from '../../../database/domain/database.repository';
|
||||
import { Ad } from '../../domain/entities/ad';
|
||||
import { DatabaseException } from '../../../database/exceptions/database.exception';
|
||||
|
||||
@Injectable()
|
||||
export class AdRepository extends MatcherRepository<Ad> {
|
||||
export class AdRepository extends DatabaseRepository<Ad> {
|
||||
protected model = 'ad';
|
||||
|
||||
async createAd(ad: Partial<Ad>): Promise<Ad> {
|
||||
createAd = async (ad: Partial<Ad>): Promise<Ad> => {
|
||||
try {
|
||||
const affectedRowNumber = await this.createWithFields(
|
||||
this.createFields(ad),
|
||||
|
@ -19,10 +19,9 @@ export class AdRepository extends MatcherRepository<Ad> {
|
|||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private createFields(ad: Partial<Ad>): Partial<AdFields> {
|
||||
return {
|
||||
private createFields = (ad: Partial<Ad>): Partial<AdFields> => ({
|
||||
uuid: `'${ad.uuid}'`,
|
||||
userUuid: `'${ad.userUuid}'`,
|
||||
driver: ad.driver ? 'true' : 'false',
|
||||
|
@ -88,8 +87,7 @@ export class AdRepository extends MatcherRepository<Ad> {
|
|||
seatsPassenger: ad.seatsPassenger,
|
||||
seatsUsed: ad.seatsUsed ?? 0,
|
||||
strict: ad.strict,
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
type AdFields = {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { TestingModule, Test } from '@nestjs/testing';
|
||||
import { DatabaseModule } from '../../../database/database.module';
|
||||
import { PrismaService } from '../../../database/adapters/secondaries/prisma-service';
|
||||
import { PrismaService } from '../../../database/adapters/secondaries/prisma.service';
|
||||
import { AdRepository } from '../../adapters/secondaries/ad.repository';
|
||||
import { Ad } from '../../domain/entities/ad';
|
||||
import { Frequency } from '../../domain/types/frequency.enum';
|
||||
|
|
|
@ -3,10 +3,10 @@ import { Prisma } from '@prisma/client';
|
|||
import { DatabaseException } from '../../exceptions/database.exception';
|
||||
import { ICollection } from '../../interfaces/collection.interface';
|
||||
import { IRepository } from '../../interfaces/repository.interface';
|
||||
import { PrismaService } from './prisma-service';
|
||||
import { PrismaService } from './prisma.service';
|
||||
|
||||
/**
|
||||
* Child classes MUST redefined _model property with appropriate model name
|
||||
* Child classes MUST redefined model property with appropriate model name
|
||||
*/
|
||||
@Injectable()
|
||||
export abstract class PrismaRepository<T> implements IRepository<T> {
|
|
@ -1,9 +1,8 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { PrismaService } from './adapters/secondaries/prisma-service';
|
||||
import { AdRepository } from '../ad/adapters/secondaries/ad.repository';
|
||||
import { PrismaService } from './adapters/secondaries/prisma.service';
|
||||
|
||||
@Module({
|
||||
providers: [PrismaService, AdRepository],
|
||||
exports: [PrismaService, AdRepository],
|
||||
providers: [PrismaService],
|
||||
exports: [PrismaService],
|
||||
})
|
||||
export class DatabaseModule {}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
import { PrismaRepository } from '../adapters/secondaries/prisma.repository.abstract';
|
||||
|
||||
export class DatabaseRepository<T> extends PrismaRepository<T> {}
|
|
@ -1,3 +0,0 @@
|
|||
import { PrismaRepository } from '../adapters/secondaries/prisma-repository.abstract';
|
||||
|
||||
export class MatcherRepository<T> extends PrismaRepository<T> {}
|
|
@ -1,7 +1,7 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PrismaService } from '../../adapters/secondaries/prisma-service';
|
||||
import { PrismaRepository } from '../../adapters/secondaries/prisma-repository.abstract';
|
||||
import { PrismaService } from '../../adapters/secondaries/prisma.service';
|
||||
import { PrismaRepository } from '../../adapters/secondaries/prisma.repository.abstract';
|
||||
import { DatabaseException } from '../../exceptions/database.exception';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
|
|
Loading…
Reference in New Issue