Skip to content
Snippets Groups Projects
Commit f69fc900 authored by SAFINE LAGET Anis's avatar SAFINE LAGET Anis Committed by SAFINE LAGET Anis
Browse files

fix ci

parent 82e28cba
No related branches found
No related tags found
1 merge request!1674chore(data): les prolongations doivent reprendre les mêmes infos que les octrois
Pipeline #540008 passed
...@@ -141,40 +141,46 @@ const checkOneProlongation = (pool: Pool, demarcheId: DemarcheId): Effect.Effect ...@@ -141,40 +141,46 @@ const checkOneProlongation = (pool: Pool, demarcheId: DemarcheId): Effect.Effect
const titreIdVideError = "Pas d'id de titre" as const const titreIdVideError = "Pas d'id de titre" as const
const upsertFailError = "Échec de mise à jour de l'étape" as const const upsertFailError = "Échec de mise à jour de l'étape" as const
const titreGetError = "Impossible de fetch le titre" as const const titreGetError = 'Impossible de fetch le titre' as const
const titreGetIsNullError = "Titre introuvable" as const const titreGetIsNullError = 'Titre introuvable' as const
const etapeIntrouvableError = "Étape introuvable dans le titre" as const const etapeIntrouvableError = 'Étape introuvable dans le titre' as const
const demarcheListIsEmptyError = "Liste des démarches héritables vide" as const const demarcheListIsEmptyError = 'Liste des démarches héritables vide' as const
type FixProlongationErrors = typeof titreIdVideError | typeof upsertFailError | typeof titreGetError | typeof titreGetIsNullError | typeof demarcheListIsEmptyError | typeof etapeIntrouvableError type FixProlongationErrors = typeof titreIdVideError | typeof upsertFailError | typeof titreGetError | typeof titreGetIsNullError | typeof demarcheListIsEmptyError | typeof etapeIntrouvableError
const fixProlongation = (pool: Pool, checkedProlongation: CheckedProlongation): Effect.Effect<null, CaminoError<FixProlongationErrors>> => { const fixProlongation = (pool: Pool, checkedProlongation: CheckedProlongation): Effect.Effect<null, CaminoError<FixProlongationErrors>> => {
return Effect.Do.pipe( return Effect.Do.pipe(
Effect.bind('titre', () => pipe( Effect.bind('titre', () =>
Effect.succeed(checkedProlongation.titre_id), pipe(
Effect.filterOrFail( Effect.succeed(checkedProlongation.titre_id),
(titreId) => isNotNullNorUndefined(titreId), Effect.filterOrFail(
() => ({ message: titreIdVideError }) titreId => isNotNullNorUndefined(titreId),
), () => ({ message: titreIdVideError })
Effect.flatMap((titreId) => Effect.tryPromise({ ),
try: () => getTitre(pool, userSuper, titreId), Effect.flatMap(titreId =>
catch: (error) => ({ message: titreGetError, extra: error }) Effect.tryPromise({
})), try: () => getTitre(pool, userSuper, titreId),
Effect.filterOrFail( catch: error => ({ message: titreGetError, extra: error }),
(titre): titre is NonNullable<typeof titre> => isNotNullNorUndefined(titre), })
(error) => ({ message: titreGetIsNullError, extra: error }) ),
Effect.filterOrFail(
(titre): titre is NonNullable<typeof titre> => isNotNullNorUndefined(titre),
error => ({ message: titreGetIsNullError, extra: error })
)
) )
)), ),
Effect.bind('etape', ({ titre }) => pipe( Effect.bind('etape', ({ titre }) =>
Effect.succeed(titre.demarches.find(({ id }) => id === checkedProlongation.demarche_id)), pipe(
Effect.filterOrFail( Effect.succeed(titre.demarches.find(({ id }) => id === checkedProlongation.demarche_id)),
(demarche): demarche is NonNullable<typeof demarche> => isNotNullNorUndefined(checkedProlongation.demarche_id) && isNotNullNorUndefined(demarche), Effect.filterOrFail(
() => ({ message: etapeIntrouvableError, extra: 'Démarche introuvable' }) (demarche): demarche is NonNullable<typeof demarche> => isNotNullNorUndefined(checkedProlongation.demarche_id) && isNotNullNorUndefined(demarche),
), () => ({ message: etapeIntrouvableError, extra: 'Démarche introuvable' })
Effect.map((demarche) => demarche.etapes.find(({ id }) => id === checkedProlongation.etape_id)), ),
Effect.filterOrFail( Effect.map(demarche => demarche.etapes.find(({ id }) => id === checkedProlongation.etape_id)),
(etape): etape is NonNullable<typeof etape> => isNotNullNorUndefined(checkedProlongation.etape_id) && isNotNullNorUndefined(etape), Effect.filterOrFail(
() => ({ message: etapeIntrouvableError, extra: 'Étape introuvable' }) (etape): etape is NonNullable<typeof etape> => isNotNullNorUndefined(checkedProlongation.etape_id) && isNotNullNorUndefined(etape),
() => ({ message: etapeIntrouvableError, extra: 'Étape introuvable' })
)
) )
)), ),
Effect.bind('propsHeritees', ({ titre }) => Effect.bind('propsHeritees', ({ titre }) =>
Effect.Do.pipe( Effect.Do.pipe(
Effect.bind('demarches', () => { Effect.bind('demarches', () => {
...@@ -201,7 +207,7 @@ const fixProlongation = (pool: Pool, checkedProlongation: CheckedProlongation): ...@@ -201,7 +207,7 @@ const fixProlongation = (pool: Pool, checkedProlongation: CheckedProlongation):
Effect.flatMap(({ titre, etape, propsHeritees }) => Effect.flatMap(({ titre, etape, propsHeritees }) =>
Effect.tryPromise({ Effect.tryPromise({
try: () => { try: () => {
console.log(`Trying to fix http://localhost:4180/etapes/${etape.id}`) console.info(`Trying to fix http://localhost:4180/etapes/${etape.id}`)
return titreEtapeUpsert( return titreEtapeUpsert(
{ {
id: etape.id, id: etape.id,
...@@ -210,9 +216,18 @@ const fixProlongation = (pool: Pool, checkedProlongation: CheckedProlongation): ...@@ -210,9 +216,18 @@ const fixProlongation = (pool: Pool, checkedProlongation: CheckedProlongation):
substances: 'fondamentale' in etape && isNotNullNorUndefinedNorEmpty(etape.fondamentale.substances) ? etape.fondamentale.substances : propsHeritees.substances, substances: 'fondamentale' in etape && isNotNullNorUndefinedNorEmpty(etape.fondamentale.substances) ? etape.fondamentale.substances : propsHeritees.substances,
titulaireIds: 'fondamentale' in etape && isNotNullNorUndefinedNorEmpty(etape.fondamentale.titulaireIds) ? etape.fondamentale.titulaireIds : propsHeritees.titulaireIds, titulaireIds: 'fondamentale' in etape && isNotNullNorUndefinedNorEmpty(etape.fondamentale.titulaireIds) ? etape.fondamentale.titulaireIds : propsHeritees.titulaireIds,
surface: 'fondamentale' in etape && isNotNullNorUndefined(etape.fondamentale.perimetre?.surface) ? etape.fondamentale.perimetre.surface : propsHeritees.perimetre?.surface, surface: 'fondamentale' in etape && isNotNullNorUndefined(etape.fondamentale.perimetre?.surface) ? etape.fondamentale.perimetre.surface : propsHeritees.perimetre?.surface,
geojson4326Perimetre: 'fondamentale' in etape && isNotNullNorUndefined(etape.fondamentale.perimetre?.geojson4326_perimetre) ? etape.fondamentale.perimetre.geojson4326_perimetre : propsHeritees.perimetre?.geojson4326_perimetre, geojson4326Perimetre:
geojsonOriginePerimetre: 'fondamentale' in etape && isNotNullNorUndefined(etape.fondamentale.perimetre?.geojson_origine_perimetre) ? etape.fondamentale.perimetre.geojson_origine_perimetre : propsHeritees.perimetre?.geojson_origine_perimetre, 'fondamentale' in etape && isNotNullNorUndefined(etape.fondamentale.perimetre?.geojson4326_perimetre)
geojsonOrigineGeoSystemeId: 'fondamentale' in etape && isNotNullNorUndefined(etape.fondamentale.perimetre?.geojson_origine_geo_systeme_id) ? etape.fondamentale.perimetre.geojson_origine_geo_systeme_id : propsHeritees.perimetre?.geojson_origine_geo_systeme_id, ? etape.fondamentale.perimetre.geojson4326_perimetre
: propsHeritees.perimetre?.geojson4326_perimetre,
geojsonOriginePerimetre:
'fondamentale' in etape && isNotNullNorUndefined(etape.fondamentale.perimetre?.geojson_origine_perimetre)
? etape.fondamentale.perimetre.geojson_origine_perimetre
: propsHeritees.perimetre?.geojson_origine_perimetre,
geojsonOrigineGeoSystemeId:
'fondamentale' in etape && isNotNullNorUndefined(etape.fondamentale.perimetre?.geojson_origine_geo_systeme_id)
? etape.fondamentale.perimetre.geojson_origine_geo_systeme_id
: propsHeritees.perimetre?.geojson_origine_geo_systeme_id,
}, },
userSuper, userSuper,
titre.id titre.id
...@@ -222,8 +237,8 @@ const fixProlongation = (pool: Pool, checkedProlongation: CheckedProlongation): ...@@ -222,8 +237,8 @@ const fixProlongation = (pool: Pool, checkedProlongation: CheckedProlongation):
}) })
), ),
Effect.map(() => null), Effect.map(() => null),
Effect.catchAll((error) => { Effect.catchAll(error => {
console.log(error) console.info(error)
return Effect.succeed(null) return Effect.succeed(null)
}) })
) )
...@@ -256,7 +271,7 @@ export const checkProlongations = (pool: Pool): Effect.Effect<CheckedProlongatio ...@@ -256,7 +271,7 @@ export const checkProlongations = (pool: Pool): Effect.Effect<CheckedProlongatio
// const link = isNotNullNorUndefined(checkedProlongation.titre_slug) // const link = isNotNullNorUndefined(checkedProlongation.titre_slug)
// ? `http://localhost:4180/titres/${checkedProlongation.titre_slug}` // ? `http://localhost:4180/titres/${checkedProlongation.titre_slug}`
// : `http://localhost:4180/demarches/${checkedProlongation.demarche_id}` // : `http://localhost:4180/demarches/${checkedProlongation.demarche_id}`
// console.log(`${link} : ${checkedProlongation.errors.join(' | ')}`) // console.info(`${link} : ${checkedProlongation.errors.join(' | ')}`)
// } // }
return [...acc, checkedProlongation] return [...acc, checkedProlongation]
...@@ -271,7 +286,7 @@ export const checkProlongations = (pool: Pool): Effect.Effect<CheckedProlongatio ...@@ -271,7 +286,7 @@ export const checkProlongations = (pool: Pool): Effect.Effect<CheckedProlongatio
const prolongationsAvecDureeManquante = prolongations.filter(({ errors }) => errors.some(error => error.includes('la durée est obligatoire'))) const prolongationsAvecDureeManquante = prolongations.filter(({ errors }) => errors.some(error => error.includes('la durée est obligatoire')))
const prolongationsParType = prolongationsEnVrac.reduce<{ [key: string]: number }>((acc, prolongation) => { const prolongationsParType = prolongationsEnVrac.reduce<{ [key: string]: number }>((acc, prolongation) => {
const domaine = isNotNullNorUndefined(prolongation.titre_slug) ? `${prolongation.titre_slug.slice(2, 4)}${ prolongation.titre_slug.slice(0, 1)}` : 'inconnu' const domaine = isNotNullNorUndefined(prolongation.titre_slug) ? `${prolongation.titre_slug.slice(2, 4)}${prolongation.titre_slug.slice(0, 1)}` : 'inconnu'
if (isNullOrUndefined(acc[domaine])) { if (isNullOrUndefined(acc[domaine])) {
acc[domaine] = 1 acc[domaine] = 1
} else { } else {
...@@ -280,9 +295,9 @@ export const checkProlongations = (pool: Pool): Effect.Effect<CheckedProlongatio ...@@ -280,9 +295,9 @@ export const checkProlongations = (pool: Pool): Effect.Effect<CheckedProlongatio
return acc return acc
}, {}) }, {})
console.log(`Prolongations en vrac : ${prolongationsEnVrac.length} (${toPercentage(prolongationsEnVrac.length / prolongations.length)})`) console.info(`Prolongations en vrac : ${prolongationsEnVrac.length} (${toPercentage(prolongationsEnVrac.length / prolongations.length)})`)
console.log(JSON.stringify(prolongationsParType, null, 2)) console.info(JSON.stringify(prolongationsParType, null, 2))
console.log(`Prolongations sans durée : ${prolongationsAvecDureeManquante.length} (${toPercentage(prolongationsAvecDureeManquante.length / prolongationsEnVrac.length)})`) console.info(`Prolongations sans durée : ${prolongationsAvecDureeManquante.length} (${toPercentage(prolongationsAvecDureeManquante.length / prolongationsEnVrac.length)})`)
}) })
) )
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment