Skip to content

Commit 4ffb581

Browse files
authored
feat(infographic): ajout des documents liés aux infographies (#1609)
1 parent 2e12e63 commit 4ffb581

File tree

30 files changed

+740
-88
lines changed

30 files changed

+740
-88
lines changed
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { DocumentElasticWithSource } from "./common";
2-
import { InfographicTemplateDoc } from "../hasura/infographic";
2+
import { HasuraDocument, InfographicTemplateDoc } from "../hasura";
33
import { SOURCES } from "@socialgouv/cdtn-utils";
4+
import { LinkedContent } from "./related-items";
45

56
export type InfographicElasticDocument = DocumentElasticWithSource<
6-
InfographicTemplateDoc,
7+
InfographicHasuraDoc,
78
typeof SOURCES.INFOGRAPHICS
89
>;
10+
11+
export type InfographicHasuraDoc = Omit<
12+
InfographicTemplateDoc,
13+
"cdtnReferences"
14+
> & {
15+
linkedContent: LinkedContent[];
16+
};

shared/types/src/hasura/infographic.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export type InfographicTemplateDoc = {
1818
meta_description: string;
1919
transcription: string;
2020
references: InfographicTemplateReference[];
21+
cdtnReferences: InfographicLinkedContent[];
22+
};
23+
24+
export type InfographicLinkedContent = {
25+
cdtnId: string;
2126
};
2227

2328
export type InfographicTemplateReference = {

targets/export-elasticsearch/src/ingester/cdtnDocuments.ts

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ElasticFicheTravailEmploi,
99
ExportEsStatus,
1010
FicheTravailEmploiDoc,
11-
InfographicTemplateDoc,
11+
InfographicTemplateDoc
1212
} from "@socialgouv/cdtn-types";
1313
import { logger } from "@shared/utils";
1414
import { SOURCES } from "@socialgouv/cdtn-utils";
@@ -18,21 +18,22 @@ import { buildThemes } from "./themes/buildThemes";
1818
import {
1919
getDocumentBySource,
2020
getDocumentBySourceWithRelation,
21-
} from "./common/fetchCdtnAdminDocuments";
21+
getGlossary,
22+
populateRelatedDocuments
23+
} from "./common";
2224
import { splitArticle } from "./fichesTravailSplitter";
2325
import {
2426
fetchContributionDocumentToPublish,
25-
generateContributions,
27+
generateContributions
2628
} from "./contributions";
2729
import { generateAgreements } from "./agreements";
2830
import { fetchThemes } from "./themes/fetchThemes";
2931
import { updateExportEsStatusWithDocumentsCount } from "./exportStatus/updateExportEsStatusWithDocumentsCount";
3032
import { generatePrequalified } from "./prequalified";
3133
import { generateEditorialContents } from "./informations/generate";
32-
import { populateRelatedDocuments } from "./common/populateRelatedDocuments";
3334
import { mergeRelatedDocumentsToEditorialContents } from "./informations/mergeRelatedDocumentsToEditorialContents";
3435
import { updateExportStatuses } from "./documents/updateExportStatuses";
35-
import { getGlossary } from "./common/fetchGlossary";
36+
import { generateInfographics } from "./infographics";
3637

