Skip to content

Commit

Permalink
fix: #2407
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Jan 28, 2025
1 parent 7a3f527 commit df79ef6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/app/src/api/core-domain/repo/IReferentRepo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { type Referent } from "@common/core-domain/domain/Referent";
import { type County } from "@common/core-domain/domain/valueObjects/County";
import { type Region } from "@common/core-domain/domain/valueObjects/Region";
import { type BulkRepo } from "@common/shared-domain";

export interface IReferentRepo extends BulkRepo<Referent> {
getOneByCounty(county?: County): Promise<Referent | null>;
getOneByRegion(region?: Region): Promise<Referent | null>;
truncate(): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type ReferentRaw } from "@api/core-domain/infra/db/raw";
import { sql } from "@api/shared-domain/infra/db/postgres";
import { type Referent } from "@common/core-domain/domain/Referent";
import { type County } from "@common/core-domain/domain/valueObjects/County";
import { type Region } from "@common/core-domain/domain/valueObjects/Region";
import { referentMap } from "@common/core-domain/mappers/referentMap";
import { UnexpectedRepositoryError } from "@common/shared-domain";
Expand Down Expand Up @@ -55,6 +56,14 @@ export class PostgresReferentRepo implements IReferentRepo {
return referentMap.toDomain(raw);
}

public async getOneByCounty(county?: County): Promise<Referent | null> {
if (!county) return null;
const [raw] = await this.sql`select * from ${this.table} where county = ${county.getValue()} limit 1`;

if (!raw) return null;
return referentMap.toDomain(raw);
}

public async save(item: Referent): Promise<UniqueID> {
const raw = referentMap.toPersistence(item);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class SendDeclarationReceipt implements UseCase<Input, void> {
throw new SendDeclarationReceiptNotFoundError(`No declaration found with siren ${siren} and year ${year}`);
}

const referent = await this.referentRepo.getOneByRegion(declaration.declaration?.company?.region);
const referent = await this.referentRepo.getOneByCounty(declaration.declaration?.company?.county);
const buffer = await this.jsxPdfService.buffer(DeclarationReceipt(declaration));

const url = `${config.host}/index-egapro/declaration/${siren}/${year}`;
Expand Down

0 comments on commit df79ef6

Please sign in to comment.