From eecdb7d5482e92fa4a6d29a11d00108d918fbc04 Mon Sep 17 00:00:00 2001 From: maxgfr <25312957+maxgfr@users.noreply.github.com> Date: Tue, 18 Jul 2023 17:03:43 +0200 Subject: [PATCH] fix(1740): remove from alert-cli and migration --- .../src/api/config.ts | 3 +++ .../src/api/modules/enterprises/service.ts | 25 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 packages/code-du-travail-frontend/src/api/config.ts diff --git a/packages/code-du-travail-frontend/src/api/config.ts b/packages/code-du-travail-frontend/src/api/config.ts new file mode 100644 index 0000000000..e3c20396af --- /dev/null +++ b/packages/code-du-travail-frontend/src/api/config.ts @@ -0,0 +1,3 @@ +export const IDCC_TO_REPLACE = { + 1740: [1596, 1597], +} as const; diff --git a/packages/code-du-travail-frontend/src/api/modules/enterprises/service.ts b/packages/code-du-travail-frontend/src/api/modules/enterprises/service.ts index d21701623a..4e77d3cbf2 100644 --- a/packages/code-du-travail-frontend/src/api/modules/enterprises/service.ts +++ b/packages/code-du-travail-frontend/src/api/modules/enterprises/service.ts @@ -2,6 +2,7 @@ import { SearchResponse, Agreement } from "@socialgouv/cdtn-utils"; import { elasticDocumentsIndex, elasticsearchClient } from "../../utils"; import { getAgreements } from "./queries"; import { EnterpriseApiResponse, ApiEnterpriseData, Convention } from "./types"; +import { IDCC_TO_REPLACE } from "../../config"; const toAgreement = (convention: Convention): Agreement => ({ id: convention.id, @@ -18,6 +19,12 @@ export const populateAgreements = async ( enterpriseApiResponse.entreprises?.flatMap((enterprise) => enterprise.conventions.flatMap((convention) => convention.idcc) ) ?? []; + const idccKeys = Object.keys(IDCC_TO_REPLACE); + const idcc = idccList.find((idcc) => idccKeys.includes(idcc.toString())); + if (idcc) { + const idccToAdd = IDCC_TO_REPLACE[idcc] as number[]; + idccList.push(...idccToAdd); + } if (idccList.length > 0) { const body = getAgreements(idccList); @@ -33,7 +40,8 @@ export const populateAgreements = async ( }, {} ); - return { + + const result = { ...enterpriseApiResponse, entreprises: enterpriseApiResponse.entreprises?.map((enterprise) => ({ ...enterprise, @@ -43,6 +51,21 @@ export const populateAgreements = async ( ), })), }; + + if (idcc) { + const idccToAdd = IDCC_TO_REPLACE[idcc] as number[]; + const conventionsToAdd: Agreement[] = idccToAdd + .map((idcc) => agreements[idcc]) + .filter((convention) => convention !== undefined); + result.entreprises = result.entreprises?.map((enterprise) => ({ + ...enterprise, + conventions: [...enterprise.conventions, ...conventionsToAdd].filter( + (convention) => convention.num !== idcc + ), + })); + } + + return result; } } return {