2023-03-26 21:25:55 +02:00
|
|
|
/*
|
|
|
|
Parcoursup API (PAPI)
|
|
|
|
Comprend un set de wrapper afin d'accéder plus aisément aux informations de l'API parcoursup
|
|
|
|
*/
|
|
|
|
|
|
|
|
class PAPI {
|
|
|
|
|
|
|
|
static dataset = "fr-esr-parcoursup"
|
|
|
|
static timezone = "Europe%2FBerlin"
|
|
|
|
static searchURL = `https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=${PAPI.dataset}&timezone=${PAPI.timezone}`
|
|
|
|
|
|
|
|
static async fetchFilieres() {
|
|
|
|
|
2023-03-30 16:31:32 +02:00
|
|
|
if (localStorage.getItem("filis")) return JSON.parse(localStorage.getItem("filis"))
|
2023-03-31 11:36:19 +02:00
|
|
|
|
2023-03-30 16:31:32 +02:00
|
|
|
let request = await fetch(`${PAPI.searchURL}&rows=0&sort=tri&facet=fili`)
|
|
|
|
let result = await request.json()
|
|
|
|
let response = result["facet_groups"][0]["facets"]
|
|
|
|
|
|
|
|
localStorage.setItem("filis", JSON.stringify(response))
|
|
|
|
|
|
|
|
return response
|
2023-03-26 21:25:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static async fetchFiliere(filiere) {
|
|
|
|
|
2023-03-30 16:31:32 +02:00
|
|
|
if (localStorage.getItem("fili." + filiere)) return JSON.parse(localStorage.getItem("fili." + filiere))
|
|
|
|
|
2023-03-31 11:36:19 +02:00
|
|
|
let url = `${PAPI.searchURL}&rows=0&sort=tri&facet=form_lib_voe_acc&refine.fili=${filiere}`
|
|
|
|
url = url.replace("+", "%2B")
|
|
|
|
|
|
|
|
let request = await fetch(url)
|
2023-03-30 16:31:32 +02:00
|
|
|
let result = await request.json()
|
|
|
|
let response = result["facet_groups"][0]["facets"]
|
|
|
|
|
|
|
|
localStorage.setItem("fili." + filiere, JSON.stringify(response))
|
|
|
|
|
|
|
|
return response
|
2023-03-26 21:25:55 +02:00
|
|
|
}
|
2023-03-28 00:48:55 +02:00
|
|
|
|
2023-03-31 00:49:11 +02:00
|
|
|
static async fetchSpecialites(filiere, specialite) {
|
2023-03-30 16:31:32 +02:00
|
|
|
|
2023-03-31 00:49:11 +02:00
|
|
|
if (localStorage.getItem(`spe.${filiere}.${specialite}`)) return JSON.parse(localStorage.getItem(`spe.${filiere}.${specialite}`))
|
2023-03-30 16:31:32 +02:00
|
|
|
|
2023-03-31 11:36:19 +02:00
|
|
|
let url = `${PAPI.searchURL}&rows=0&sort=tri&facet=fil_lib_voe_acc&refine.form_lib_voe_acc=${specialite}&refine.fili=${filiere}`
|
|
|
|
url = url.replace("+", "%2B")
|
|
|
|
|
|
|
|
let request = await fetch(url)
|
2023-03-28 00:48:55 +02:00
|
|
|
let result = await request.json()
|
2023-03-30 16:31:32 +02:00
|
|
|
let response = result["facet_groups"][0]["facets"]
|
|
|
|
|
2023-03-31 00:49:11 +02:00
|
|
|
localStorage.setItem(`spe.${filiere}.${specialite}`, JSON.stringify(response))
|
2023-03-28 00:48:55 +02:00
|
|
|
|
2023-03-30 16:31:32 +02:00
|
|
|
return response
|
2023-03-28 00:48:55 +02:00
|
|
|
}
|
2023-03-28 16:51:44 +02:00
|
|
|
|
|
|
|
static async fetchEtablissement(filiere, sousfiliere, soussousfiliere) {
|
2023-03-30 16:31:32 +02:00
|
|
|
|
|
|
|
if (localStorage.getItem(`eta.${filiere}.${sousfiliere}.${soussousfiliere}`)) return JSON.parse(localStorage.getItem(`eta.${filiere}.${sousfiliere}.${soussousfiliere}`))
|
|
|
|
|
2023-03-31 11:36:19 +02:00
|
|
|
let url = `${PAPI.searchURL}&rows=10000&refine.fil_lib_voe_acc=${soussousfiliere}&refine.form_lib_voe_acc=${sousfiliere}&refine.fili=${filiere}`
|
|
|
|
url = url.replace("+", "%2B")
|
|
|
|
|
|
|
|
let request = await fetch(url)
|
2023-03-28 16:51:44 +02:00
|
|
|
let result = await request.json()
|
2023-03-30 16:31:32 +02:00
|
|
|
let response = result["records"]
|
|
|
|
|
|
|
|
localStorage.setItem(`eta.${filiere}.${sousfiliere}.${soussousfiliere}`, JSON.stringify(response))
|
2023-03-28 16:54:41 +02:00
|
|
|
|
2023-03-30 16:31:32 +02:00
|
|
|
return response
|
2023-03-28 16:51:44 +02:00
|
|
|
}
|
2023-03-26 21:25:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PAPI
|