-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correction et ajout de certains types manquants (#1464)
- Loading branch information
Showing
9 changed files
with
134 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { DocumentElasticWithSource } from "./common"; | ||
import { MailTemplateDoc } from "../hasura"; | ||
|
||
export type MailElasticDocument = DocumentElasticWithSource< | ||
MailTemplateDoc, | ||
"modeles_de_courriers" | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DocumentElasticWithSource } from "./common"; | ||
|
||
export type ThemeElasticDocument = DocumentElasticWithSource< | ||
ThemeElastic, | ||
"themes" | ||
>; | ||
|
||
export type ThemeElastic = { | ||
children: ThemeChildren[]; | ||
description?: string; | ||
icon?: string; | ||
position: number; | ||
}; | ||
|
||
export type ThemeChildren = { | ||
label: string; | ||
slug: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
targets/export-elasticsearch/src/ingester/themes/buildThemes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Theme, ThemeContentRelation } from "../types/themes"; | ||
import { GetBreadcrumbsFn } from "../breadcrumbs"; | ||
import { ThemeElasticDocument } from "@socialgouv/cdtn-types/build/elastic/theme"; | ||
import { DocumentRef } from "@socialgouv/cdtn-types"; | ||
|
||
export function buildThemes( | ||
themes: Theme[], | ||
getBreadcrumbs: GetBreadcrumbsFn | ||
): ThemeElasticDocument[] { | ||
return themes.map( | ||
({ | ||
cdtnId, | ||
id, | ||
slug, | ||
source, | ||
title, | ||
document: { icon, description }, | ||
contentRelations, | ||
parentRelations, | ||
}) => { | ||
const breadcrumbs = getBreadcrumbs(cdtnId); | ||
return { | ||
breadcrumbs: breadcrumbs.slice(0, -1), | ||
cdtnId, | ||
text: title, | ||
excludeFromSearch: false, | ||
metaDescription: `Explorez les contenus autour du thème ${title}`, | ||
children: themes | ||
.filter( | ||
({ parentRelations }) => parentRelations[0].parentThemeId === cdtnId | ||
) | ||
.sort( | ||
( | ||
{ parentRelations: [{ position: positionA }] }, | ||
{ parentRelations: [{ position: positionB }] } | ||
) => positionA - positionB | ||
) | ||
.map(({ slug, title }) => ({ | ||
label: title, | ||
slug, | ||
})), | ||
description, | ||
icon, | ||
id, | ||
isPublished: true, | ||
position: parentRelations[0].position, | ||
refs: getContentRelation(contentRelations, getBreadcrumbs), | ||
slug, | ||
source, | ||
title, | ||
}; | ||
} | ||
); | ||
} | ||
|
||
const getContentRelation = ( | ||
contentRelations: ThemeContentRelation[], | ||
getBreadcrumbs: GetBreadcrumbsFn | ||
): DocumentRef[] => { | ||
return contentRelations | ||
.sort( | ||
({ position: positionA }, { position: positionB }) => | ||
positionA - positionB | ||
) | ||
.map(({ content: { cdtnId, description, url, slug, source, title } }) => ({ | ||
cdtnId, | ||
description, | ||
url, | ||
slug, | ||
source, | ||
title, | ||
breadcrumbs: getBreadcrumbs(cdtnId), | ||
})); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters