Skip to content

Commit

Permalink
fix(1740): remove from alert-cli and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Jul 18, 2023
1 parent 806b4d8 commit eecdb7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/code-du-travail-frontend/src/api/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const IDCC_TO_REPLACE = {
1740: [1596, 1597],
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -33,7 +40,8 @@ export const populateAgreements = async (
},
{}
);
return {

const result = {
...enterpriseApiResponse,
entreprises: enterpriseApiResponse.entreprises?.map((enterprise) => ({
...enterprise,
Expand All @@ -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 {
Expand Down

0 comments on commit eecdb7d

Please sign in to comment.