From a76215ceaa0cce0561ede9815c33d9f12a724f97 Mon Sep 17 00:00:00 2001 From: Nicolas Humblot Date: Sat, 3 Sep 2022 14:11:54 +0200 Subject: [PATCH] #282 Update config --- src/state/State.ts | 4 ++-- src/utils/LocalConfig.ts | 18 +++++++++++++++--- src/utils/RemoteConfig.ts | 21 ++++++++++++++++++--- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/state/State.ts b/src/state/State.ts index 0a14cb2d..02ba7304 100644 --- a/src/state/State.ts +++ b/src/state/State.ts @@ -52,7 +52,7 @@ export namespace SearchRequest { } export type CodeTriCentre = 'date' | 'distance'; -export type DoseType = 'covid'; +export type DoseType = 'covid' | 'monkeypox'; export type TypePlateforme = "Doctolib"|"Maiia"|"Ordoclic"|"Keldoc"|"Pandalab"|"Mapharma"|"AvecMonDoc"|"Clikodoc"|"mesoigner"|"Bimedoc"|"Valwin"; export type Plateforme = { @@ -457,7 +457,7 @@ export class State { const urlGenerator = await RemoteConfig.INSTANCE.urlGenerator(); const [principalLieuxDepartement, ...lieuxDepartementsAditionnels] = await Promise.all( codesDepartements.map(codeDept => Promise.all([ - fetch(urlGenerator.infosDepartement(codeDept), { cache: 'no-cache' }) + fetch(urlGenerator.infosDepartement(codeDept, doseType), { cache: 'no-cache' }) .then(resp => resp.json()) .then((statsDept: LieuxParDepartement_JSON) => ({...statsDept, codeDepartement: codeDept} as LieuxParDepartement_JSON & {codeDepartement: string})), fetch(urlGenerator.creneauxQuotidiensDepartement(codeDept, doseType), { cache: 'no-cache' }) diff --git a/src/utils/LocalConfig.ts b/src/utils/LocalConfig.ts index 031936a0..30512c78 100644 --- a/src/utils/LocalConfig.ts +++ b/src/utils/LocalConfig.ts @@ -4,7 +4,7 @@ export type DataUrlGenerator = { listDepartements: () => string, statsByDate: () => string, stats: () => string, - infosDepartement: (codeDepartement: string) => string, + infosDepartement: (codeDepartement: string, doseType: DoseType) => string, creneauxQuotidiensDepartement: (codeDepartement: string, doseType: DoseType) => string, }; @@ -13,7 +13,13 @@ export const GITLAB_DATA_URLS: DataUrlGenerator = { statsByDate: () => `https://vitemadose.gitlab.io/vitemadose/stats_by_date.json`, stats: () => `https://vitemadose.gitlab.io/vitemadose/stats.json`, infosDepartement: (codeDepartement) => `https://vitemadose.gitlab.io/vitemadose/${codeDepartement}.json`, - creneauxQuotidiensDepartement: (codeDepartement) => `https://vitemadose.gitlab.io/vitemadose/${codeDepartement}/creneaux-quotidiens.json` + creneauxQuotidiensDepartement: (codeDepartement, doseType) => { + if (doseType == 'covid') { + return `https://vitemadose.gitlab.io/vitemadose/${codeDepartement}/creneaux-quotidiens.json`; + } + + return `https://vitemadose.gitlab.io/vitemadose/monkeypox/${codeDepartement}/creneaux-quotidiens.json`; + } } export const GITHUB_DATA_URLS: DataUrlGenerator = { @@ -21,5 +27,11 @@ export const GITHUB_DATA_URLS: DataUrlGenerator = { statsByDate: () => `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/stats_by_date.json`, stats: () => `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/stats.json`, infosDepartement: (codeDepartement) => `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/${codeDepartement}.json`, - creneauxQuotidiensDepartement: (codeDepartement) => `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/${codeDepartement}/creneaux-quotidiens.json` + creneauxQuotidiensDepartement: (codeDepartement,doseType) => { + if (doseType == 'covid') { + return `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/${codeDepartement}/creneaux-quotidiens.json` + } + + return `https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output/monkeypox/${codeDepartement}/creneaux-quotidiens.json` + } } diff --git a/src/utils/RemoteConfig.ts b/src/utils/RemoteConfig.ts index ac0fcffd..370dc88a 100644 --- a/src/utils/RemoteConfig.ts +++ b/src/utils/RemoteConfig.ts @@ -8,6 +8,7 @@ type RemoteConfigEntries = { "data_disclaimer_severity": string, "path_contributors": string, "path_data_department": string, + "path_monkeypox_data_department": string, "path_list_departments": string, "path_stats": string, "url_base": string, @@ -22,6 +23,7 @@ const REMOTE_CONFIG_ENTRIES_FALLBACK: RemoteConfigEntries = { "data_disclaimer_severity": "warning", "path_contributors": "/vitemadose/contributors_all.json", "path_data_department": "/vitemadose/{code}.json", + "path_monkeypox_data_department": "/vitemadose/monkeypox/{code}.json", "path_list_departments": "/vitemadose/departements.json", "path_stats": "/vitemadose/stats.json", "url_base": "https://vitemadose.gitlab.io", @@ -68,7 +70,13 @@ export class RemoteConfig { statsByDate: () => `/offline/stats_by_date.json`, stats: () => `/offline/stats.json`, infosDepartement: (codeDepartement) => `/offline/${codeDepartement}.json`, - creneauxQuotidiensDepartement: (codeDepartement) => `/offline/${codeDepartement}/creneaux-quotidiens.json` + creneauxQuotidiensDepartement: (codeDepartement, doseType) => { + if (doseType == 'covid') { + return `/offline/${codeDepartement}/creneaux-quotidiens.json`; + } + + return `/offline/monkeypox/${codeDepartement}/creneaux-quotidiens.json` + } }; this.configurationSyncedPromise = Promise.resolve(); @@ -105,12 +113,19 @@ export class RemoteConfig { const statsByDatePath = `/vitemadose/stats_by_date.json`; const departementsListPath = this.configuration.path_list_departments || `/vitemadose/departements.json`; const infosDepartementPath = this.configuration.path_data_department || `/vitemadose/{code}.json`; + const monkeypoxDepartmentDataPath = this.configuration.path_monkeypox_data_department || REMOTE_CONFIG_ENTRIES_FALLBACK.path_monkeypox_data_department; this._urlGenerator = { listDepartements: () => `${urlBase}${departementsListPath}`, statsByDate: () => `${urlBase}${statsByDatePath}`, stats: () => `${urlBase}${statsPath}`, - infosDepartement: (codeDepartement) => `${urlBase}${infosDepartementPath.replace('{code}', codeDepartement)}`, - creneauxQuotidiensDepartement: (codeDepartement) => `${urlBase}/vitemadose/${codeDepartement}/creneaux-quotidiens.json` + infosDepartement: (codeDepartement, doseType) => doseType === 'monkeypox' ? `${urlBase}${monkeypoxDepartmentDataPath.replace('{code}', codeDepartement)}` : `${urlBase}${infosDepartementPath.replace('{code}', codeDepartement)}`, + creneauxQuotidiensDepartement: (codeDepartement, doseType) => { + if (doseType == 'covid') { + return `${urlBase}/vitemadose/${codeDepartement}/creneaux-quotidiens.json`; + } + + return `${urlBase}/vitemadose/monkeypox/${codeDepartement}/creneaux-quotidiens.json`; + } }; } else if(USE_GITLAB_AS_FALLBACK) { this._urlGenerator = GITLAB_DATA_URLS;