Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

fix: corrige le calcul des amodiataires #602

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sources/domaines.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
},
{
"id": "i",
"nom": "inconnu",
"description": "Domaine inconnu",
"nom": "indéterminé",
"description": "Domaine indéterminé",
"ordre": "9"
}
]
2 changes: 1 addition & 1 deletion sources/titres-types-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
{
"id": "in",
"nom": "inconnu",
"nom": "indéterminé",
"description": "Inconnu",
"exploitation": "FALSE",
"ordre": "8"
Expand Down
1 change: 1 addition & 0 deletions src/api/graphql/resolvers/entreprises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const etapeEntreprises = async (
{
fields: {
demarches: {
phase: { id: {} },
etapes: {
titulaires: fields.elements,
amodiataires: fields.elements
Expand Down
8 changes: 4 additions & 4 deletions src/business/_updates-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const updatesLog = ({
titresAdministrationsGestionnairesDeleted,
titresEtapesAdministrationsLocalesCreated,
titresEtapesAdministrationsLocalesDeleted,
titresPropsEtapeIdUpdated,
titresPropsEtapesIdsUpdated,
titresPropsContenuUpdated,
titresCoordonneesUpdated,
titresTravauxEtapesOrdreUpdated,
Expand Down Expand Up @@ -61,7 +61,7 @@ const updatesLog = ({
titresAdministrationsGestionnairesDeleted?: string[]
titresEtapesAdministrationsLocalesCreated?: ITitreAdministrationLocale[]
titresEtapesAdministrationsLocalesDeleted?: ITitreAdministrationLocale[]
titresPropsEtapeIdUpdated?: string[]
titresPropsEtapesIdsUpdated?: string[]
titresPropsContenuUpdated?: string[]
titresCoordonneesUpdated?: string[]
titresTravauxEtapesOrdreUpdated?: string[]
Expand Down Expand Up @@ -193,9 +193,9 @@ const updatesLog = ({
)
}

if (titresPropsEtapeIdUpdated?.length) {
if (titresPropsEtapesIdsUpdated?.length) {
console.info(
`mise à jour: ${titresPropsEtapeIdUpdated.length} titres(s) (propriétés-étapes)`
`mise à jour: ${titresPropsEtapesIdsUpdated.length} titres(s) (propriétés-étapes)`
)
}

Expand Down
6 changes: 3 additions & 3 deletions src/business/daily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { titresIdsUpdate } from './processes/titres-ids-update'
import titresPhasesUpdate from './processes/titres-phases-update'
import titresPointsReferencesCreate from './processes/titres-points-references-create'
import titresPublicUpdate from './processes/titres-public-update'
import titresPropsEtapeIdUpdate from './processes/titres-props-etape-id-update'
import titresPropsEtapesIdsUpdate from './processes/titres-props-etapes-ids-update'
import titresPropsContenuUpdate from './processes/titres-props-contenu-update'
import titresStatutIdsUpdate from './processes/titres-statut-ids-update'
import titresTravauxOrdreUpdate from './processes/titres-travaux-ordre-update'
Expand Down Expand Up @@ -58,7 +58,7 @@ const daily = async () => {
titresEtapesAdministrationsLocalesCreated,
titresEtapesAdministrationsLocalesDeleted
} = await titresEtapesAdministrationsLocalesUpdate()
const titresPropsEtapeIdUpdated = await titresPropsEtapeIdUpdate()
const titresPropsEtapesIdsUpdated = await titresPropsEtapesIdsUpdate()
const titresPropsContenuUpdated = await titresPropsContenuUpdate()

const titresCoordonneesUpdated = await titresCoordonneesUpdate()
Expand Down Expand Up @@ -94,7 +94,7 @@ const daily = async () => {
titresAdministrationsGestionnairesDeleted,
titresEtapesAdministrationsLocalesCreated,
titresEtapesAdministrationsLocalesDeleted,
titresPropsEtapeIdUpdated,
titresPropsEtapesIdsUpdated,
titresPropsContenuUpdated,
titresCoordonneesUpdated,
titresTravauxEtapesOrdreUpdated,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mocked } from 'ts-jest/utils'
import titresPropsEtapeIdUpdate from './titres-props-etape-id-update'
import titresPropsEtapesIdsUpdate from './titres-props-etapes-ids-update'
import titrePropEtapeIdFind from '../rules/titre-prop-etape-id-find'
import { titresGet } from '../../database/queries/titres'
import Titres from '../../database/models/titres'
Expand All @@ -25,7 +25,7 @@ describe("propriétés (étape) d'un titre", () => {
({ titulairesTitreEtapeId: null } as unknown) as Titres
])

const titresUpdatedRequests = await titresPropsEtapeIdUpdate()
const titresUpdatedRequests = await titresPropsEtapesIdsUpdate()

expect(titresUpdatedRequests.length).toEqual(1)
expect(console.info).toHaveBeenCalled()
Expand All @@ -37,7 +37,7 @@ describe("propriétés (étape) d'un titre", () => {
({ titulairesTitreEtapeId: null } as unknown) as Titres
])

const titresUpdatedRequests = await titresPropsEtapeIdUpdate()
const titresUpdatedRequests = await titresPropsEtapesIdsUpdate()

expect(titresUpdatedRequests.length).toEqual(0)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ITitre, TitreProp, TitreEtapeProp } from '../../types'
import { ITitre, ITitreProp, ITitreEtapeProp } from '../../types'
import PQueue from 'p-queue'

import { titresGet, titreUpdate } from '../../database/queries/titres'
Expand All @@ -16,11 +16,11 @@ const titrePropsEtapes = [
prop,
name: `${prop}TitreEtapeId`
})) as {
prop: TitreEtapeProp
name: TitreProp
prop: ITitreEtapeProp
name: ITitreProp
}[]

const titresPropsEtapeIdsUpdate = async (titresIds?: string[]) => {
const titresPropsEtapesIdsUpdate = async (titresIds?: string[]) => {
console.info()
console.info('propriétés des titres (liens vers les étapes)…')
const queue = new PQueue({ concurrency: 100 })
Expand All @@ -30,6 +30,7 @@ const titresPropsEtapeIdsUpdate = async (titresIds?: string[]) => {
{
fields: {
demarches: {
phase: { id: {} },
etapes: {
points: { id: {} },
titulaires: { id: {} },
Expand All @@ -44,50 +45,50 @@ const titresPropsEtapeIdsUpdate = async (titresIds?: string[]) => {
'super'
)

const titresPropsEtapeIdsUpdated = [] as string[]
const titresPropsEtapesIdsUpdated = [] as string[]

titres.forEach(titre => {
const props = titrePropsEtapes.reduce(
(props: Partial<ITitre>, { prop, name }) => {
const value = titrePropEtapeIdFind(
const propsEtapesIds = titrePropsEtapes.reduce(
(propsEtapesIds: Partial<ITitre>, { prop, name }) => {
const titreEtapeId = titrePropEtapeIdFind(
prop,
titre.demarches!,
titre.statutId!,
prop
titre.statutId!
)

// si
// - la valeur de la prop est différente de celle du titre
// - la valeur existe ou elle existe dans le titre
if (value !== titre[name] && (titre[name] || value)) {
props[name] = value
// - l'id de l'étape est différente de celle du titre
// - l'id de l'étape existe ou elle existe dans le titre
if (titreEtapeId !== titre[name] && (titre[name] || titreEtapeId)) {
propsEtapesIds[name] = titreEtapeId
}

return props
return propsEtapesIds
},
{}
)

if (Object.keys(props).length) {
if (Object.keys(propsEtapesIds).length) {
queue.add(async () => {
await titreUpdate(titre.id, props)
await titreUpdate(titre.id, propsEtapesIds)

const log = {
type: 'titre : props-etape (mise à jour) ->',
value: `${titre.id} : ${JSON.stringify(props)}`
type: "titre : ids d'étapes des props (mise à jour) ->",
value: `${titre.id} : ${JSON.stringify(propsEtapesIds)}`
}

console.info(log.type, log.value)

titresPropsEtapeIdsUpdated.push(titre.id)
titresPropsEtapesIdsUpdated.push(titre.id)
})
}
})

await queue.onIdle()

return titresPropsEtapeIdsUpdated
return titresPropsEtapesIdsUpdated
}

export { titrePropsEtapes }

export default titresPropsEtapeIdsUpdate
export default titresPropsEtapesIdsUpdate
21 changes: 15 additions & 6 deletions src/business/rules/__mocks__/titre-prop-etape-id-find-demarches.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ITitreDemarche } from '../../../types'
import { ITitreDemarche, ITitrePhase } from '../../../types'

const titreDemarchesOctPointsMut = {
statutId: 'val',
Expand Down Expand Up @@ -255,7 +255,8 @@ const titreDemarchesOctAmodiatairesPassee = {
dateFin: '2018-12-31',
amodiataires: [{ id: 'fr-123456789' }]
}
]
],
phase: { statutId: 'val' }
}
] as ITitreDemarche[]
}
Expand All @@ -264,21 +265,29 @@ const titreDemarchesOctAmodiatairesValide = {
statutId: 'mod',
demarches: [
{
id: 'h-cx-courdemanges-1982-oct01',
id: 'h-cx-courdemanges-1982-amo01',
titreId: 'h-cx-courdemanges-1982',
typeId: 'oct',
typeId: 'amo',
statutId: 'acc',
etapes: [
{
id: 'h-cx-courdemanges-1982-oct01-dpu01',
titreDemarcheId: 'h-cx-courdemanges-1982-oct01',
id: 'h-cx-courdemanges-1982-amo01-dpu01',
titreDemarcheId: 'h-cx-courdemanges-1982-amo01',
typeId: 'dpu',
statutId: 'acc',
ordre: 1,
dateFin: '4018-12-31',
amodiataires: [{ id: 'fr-123456789' }]
}
]
},
{
id: 'h-cx-courdemanges-1982-oct01',
titreId: 'h-cx-courdemanges-1982',
typeId: 'oct',
statutId: 'acc',
phase: { statutId: 'val' } as ITitrePhase,
etapes: []
}
] as ITitreDemarche[]
}
Expand Down
10 changes: 5 additions & 5 deletions src/business/rules/titre-etape-prop-find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ITitreDemarche,
ITitre,
ITitreEtape,
TitreEtapeProp
ITitreEtapeProp
} from '../../types'

import titrePropEtapeIdFind from './titre-prop-etape-id-find'
Expand All @@ -27,7 +27,7 @@ const titreEtapeFind = (
return titreEtape
}

const propFind = (titreEtapes: ITitreEtape[], prop: TitreEtapeProp) => {
const propFind = (titreEtapes: ITitreEtape[], prop: ITitreEtapeProp) => {
for (const titreEtape of titreEtapes) {
const value = titreEtape[prop]

Expand Down Expand Up @@ -71,7 +71,7 @@ const titreDemarchesEtapesFilter = (

// trouve relative à une étape
const titreEtapePropFind = (
prop: TitreEtapeProp,
prop: ITitreEtapeProp,
titreEtape: ITitreEtape,
titreDemarcheEtapes: ITitreEtape[],
titre: ITitre
Expand Down Expand Up @@ -103,9 +103,9 @@ const titreEtapePropFind = (
// cherche la première occurrence de la propriété
// dans une démarche et une étape valides
const propTitreEtapeId = titrePropEtapeIdFind(
prop,
titre.demarches,
titre.statutId!,
prop
titre.statutId!
)

if (propTitreEtapeId) {
Expand Down
Loading