-
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.
feat: implement new route for aquagir rex export
- Loading branch information
Showing
5 changed files
with
125 additions
and
2 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,54 @@ | ||
import { NextResponse } from "next/server"; | ||
import { getAquagirRetoursExperiences } from "@/src/lib/strapi/queries/retoursExperienceQueries"; | ||
import { RetourExperience } from "@/src/lib/strapi/types/api/retour-experience"; | ||
import join from "lodash/join"; | ||
import { getFullUrl, PFMV_ROUTES } from "@/src/helpers/routes"; | ||
import { GeoJsonAdresse } from "@/src/components/sourcing/types"; | ||
import { getStrapiImageUrl } from "@/src/lib/strapi/strapiClient"; | ||
import { captureError } from "@/src/lib/sentry/sentryCustomMessage"; | ||
|
||
type AquagirRetourExperience = { | ||
id: number; | ||
titre: string; | ||
description: string; | ||
contenu: string; | ||
url: string; | ||
codeInsee: string; | ||
datePublication?: Date; | ||
image: string; | ||
}; | ||
|
||
const rexToAquagirRex = (rex: RetourExperience): AquagirRetourExperience => ({ | ||
id: rex.id, | ||
titre: rex.attributes.titre, | ||
description: rex.attributes.description, | ||
contenu: join( | ||
[ | ||
rex.attributes.titre, | ||
rex.attributes.citations.map((citation) => `${citation.auteur} ${citation.texte}`).join(" "), | ||
rex.attributes.description, | ||
rex.attributes.solution_retour_experiences?.data | ||
.map((sol) => ` ${sol.attributes.titre} ${sol.attributes.description} `) | ||
.join(" "), | ||
rex.attributes.situation_avant?.description, | ||
rex.attributes.situation_apres?.description, | ||
rex.attributes.partenaires, | ||
rex.attributes.credits, | ||
], | ||
" ", | ||
), | ||
url: getFullUrl(PFMV_ROUTES.RETOUR_EXPERIENCE(rex.attributes.slug)), | ||
codeInsee: (rex.attributes.location as GeoJsonAdresse).properties.citycode, | ||
datePublication: rex.attributes.publishedAt, | ||
image: getStrapiImageUrl(rex.attributes.image_principale, "medium"), | ||
}); | ||
|
||
export async function GET() { | ||
const response = await getAquagirRetoursExperiences(); | ||
console.log("Appel de l'API Aquagir"); | ||
if (response) { | ||
return NextResponse.json(response.map(rexToAquagirRex)); | ||
} | ||
captureError("Erreur lors de l'appel à l'API Aquagir"); | ||
return NextResponse.json(null); | ||
} |
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
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