Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stocker le département principal si ce dernier est rempli en cas d'absence des autres infos de localisation #137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion outils/sync-démarches-simplifiées-88444.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import _schema88444 from '../data/démarches-simplifiées/schema-DS-88444.json'
/** @import {default as Personne, PersonneInitializer} from '../scripts/types/database/public/Personne.ts' */
/** @import {default as Entreprise} from '../scripts/types/database/public/Entreprise.ts' */
/** @import {AnnotationsPriveesDemarcheSimplifiee88444, DossierDemarcheSimplifiee88444} from '../scripts/types/démarches-simplifiées/DémarcheSimplifiée88444.ts' */
/** @import {DémarchesSimpliféesCommune, BaseChampDS, ChampDSCommunes, ChampDSDépartements, ChampDSRégions, Dossier as DossierDS, Traitement, Message } from '../scripts/types/démarches-simplifiées/apiSchema.ts' */
/** @import {DémarchesSimpliféesCommune, BaseChampDS, ChampDSCommunes, ChampDSDépartements, ChampDSRégions, Dossier as DossierDS, Traitement, Message, ChampDSDépartement, DémarchesSimpliféesDépartement } from '../scripts/types/démarches-simplifiées/apiSchema.ts' */
/** @import {SchemaDémarcheSimplifiée, ChampDescriptor} from '../scripts/types/démarches-simplifiées/schema.ts' */
/** @import {DossierPourSynchronisation} from '../scripts/types/démarches-simplifiées/DossierPourSynchronisation.ts' */

Expand Down Expand Up @@ -169,12 +169,16 @@ const dossiersPourSynchronisation = dossiersDS.map((
const champCommunes = champById.get(pitchouKeyToChampDS.get('Commune(s) où se situe le projet'))
/** @type {ChampDSDépartements} */
const champDépartements = champById.get(pitchouKeyToChampDS.get('Département(s) où se situe le projet'))
/** @type {ChampDSDépartement} */
const champDépartementPrincipal = champById.get(pitchouKeyToChampDS.get('Dans quel département se localise majoritairement votre projet ?'))
/** @type {ChampDSRégions} */
const champRégions = champById.get(pitchouKeyToChampDS.get('Région(s) où se situe le projet'))


/** @type {DémarchesSimpliféesCommune[] | undefined} */
let communes;

/** @type {DémarchesSimpliféesDépartement['code'][] | undefined} */
let départements;
let régions;

Expand Down Expand Up @@ -210,6 +214,12 @@ const dossiersPourSynchronisation = dossiersDS.map((
}
}

// Si la localisation avec les champs dédiés (surtout communes et départements) a échoué,
// se rabattre sur le champ du département principal s'il est présent
if(champDépartementPrincipal && (!départements || départements.length === 0)){
départements = [champDépartementPrincipal.departement.code]
}


/*
Demandeur
Expand Down
14 changes: 8 additions & 6 deletions scripts/types/démarches-simplifiées/apiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@ export interface DémarchesSimpliféesCommune{
postalCode: string
}

export interface DémarchesSimpliféesDépartement {
name: string
code: string
}


interface BaseChampDSCommune extends BaseChampDS {
commune: DémarchesSimpliféesCommune
departement: DémarchesSimpliféesDépartement
}

export type ChampDSCommunes = BaseRepetitionChampsDS<BaseChampDSCommune>

export interface DémarchesSimpliféesDépartement {
name: string
code: string
}

interface BaseChampDSDépartement extends BaseChampDS {
export interface ChampDSDépartement extends BaseChampDS {
departement: DémarchesSimpliféesDépartement
}

export type ChampDSDépartements = BaseRepetitionChampsDS<BaseChampDSDépartement>
export type ChampDSDépartements = BaseRepetitionChampsDS<ChampDSDépartement>

export interface BaseChampDSRégion extends BaseChampDS {
region: {
Expand Down
Loading