Skip to content

Commit

Permalink
fix: training links (#1396)
Browse files Browse the repository at this point in the history
* fix: france entière si pas de rome

* fix: homepage si pas de rome

* fix: formation query

* fix: query

* feat: add extra ban search

* fix: migration
  • Loading branch information
kevbarns authored Jul 31, 2024
1 parent 65ac4b3 commit e43920c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ import { logger } from "@/common/logger"
export const up = async (db: Db) => {
logger.info("202407030000000-migrate-rename-bonnesboites started")

await db.collection("bonnesboites").rename("recruteurslba")
await db.collection("unsubscribedbonnesboites").rename("unsubscribedrecruteurslba")
await db.collection("bonnesboiteslegacies").rename("recruteurslbalegacies")
const renameCollectionIfNecessary = async (db, oldName, newName) => {
const collections = await db.listCollections({ name: newName }).toArray()
if (collections.length === 0) {
await db.collection(oldName).rename(newName)
console.log(`Renamed collection ${oldName} to ${newName}`)
} else {
console.log(`Collection ${newName} already exists, skipping rename of ${oldName}`)
}
}

await renameCollectionIfNecessary(db, "bonnesboites", "recruteurslba")
await renameCollectionIfNecessary(db, "unsubscribedbonnesboites", "unsubscribedrecruteurslba")
await renameCollectionIfNecessary(db, "bonnesboiteslegacies", "recruteurslbalegacies")

logger.info("202407030000000-migrate-rename-bonnesboites ended")
}
36 changes: 29 additions & 7 deletions server/src/services/trainingLinks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ const getFormations = (

const getTrainingsFromParameters = async (wish: IWish): Promise<IFormationCatalogue[]> => {
let formations
let query: any = { $or: [] }

if (wish.cfd) {
query.$or.push({ cfd: wish.cfd })
}
if (wish.rncp) {
query.$or.push({ rncp_code: wish.rncp })
}
if (wish.mef) {
query.$or.push({ "bcn_mefs_10.mef10": wish.mef })
}

if (!query.$or.length) {
query = undefined
}
// search by cle ME
if (wish.cle_ministere_educatif) {
formations = await getFormations({ cle_ministere_educatif: wish.cle_ministere_educatif })
Expand All @@ -71,17 +86,14 @@ const getTrainingsFromParameters = async (wish: IWish): Promise<IFormationCatalo
if (!formations || !formations.length) {
// search by uai_formateur
if (wish.uai_formateur) {
formations = await getFormations({ $or: [{ cfd: wish.cfd }, { rncp_code: wish.rncp }, { "bcn_mefs_10.mef10": wish.mef }], etablissement_formateur_uai: wish.uai_formateur })
formations = await getFormations({ ...query, etablissement_formateur_uai: wish.uai_formateur })
}
}

if (!formations || !formations.length) {
// search by uai_formateur_responsable
if (wish.uai_formateur_responsable) {
formations = await getFormations({
$or: [{ cfd: wish.cfd }, { rncp_code: wish.rncp }, { "bcn_mefs_10.mef10": wish.mef }],
etablissement_gestionnaire_uai: wish.uai_formateur_responsable,
})
formations = await getFormations({ ...query, etablissement_gestionnaire_uai: wish.uai_formateur_responsable })
}
}

Expand Down Expand Up @@ -162,7 +174,13 @@ const getLBALink = async (wish: IWish): Promise<string> => {
const postCode = wish.code_insee || wish.code_postal
let wLat, wLon
if (postCode) {
const responseApiAdresse = await apiGeoAdresse.search(postCode)
let responseApiAdresse = await apiGeoAdresse.search(postCode)

if (!responseApiAdresse || !responseApiAdresse.features.length) {
const generalPostCode = postCode.replace(/\d{3}$/, "000")
responseApiAdresse = await apiGeoAdresse.search(generalPostCode)
}

if (responseApiAdresse && responseApiAdresse.features.length) {
;[wLon, wLat] = responseApiAdresse.features[0].geometry.coordinates
}
Expand Down Expand Up @@ -198,7 +216,11 @@ const getLBALink = async (wish: IWish): Promise<string> => {
return buildEmploiUrl({ params: { ...(romes.length ? { romes } : {}), lat, lon, radius: "60", ...utmData } })
} else {
// No formations found, use user coordinates if available
return buildEmploiUrl({ params: { ...(romes.length ? { romes } : {}), lat: wLat ?? undefined, lon: wLon ?? undefined, radius: "60", ...utmData } })
if (romes.length) {
return buildEmploiUrl({ params: { romes, lat: wLat ?? undefined, lon: wLon ?? undefined, radius: "60", ...utmData } })
} else {
return buildEmploiUrl({ baseUrl: config.publicUrl, params: { ...utmData } })
}
}
}

Expand Down

0 comments on commit e43920c

Please sign in to comment.