Skip to content

Commit

Permalink
feat: lbac 2120 get rome from rncp api apprentissage (#1199)
Browse files Browse the repository at this point in the history
* feat: add api config

* feat: get rome from api apprentissage

* feat: remove while loop

* fix: find instead of filter

* fix: types

* fix: single certification retreived

* feat: update control logic

* feat: use findLast

* feat: update vault

* fix: talisman

* fix: talisman

* fix: test
  • Loading branch information
kevbarns authored Apr 29, 2024
1 parent ebb6929 commit d6f0af9
Show file tree
Hide file tree
Showing 7 changed files with 840 additions and 721 deletions.
1 change: 1 addition & 0 deletions .infra/.env_server
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ LBA_S3_BUCKET={{ vault.LBA_S3_BUCKET }}
LBA_ENTREPRISE_API_KEY={{ vault.LBA_ENTREPRISE_API_KEY }}
LBA_FRANCE_COMPETENCE_API_KEY={{ vault.LBA_FRANCE_COMPETENCE_API_KEY }}
LBA_FRANCE_COMPETENCE_TOKEN={{ vault.LBA_FRANCE_COMPETENCE_TOKEN }}
LBA_API_APPRENTISSAGE_KEY={{ vault.LBA_API_APPRENTISSAGE_KEY }}
1,259 changes: 637 additions & 622 deletions .infra/vault/vault.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fileignoreconfig:
- filename: docker-compose.yml
checksum: 8cdd1da6c1155f26b417a27e26311d4f00b7d8bd6c21f1f86c1c7cb3f0599e6a
- filename: server/.env.test
checksum: a5416822ec3c607557a69a8f20014de9fc40d8a871884bb79cc3906078c4ef15
checksum: 69332e43a85e702b93d00e62edf109c3b22189660de33e50e766ba15ea58f8b8
- filename: server/src/common/model/schema/_shared/mongoose-paginate.ts
checksum: b6762a7cb5df9bbee1f0ce893827f0991ad01514f7122a848b3b5d49b620f238
- filename: server/src/config.ts
Expand Down
1 change: 1 addition & 0 deletions server/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ LBA_ENTREPRISE_API_KEY=LBA_ENTREPRISE_API_KEY
PUBLIC_VERSION=0.0.0-local
LBA_FRANCE_COMPETENCE_API_KEY=LBA_FRANCE_COMPETENCE_API_KEY
LBA_FRANCE_COMPETENCE_TOKEN=LBA_FRANCE_COMPETENCE_TOKEN
LBA_API_APPRENTISSAGE_KEY=LBA_API_APPRENTISSAGE_KEY
4 changes: 4 additions & 0 deletions server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ const config = {
tco: {
baseUrl: "https://tables-correspondances.apprentissage.beta.gouv.fr",
},
apiApprentissage: {
baseUrl: "https://api.apprentissage.beta.gouv.fr/api",
apiKey: env.get("LBA_API_APPRENTISSAGE_KEY").required().asString(),
},
parcoursupPeriods: {
start: {
startMonth: 0, // January = 0
Expand Down
37 changes: 30 additions & 7 deletions server/src/services/queryValidator.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "axios"
import Boom from "boom"
import { allLbaItemTypeOLD } from "shared/constants/lbaitem"

import { isOriginLocal } from "../common/utils/isOriginLocal"
Expand All @@ -7,15 +8,37 @@ import { sentryCaptureException } from "../common/utils/sentryUtils"
import config from "../config"

import { TFormationSearchQuery, TJobSearchQuery } from "./jobOpportunity.service.types"
import { IRncpTCO } from "./queryValidator.service.types"
import { CertificationAPIApprentissage } from "./queryValidator.service.types"

const getRomesFromRncp = async (rncp: string): Promise<string | null | undefined> => {
const getFirstCertificationFromAPIApprentissage = async (rncp: string): Promise<CertificationAPIApprentissage | null> => {
try {
const response = await axios.post<IRncpTCO>(`${config.tco.baseUrl}/api/v1/rncp`, { rncp })
const romes = response.data.result.romes.map(({ rome }) => rome).join(",")
return romes ?? null
} catch (error) {
sentryCaptureException(error)
const { data } = await axios.get<CertificationAPIApprentissage[]>(`${config.apiApprentissage.baseUrl}/certification/v1?identifiant.rncp=${rncp}`, {
headers: { Authorization: `Bearer ${config.apiApprentissage.apiKey}` },
})

if (!data.length) return null

return data[0]
} catch (error: any) {
sentryCaptureException(error, { responseData: error.response?.data })
return null
}
}

const getRomesFromRncp = async (rncp: string): Promise<string | null> => {
let certification = await getFirstCertificationFromAPIApprentissage(rncp)
if (!certification) return null

if (certification.periode_validite.rncp.actif) {
return certification.domaines.rome.rncp.map((x) => x.code).join(",")
} else {
const latestRNCP = certification.continuite.rncp.findLast((rncp) => rncp.actif === true)
if (!latestRNCP) {
throw Boom.internal(`le code RNCP ${rncp} n'a aucune continuité`)
}
certification = await getFirstCertificationFromAPIApprentissage(latestRNCP.code)
if (!certification) return null
return certification.domaines.rome.rncp.map((x) => x.code).join(",")
}
}

Expand Down
257 changes: 166 additions & 91 deletions server/src/services/queryValidator.service.types.ts
Original file line number Diff line number Diff line change
@@ -1,112 +1,187 @@
export interface IRncpTCO {
result: Result
messages: Messages
}

interface Result {
_id: string
cfds: string[]
code_rncp: string
intitule_diplome: string
date_fin_validite_enregistrement: string
active_inactive: string
etat_fiche_rncp: string
niveau_europe: string
code_type_certif: any
type_certif: any
ancienne_fiche: string[]
nouvelle_fiche: any
demande: number
certificateurs: Certificateur[]
nsf_code: string
nsf_libelle: string
romes: Rome[]
blocs_competences: BlocsCompetence[]
voix_acces: any
partenaires: Partenaire[]
type_enregistrement: string
si_jury_ca: string
eligible_apprentissage: boolean
created_at: string
last_update_at: string
__v: number
rncp_outdated: boolean
releated: Releated[]
}

interface Certificateur {
certificateur: string
siret_certificateur: string
export interface CertificationAPIApprentissage {
identifiant: Identifiant
intitule: Intitule
base_legale: BaseLegale
blocs_competences: BlocsCompetences
convention_collectives: ConventionCollectives
domaines: Domaines
periode_validite: PeriodeValidite
type: Type
continuite: Continuite
}

interface Rome {
rome: string
interface Identifiant {
cfd: string
rncp: string
rncp_anterieur_2019: boolean
}

interface Intitule {
cfd: IntituleCfd
niveau: Niveau
rncp: string
}

interface IntituleCfd {
long: string
court: string
}

interface Niveau {
cfd: NiveauCfd
rncp: Rncp
}

interface NiveauCfd {
europeen: string
formation_diplome: string
interministeriel: string
libelle: string
sigle: string
}

interface Rncp {
europeen: string
}

interface BlocsCompetence {
numero_bloc: string
interface BaseLegale {
cfd: BaseLegaleCfd
}

interface BaseLegaleCfd {
creation: string
abrogation: string
}

interface BlocsCompetences {
rncp: BlocCompetencesRncp[]
}

interface BlocCompetencesRncp {
code: string
intitule: string
liste_competences: string
modalites_evaluation: string
}

interface Partenaire {
Nom_Partenaire: string
Siret_Partenaire: string
Habilitation_Partenaire: string
interface ConventionCollectives {
rncp: ConventionCollectivesRncp[]
}

interface Releated {
cfd: Cfd
mefs: Mefs
interface ConventionCollectivesRncp {
numero: string
intitule: string
}

interface Cfd {
cfd: string
cfd_outdated: boolean
date_fermeture: number
date_ouverture: number
specialite: any
niveau: string
intitule_long: string
intitule_court: string
diplome: string
libelle_court: string
niveau_formation_diplome: string
interface Domaines {
formacodes: Formacodes
nsf: Nsf
rome: Rome
}

interface Mefs {
mefs10: any[]
mefs8: any[]
mefs_aproximation: any[]
mefs11: any[]
interface Formacodes {
rncp: FormacodesRncp[]
}

interface Messages {
code_rncp: string
releated: Releated2[]
interface FormacodesRncp {
code: string
intitule: string
}

interface Releated2 {
cfd: Cfd2
mefs: Mefs2
interface Nsf {
cfd: NsfCfd
rncp: NsfRncp[]
}

interface Cfd2 {
cfd: string
specialite: string
niveau: string
intitule_long: string
intitule_court: string
diplome: string
libelle_court: string
niveau_formation_diplome: string
}

interface Mefs2 {
mefs10: string
mefs8: string
mefs_aproximation: string
mefs11: string
interface NsfCfd {
code: string
intitule: string
}

interface NsfRncp {
code: string
intitule: string
}

interface Rome {
rncp: RomeRncp[]
}

interface RomeRncp {
code: string
intitule: string
}

interface PeriodeValidite {
debut: string
fin: string
cfd: PeriodeValiditeCfd
rncp: PeriodeValiditeRncp
}

interface PeriodeValiditeCfd {
ouverture: string
fermeture: string
premiere_session: number
derniere_session: number
}

interface PeriodeValiditeRncp {
actif: boolean
activation: string
debut_parcours: string
fin_enregistrement: string
}

interface Type {
nature: Nature
gestionnaire_diplome: string
enregistrement_rncp: string
voie_acces: VoieAcces
certificateurs_rncp: CertificateursRncp[]
}

interface Nature {
cfd: NatureCfd
}

interface NatureCfd {
code: string
libelle: string
}

interface VoieAcces {
rncp: VoieAccesRncp
}

interface VoieAccesRncp {
apprentissage: boolean
experience: boolean
candidature_individuelle: boolean
contrat_professionnalisation: boolean
formation_continue: boolean
formation_statut_eleve: boolean
}

interface CertificateursRncp {
siret: string
nom: string
}

interface Continuite {
cfd: ContinuiteCfd[]
rncp: ContinuiteRncp[]
}

interface ContinuiteCfd {
ouverture: string
fermeture: string
code: string
courant: boolean
}

interface ContinuiteRncp {
activation: string
fin_enregistrement: string
code: string
courant: boolean
actif: boolean
}

0 comments on commit d6f0af9

Please sign in to comment.