3738
/**
3839
* Find duplicate slugs
@@ -49,7 +50,7 @@ export async function getDuplicateSlugs(allDocuments: any) {
4950
return slugs
5051
.map((slug: string) => ({
5152
count: slugs.filter((s: string) => slug === s).length,
52-
slug,
53+
slug
5354
}))
5455
.filter(({ count }: any) => count > 1)
5556
.reduce(
@@ -68,8 +69,9 @@ export async function cdtnDocumentsGen(
6869

6970
const getBreadcrumbs = buildGetBreadcrumbs(themes);
7071

71-
const contributionsToPublish =
72-
await fetchContributionDocumentToPublish(isProd);
72+
const contributionsToPublish = await fetchContributionDocumentToPublish(
73+
isProd
74+
);
7375

7476
logger.info("=== Courriers ===");
7577
const modelesDeCourriers = await getDocumentBySource(
@@ -78,15 +80,15 @@ export async function cdtnDocumentsGen(
7880
);
7981
documentsCount = {
8082
...documentsCount,
81-
[SOURCES.LETTERS]: modelesDeCourriers.length,
83+
[SOURCES.LETTERS]: modelesDeCourriers.length
8284
};
8385
await updateDocs(SOURCES.LETTERS, modelesDeCourriers);
8486

8587
logger.info("=== Outils ===");
8688
const tools = await getDocumentBySource(SOURCES.TOOLS, getBreadcrumbs);
8789
documentsCount = {
8890
...documentsCount,
89-
[SOURCES.TOOLS]: tools.length,
91+
[SOURCES.TOOLS]: tools.length
9092
};
9193
await updateDocs(SOURCES.TOOLS, tools);
9294

@@ -97,7 +99,7 @@ export async function cdtnDocumentsGen(
9799
);
98100
documentsCount = {
99101
...documentsCount,
100-
[SOURCES.EXTERNALS]: externalTools.length,
102+
[SOURCES.EXTERNALS]: externalTools.length
101103
};
102104
await updateDocs(SOURCES.EXTERNALS, externalTools);
103105

@@ -109,7 +111,7 @@ export async function cdtnDocumentsGen(
109111
);
110112
documentsCount = {
111113
...documentsCount,
112-
[SOURCES.THEMATIC_FILES]: dossiers.length,
114+
[SOURCES.THEMATIC_FILES]: dossiers.length
113115
};
114116

115117
await updateDocs(SOURCES.THEMATIC_FILES, dossiers);
@@ -148,7 +150,7 @@ export async function cdtnDocumentsGen(
148150

149151
documentsCount = {
150152
...documentsCount,
151-
[SOURCES.CONTRIBUTIONS]: generatedContributions.length,
153+
[SOURCES.CONTRIBUTIONS]: generatedContributions.length
152154
};
153155

154156
await updateDocs(SOURCES.CONTRIBUTIONS, generatedContributions);
@@ -161,7 +163,7 @@ export async function cdtnDocumentsGen(
161163

162164
documentsCount = {
163165
...documentsCount,
164-
[SOURCES.CCN]: agreementsDocs.length,
166+
[SOURCES.CCN]: agreementsDocs.length
165167
};
166168

167169
await updateDocs(SOURCES.CCN, agreementsDocs);
@@ -171,7 +173,7 @@ export async function cdtnDocumentsGen(
171173

172174
documentsCount = {
173175
...documentsCount,
174-
[SOURCES.SHEET_SP]: fichesSp.length,
176+
[SOURCES.SHEET_SP]: fichesSp.length
175177
};
176178
await updateDocs(SOURCES.SHEET_SP, fichesSp);
177179

@@ -188,17 +190,17 @@ export async function cdtnDocumentsGen(
188190
html: section.htmlWithGlossary,
189191
anchor: section.anchor,
190192
references: section.references,
191-
title: section.title,
193+
title: section.title
192194
})),
193-
source: SOURCES.SHEET_MT_PAGE,
195+
source: SOURCES.SHEET_MT_PAGE
194196
})
195197
);
196198
logger.info(
197199
`Mapped ${fichesMTWithGlossary.length} fiches travail with glossary`
198200
);
199201
documentsCount = {
200202
...documentsCount,
201-
[SOURCES.SHEET_MT_PAGE]: fichesMTWithGlossary.length,
203+
[SOURCES.SHEET_MT_PAGE]: fichesMTWithGlossary.length
202204
};
203205

204206
await updateDocs(SOURCES.SHEET_MT_PAGE, fichesMTWithGlossary);
@@ -214,20 +216,20 @@ export async function cdtnDocumentsGen(
214216
return {
215217
...fiche,
216218
breadcrumbs,
217-
source: SOURCES.SHEET_MT,
219+
source: SOURCES.SHEET_MT
218220
};
219221
});
220222
documentsCount = {
221223
...documentsCount,
222-
[SOURCES.SHEET_MT]: splittedFichesMt.length,
224+
[SOURCES.SHEET_MT]: splittedFichesMt.length
223225
};
224226
await updateDocs(SOURCES.SHEET_MT, splittedFichesMt);
225227

226228
logger.info("=== Themes ===");
227229
const themesDoc = buildThemes(themes, getBreadcrumbs);
228230
documentsCount = {
229231
...documentsCount,
230-
[SOURCES.THEMES]: themesDoc.length,
232+
[SOURCES.THEMES]: themesDoc.length
231233
};
232234

233235
await updateDocs(SOURCES.THEMES, themesDoc);
@@ -248,55 +250,56 @@ export async function cdtnDocumentsGen(
248250
);
249251
return {
250252
...ref,
251-
description: foundContrib?.description,
253+
description: foundContrib?.description
252254
};
253255
}
254256
return ref;
255-
}),
257+
})
256258
}));
257259
documentsCount = {
258260
...documentsCount,
259-
[SOURCES.HIGHLIGHTS]: highlightsWithContrib.length,
261+
[SOURCES.HIGHLIGHTS]: highlightsWithContrib.length
260262
};
261263
await updateDocs(SOURCES.HIGHLIGHTS, highlightsWithContrib);
262264

263265
logger.info("=== PreQualified Request ===");
264266
const prequalified = await generatePrequalified(getBreadcrumbs);
265267
documentsCount = {
266268
...documentsCount,
267-
[SOURCES.PREQUALIFIED]: prequalified.length,
269+
[SOURCES.PREQUALIFIED]: prequalified.length
268270
};
269271
await updateDocs(SOURCES.PREQUALIFIED, prequalified);
270272

271273
logger.info("=== glossary ===");
272274
const glossaryTerms = await getGlossary();
273275
documentsCount = {
274276
...documentsCount,
275-
[SOURCES.GLOSSARY]: glossaryTerms.length,
277+
[SOURCES.GLOSSARY]: glossaryTerms.length
276278
};
277279
await updateDocs(SOURCES.GLOSSARY, [
278280
{
279281
data: glossaryTerms,
280-
source: SOURCES.GLOSSARY,
281-
},
282+
source: SOURCES.GLOSSARY
283+
}
282284
]);
283285

284286
logger.info("=== Code du travail ===");
285287
const cdtDoc = await getDocumentBySource(SOURCES.CDT);
286288
documentsCount = {
287289
...documentsCount,
288-
[SOURCES.CDT]: cdtDoc.length,
290+
[SOURCES.CDT]: cdtDoc.length
289291
};
290292
await updateDocs(SOURCES.CDT, cdtDoc);
291293

292294
logger.info("=== Infographies ===");
293-
const infographics = await getDocumentBySource<InfographicTemplateDoc>(
295+
const infographicDocs = await getDocumentBySource<InfographicTemplateDoc>(
294296
SOURCES.INFOGRAPHICS,
295297
getBreadcrumbs
296298
);
299+
const infographics = await generateInfographics(infographicDocs);
297300
documentsCount = {
298301
...documentsCount,
299-
[SOURCES.INFOGRAPHICS]: infographics.length,
302+
[SOURCES.INFOGRAPHICS]: infographics.length
300303
};
301304
await updateDocs(SOURCES.INFOGRAPHICS, infographics);
302305

@@ -307,11 +310,11 @@ export async function cdtnDocumentsGen(
307310
);
308311
const {
309312
documents: editorialContents,
310-
relatedIdsDocuments: relatedIdsEditorialDocuments,
313+
relatedIdsDocuments: relatedIdsEditorialDocuments
311314
} = generateEditorialContents(documents, infographics);
312315
documentsCount = {
313316
...documentsCount,
314-
[SOURCES.EDITORIAL_CONTENT]: editorialContents.length,
317+
[SOURCES.EDITORIAL_CONTENT]: editorialContents.length
315318
};
316319

317320
logger.info("=== Merge Related Documents ===");
@@ -327,7 +330,7 @@ export async function cdtnDocumentsGen(
327330
...fichesMTWithGlossary,
328331
...splittedFichesMt,
329332
...highlightsWithContrib,
330-
...cdtDoc,
333+
...cdtDoc
331334
];
332335

333336
const relatedDocuments = populateRelatedDocuments(
@@ -348,7 +351,7 @@ export async function cdtnDocumentsGen(
348351
logger.info("=== Save the documents length ===");
349352
documentsCount = {
350353
...documentsCount,
351-
total: Object.values(documentsCount).reduce((a: any, b: any) => a + b, 0),
354+
total: Object.values(documentsCount).reduce((a: any, b: any) => a + b, 0)
352355
};
353356
await updateExportEsStatusWithDocumentsCount(
354357
documentsCount as ExportEsStatus["documentsCount"]

targets/export-elasticsearch/src/ingester/contributions/fetchLinkedContent.ts renamed to targets/export-elasticsearch/src/ingester/common/fetchLinkedContent.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,32 @@ interface HasuraReturn {
1717
documents: LinkedContent[];
1818
}
1919

20-
21-
2220
export async function fetchLinkedContent(
2321
cdtnId: string,
24-
questionIndex: number,
25-
idcc: string,
22+
logDetails: string
2623
): Promise<LinkedContent | undefined> {
2724
const HASURA_GRAPHQL_ENDPOINT =
2825
context.get("cdtnAdminEndpoint") || "http://localhost:8080/v1/graphql";
2926
const HASURA_GRAPHQL_ENDPOINT_SECRET =
3027
context.get("cdtnAdminEndpointSecret") || "admin1";
3128
const res = await gqlClient({
3229
graphqlEndpoint: HASURA_GRAPHQL_ENDPOINT,
33-
adminSecret: HASURA_GRAPHQL_ENDPOINT_SECRET,
30+
adminSecret: HASURA_GRAPHQL_ENDPOINT_SECRET
3431
})
3532
.query<HasuraReturn>(fetchLinkedContentById, {
36-
cdtnId: cdtnId,
33+
cdtnId: cdtnId
3734
})
3835
.toPromise();
3936
if (res.error) {
4037
console.log(
4138
"Error",
42-
`Impossible de récupérer la contenu lié avec l'id ${cdtnId} (QR${questionIndex} - IDCC ${idcc})`,
43-
res.error,
39+
`Impossible de récupérer la contenu lié avec l'id ${cdtnId} (${logDetails})`,
40+
res.error
4441
);
4542
throw res.error;
4643
}
4744
if (!res.data?.documents.length) {
48-
logger.info(
49-
`Warning: Pas de contenu lié ${cdtnId}, voir QR${questionIndex} - IDCC ${idcc}`,
50-
);
45+
logger.info(`Warning: Pas de contenu lié ${cdtnId}, (${logDetails})`);
5146
return;
5247
}
5348
return res.data.documents[0];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from "./fetchCdtnAdminDocuments";
2+
export * from "./fetchGlossary";
3+
export * from "./fetchLinkedContent";
4+
export * from "./populateRelatedDocuments";

targets/export-elasticsearch/src/ingester/contributions/__tests__/generateLinkedContent.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { generateLinkedContent } from "../generateLinkedContent";
2-
import { fetchLinkedContent } from "../fetchLinkedContent";
2+
import { fetchLinkedContent } from "../../common/fetchLinkedContent";
33
import { ContributionElasticDocumentLightRelatedContent } from "../generate";
44
import { LinkedContent } from "@socialgouv/cdtn-types/build/elastic/related-items";
55

6-
jest.mock("../fetchLinkedContent");
6+
jest.mock("../../common/fetchLinkedContent");
77

88
describe("generateLinkedContent", () => {
99
beforeEach(() => {

0 commit comments

Comments
 (0)