Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
feat(flux): limite la liste des types de références métier
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoBahamut committed Nov 18, 2019
1 parent ef1695b commit 6931fa3
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion worker/geojson-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function titreFormat({
amodiataires.map(t => entrepriseFormat(t)).join(', ')) ||
null,
references:
references && references.map(r => `${r.type}: ${r.valeur}`).join(', '),
references && references.map(r => `${r.type.nom}: ${r.nom}`).join(', '),
date_debut: dateDebut,
date_fin: dateFin,
date_demande: dateDemande,
Expand Down
34 changes: 29 additions & 5 deletions worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,28 @@ async function run() {
try {
// importe les requêtes graphQL
const titresQuery = await fileImport(join(__dirname, 'queries/titres.gql'))
const metasQuery = await fileImport(join(__dirname, 'queries/metas.gql'))
const typesQuery = await fileImport(join(__dirname, 'queries/types.gql'))
const domainesQuery = await fileImport(
join(__dirname, 'queries/domaines.gql')
)
const statutsQuery = await fileImport(
join(__dirname, 'queries/statuts.gql')
)

// efface le dossier cible et son contenu
await directoryDelete(join(__dirname, EXPORT_DIRECTORY))

// créé le dossier cible
await directoryCreate(join(__dirname, EXPORT_DIRECTORY))

// récupère les metas
const metas = await metasGet(apiUrl, metasQuery)
// récupère les types
const types = await typesGet(apiUrl, typesQuery)
// récupère les domaines
const domaines = await domainesGet(apiUrl, domainesQuery)
// récupère les statuts
const statuts = await statutsGet(apiUrl, statutsQuery)

const metas = { types, domaines, statuts }

// parcourt les définitions et construit un tableau de geojsons
// dont l'entrée properties contient, entre autre le nom du fichier
Expand All @@ -74,10 +86,22 @@ async function run() {
// fonctions
// ------------------------------------

async function metasGet(url, query) {
async function typesGet(url, query) {
const res = await apiFetch(url, JSON.stringify({ query }))

return res && res.data && res.data.types
}

async function domainesGet(url, query) {
const res = await apiFetch(url, JSON.stringify({ query }))

return res && res.data && res.data.domaines
}

async function statutsGet(url, query) {
const res = await apiFetch(url, JSON.stringify({ query }))

return res && res.data && res.data.metas
return res && res.data && res.data.statuts
}

async function titresGet(url, query, variables) {
Expand Down
6 changes: 6 additions & 0 deletions worker/queries/domaines.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query Domaines {
domaines {
id
nom
}
}
7 changes: 7 additions & 0 deletions worker/queries/statuts.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query Statuts {
statuts {
id
nom
couleur
}
}
11 changes: 9 additions & 2 deletions worker/queries/titres.gql
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ fragment titre on Titre {
nom
}
references {
type
valeur
...reference
}
dateDebut
dateFin
Expand Down Expand Up @@ -134,3 +133,11 @@ fragment substance on TitreSubstance {
nom
}
}

fragment reference on Reference {
type {
id
nom
}
nom
}
6 changes: 6 additions & 0 deletions worker/queries/types.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query Types {
types {
id
nom
}
}

0 comments on commit 6931fa3

Please sign in to comment.