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

Commit

Permalink
feat(openfisca): mise à jour de la structure des objets échangés avec…
Browse files Browse the repository at this point in the history
… Openfisca
  • Loading branch information
vmaubert committed Mar 17, 2022
1 parent e31d21d commit 27160c7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/dev/api-openfisca-call.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dotenv/config'
import { redevanceCommunaleMinesAurifiereGet } from '../tools/api-openfisca'

async function main() {
Expand Down
50 changes: 40 additions & 10 deletions src/tools/api-openfisca/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,47 @@ import fetch from 'node-fetch'

import errorLog from '../error-log'

/*
eslint-disable camelcase
*/

interface IOpenfiscaBody {
societes: {
[titreId: string]: {
// eslint-disable-next-line camelcase
quantite_aurifere_kg: {
articles: {
[titreId_substance_commune: string]: {
quantite_aurifere_kg?: {
[annee: string]: number | null
}
surface_communale?: {
[annee: string]: number | null
}
// eslint-disable-next-line camelcase
redevance_communale_des_mines_aurifere_kg: {
redevance_communale_des_mines_aurifere_kg?: {
[annee: string]: number | null
}
surface_totale?: {
[annee: string]: number | null
}
}
}
titres?: {
[titreId: string]: {
commune_principale_exploitation: {
[annee: string]: string | null
}
operateur: {
[annee: string]: string | null
}
categorie: {
[annee: string]: string | null
}
investissement: {
[annee: string]: string | null
}
articles: string[]
}
}
communes?: {
[communeId: string]: {
articles: string[]
}
}
}
Expand Down Expand Up @@ -78,22 +108,22 @@ const redevanceCommunaleMinesAurifiereGet = async (
{}
)

acc.societes[entreprise.id] = {
acc.articles[entreprise.id] = {
quantite_aurifere_kg: orNetKg,
redevance_communale_des_mines_aurifere_kg:
redevanceCommunaleDesMinesAurifereKg
}

return acc
},
{ societes: {} } as IOpenfiscaBody
{ articles: {} } as IOpenfiscaBody
)

const result = (await apiOpenfiscaFetch(societes))?.societes
const result = (await apiOpenfiscaFetch(societes))?.articles

if (result) {
return Object.keys(result).reduce((acc, societe) => {
acc[societe] = result[societe].redevance_communale_des_mines_aurifere_kg
acc[societe] = result[societe].redevance_communale_des_mines_aurifere_kg!

return acc
}, {} as { [entrepriseId: string]: { [annee: string]: number | null } })
Expand Down

0 comments on commit 27160c7

Please sign in to comment.