Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: LBA-1326 Modification du lien catalogue des CFAs delegations #1508

Merged
merged 10 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export default (server: Server) => {
schema: zRoutes.get["/etablissement/cfas-proches"],
},
async (req, res) => {
const { latitude, longitude, rome } = req.query
const etablissements = await getNearEtablissementsFromRomes({ rome: [rome], origin: { latitude: latitude, longitude: longitude } })
const { latitude, longitude, rome, limit } = req.query
const etablissements = await getNearEtablissementsFromRomes({ rome: [rome], origin: { latitude: latitude, longitude: longitude }, limit })
res.send(etablissements)
}
)
Expand Down
5 changes: 2 additions & 3 deletions server/src/http/controllers/jobs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,14 @@ export default (server: Server) => {
latitude: parseFloat(latitude),
longitude: parseFloat(longitude),
},
limit: 10,
})

if (!etablissements.length) {
throw notFound("No delegations found")
}

const top10 = etablissements.slice(0, 10)

return res.status(200).send(top10)
return res.status(200).send(etablissements)
}
)

Expand Down
15 changes: 8 additions & 7 deletions server/src/services/catalogue.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { got } from "got"
import { sortBy } from "lodash-es"
import { ObjectId } from "mongodb"
import { compose } from "oleoduc"
import { IEtablissementCatalogue, IEtablissementCatalogueProche, IEtablissementCatalogueProcheWithDistance } from "shared/interface/etablissement.types"

import { getDbCollection } from "@/common/utils/mongodbUtils"
import { sentryCaptureException } from "@/common/utils/sentryUtils"
Expand Down Expand Up @@ -140,7 +141,7 @@ export const countFormations = async (): Promise<number | boolean> => {
* @param {Object} query
* @returns {Promise<Object[]>}
*/
export const getCatalogueEtablissements = (query: object = {}, select: object = {}): Promise<any> =>
export const getCatalogueEtablissements = (query: object = {}, select: object = {}): Promise<{ etablissements: IEtablissementCatalogue[] }> =>
got(`${config.catalogueUrl}/api/v1/entity/etablissements`, {
method: "POST",
json: {
Expand All @@ -156,7 +157,7 @@ export const getCatalogueEtablissements = (query: object = {}, select: object =
* @param {{latitude: string, longitude: string}} origin
* @returns {Promise<Object[]>}
*/
export const getNearEtablissementsFromRomes = async ({ rome, origin }: { rome: string[]; origin: { latitude: number; longitude: number } }) => {
export const getNearEtablissementsFromRomes = async ({ rome, origin, limit }: { rome: string[]; origin: { latitude: number; longitude: number }; limit: number }) => {
const formations = await getCatalogueFormations(
{
rome_codes: { $in: rome },
Expand All @@ -173,12 +174,12 @@ export const getNearEtablissementsFromRomes = async ({ rome, origin }: { rome: s
const etablissementsToRetrieve = new Set()
formations.forEach((formation) => etablissementsToRetrieve.add(formation.etablissement_formateur_id))

const { etablissements } = await getCatalogueEtablissements(
const { etablissements }: { etablissements: IEtablissementCatalogueProche[] } = await getCatalogueEtablissements(
{
_id: { $in: Array.from(etablissementsToRetrieve) },
certifie_qualite: true,
},
{ _id: 1, numero_voie: 1, type_voie: 1, nom_voie: 1, code_postal: 1, nom_departement: 1, entreprise_raison_sociale: 1, geo_coordonnees: 1 }
{ _id: 1, siret: 1, numero_voie: 1, type_voie: 1, nom_voie: 1, code_postal: 1, nom_departement: 1, entreprise_raison_sociale: 1, geo_coordonnees: 1 }
)

let etablissementsRefined = etablissements.flatMap((etablissement) => {
Expand All @@ -193,17 +194,17 @@ export const getNearEtablissementsFromRomes = async ({ rome, origin }: { rome: s
return [
{
...etablissement,
distance_en_km: getDistanceInKm({ origin, destination: { latitude, longitude } }),
distance_en_km: getDistanceInKm({ origin, destination: { latitude: parseFloat(latitude), longitude: parseFloat(longitude) } }),
},
]
] as IEtablissementCatalogueProcheWithDistance[]
})
etablissementsRefined = sortBy(etablissementsRefined, "distance_en_km")
const unsubscribedEtablissements = await getDbCollection("unsubscribedofs")
.find({ catalogue_id: { $in: etablissementsRefined.map((etablissement) => etablissement._id) } })
.toArray()
const unsubscribedIds = unsubscribedEtablissements.map((unsubscribeOF) => unsubscribeOF.catalogue_id)
etablissementsRefined = etablissementsRefined.filter((etablissement) => !unsubscribedIds.includes(etablissement._id))
return etablissementsRefined
return etablissementsRefined.slice(0, limit)
}

/**
Expand Down
107 changes: 0 additions & 107 deletions server/src/services/etablissement.service.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,113 +193,6 @@ interface IUaiPotentiel {
sources: string[]
date_collecte: Date
}

interface IEtablissementCatalogueRaw {
_id: string
siege_social: boolean
etablissement_siege_siret: string
siret: string
siren: string
nda: string
naf_code: string
naf_libelle: string
date_creation: Date
diffusable_commercialement: boolean
enseigne: null
onisep_nom: null
onisep_url: null
onisep_code_postal: null
adresse: string
numero_voie: string
type_voie: string
nom_voie: string
complement_adresse: string
code_postal: string
num_departement: string
nom_departement: string
localite: string
code_insee_localite: string
cedex: null
date_fermeture: Date
ferme: boolean
region_implantation_code: string
region_implantation_nom: string
commune_implantation_code: string
commune_implantation_nom: string
num_academie: number
nom_academie: string
uai: string
info_datagouv_ofs: null
info_datagouv_ofs_info: null
info_qualiopi_info: string
api_entreprise_reference: boolean
entreprise_siren: string
entreprise_procedure_collective: boolean
entreprise_enseigne: null
entreprise_numero_tva_intracommunautaire: null
entreprise_raison_sociale: string
entreprise_nom_commercial: null
entreprise_date_creation: Date
entreprise_date_radiation: Date
entreprise_naf_code: string
entreprise_naf_libelle: string
entreprise_date_fermeture: Date
entreprise_ferme: boolean
entreprise_siret_siege_social: string
entreprise_nom: null
entreprise_prenom: null
formations_attachees: null
formations_ids: any[]
formations_uais: null
published: boolean
updates_history: any[]
tags: string[]
rco_uai: string
rco_adresse: null
rco_code_postal: string
rco_code_insee_localite: string
idcc: null
opco_nom: null
opco_siren: null
created_at: Date
last_update_at: Date
__v: number
entreprise_tranche_effectif_salarie: null
etablissement_siege_id: null
geo_coordonnees: string
rco_geo_coordonnees: null
uai_valide: boolean
certifie_qualite: boolean
date_mise_a_jour: null
ds_id_dossier: null
ds_questions_ask_for_certificaton_date: null
ds_questions_declaration_code: null
ds_questions_has_2020_training: null
ds_questions_has_agrement_cfa: null
ds_questions_has_ask_for_certificaton: null
ds_questions_has_certificaton_2015: null
ds_questions_nom: null
ds_questions_siren: null
ds_questions_uai: null
entreprise_capital_social: null
entreprise_categorie: null
entreprise_code_effectif_entreprise: null
entreprise_forme_juridique: string
entreprise_forme_juridique_code: string
formations_n3: null
formations_n4: null
formations_n5: null
formations_n6: null
formations_n7: null
pays_implantation_code: string
pays_implantation_nom: string
tranche_effectif_salarie: null
uais_potentiels: null
update_error: null
}

export type IEtablissementCatalogue = Jsonify<IEtablissementCatalogueRaw>

export interface IAPIAdresse {
type: string
version: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8005,7 +8005,7 @@ Limite : 5 appel(s) / 1 seconde(s)
"additionalProperties": false,
"properties": {
"_id": {
"description": "Identifiant unique",
"type": "string",
},
"code_postal": {
"type": "string",
Expand Down Expand Up @@ -8034,6 +8034,9 @@ Limite : 5 appel(s) / 1 seconde(s)
"null",
],
},
"siret": {
"type": "string",
},
"type_voie": {
"type": [
"string",
Expand All @@ -8042,6 +8045,11 @@ Limite : 5 appel(s) / 1 seconde(s)
},
},
"required": [
"_id",
"siret",
"numero_voie",
"type_voie",
"nom_voie",
"code_postal",
"nom_departement",
"entreprise_raison_sociale",
Expand Down
33 changes: 26 additions & 7 deletions shared/interface/etablissement.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { z } from "zod"

import { zObjectId } from "../models/common"

export const zEtablissementCatalogue = z
export const ZEtablissementCatalogue = z
.object({
_id: zObjectId,
_id: z.string(),
siege_social: z.boolean(),
etablissement_siege_siret: z.string(),
siret: z.string(),
Expand All @@ -19,9 +17,9 @@ export const zEtablissementCatalogue = z
onisep_url: z.null(),
onisep_code_postal: z.null(),
adresse: z.string(),
numero_voie: z.string(),
type_voie: z.string(),
nom_voie: z.string(),
numero_voie: z.string().nullable(),
type_voie: z.string().nullable(),
nom_voie: z.string().nullable(),
complement_adresse: z.string(),
code_postal: z.string(),
num_departement: z.string(),
Expand Down Expand Up @@ -107,3 +105,24 @@ export const zEtablissementCatalogue = z
update_error: z.null(),
})
.strict()

export type IEtablissementCatalogue = z.output<typeof ZEtablissementCatalogue>

export const ZEtablissementCatalogueProche = ZEtablissementCatalogue.pick({
_id: true,
siret: true,
numero_voie: true,
type_voie: true,
nom_voie: true,
code_postal: true,
nom_departement: true,
entreprise_raison_sociale: true,
geo_coordonnees: true,
})

export type IEtablissementCatalogueProche = z.output<typeof ZEtablissementCatalogueProche>

export const ZEtablissementCatalogueProcheWithDistance = ZEtablissementCatalogueProche.extend({
distance_en_km: z.number(),
})
export type IEtablissementCatalogueProcheWithDistance = z.output<typeof ZEtablissementCatalogueProcheWithDistance>
19 changes: 3 additions & 16 deletions shared/routes/recruiters.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Jsonify } from "type-fest"

import { extensions } from "../helpers/zodHelpers/zodPrimitives"
import { z } from "../helpers/zodWithOpenApi"
import { ZEtablissementCatalogueProcheWithDistance } from "../interface/etablissement.types"
import { ZPointGeometry, ZRecruiter } from "../models"
import { zCFA } from "../models/cfa.model"
import { zObjectId } from "../models/common"
Expand Down Expand Up @@ -41,25 +42,11 @@ export const zRecruiterRoutes = {
latitude: z.coerce.number(),
longitude: z.coerce.number(),
rome: z.string(),
limit: z.coerce.number(),
})
.strict(),
response: {
// TODO ANY TO BE FIXED
"200": z.array(z.any()),
// "2xx": zEtablissementCatalogue
// .pick({
// _id: true,
// numero_voie: true,
// type_voie: true,
// nom_voie: true,
// nom_departement: true,
// entreprise_raison_sociale: true,
// geo_coordonnees: true,
// })
// .extend({
// distance_en_km: z.string(),
// })
// .strict(),
"200": z.array(ZEtablissementCatalogueProcheWithDistance),
},
securityScheme: null,
},
Expand Down
17 changes: 2 additions & 15 deletions shared/routes/v1Jobs.routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { extensions } from "../helpers/zodHelpers/zodPrimitives"
import { z } from "../helpers/zodWithOpenApi"
import { ZEtablissementCatalogueProcheWithDistance } from "../interface/etablissement.types"
import { ZJob, ZJobFields, ZJobStartDateCreate } from "../models"
import { zObjectId } from "../models/common"
import { ZApiError, ZLbacError, ZLbarError } from "../models/lbacError.model"
Expand Down Expand Up @@ -141,21 +142,7 @@ export const zV1JobsRoutes = {
})
.strict(),
response: {
"200": z.array(
z
.object({
_id: zObjectId,
numero_voie: z.string().nullish(),
type_voie: z.string().nullish(),
nom_voie: z.string().nullish(),
code_postal: z.string(),
nom_departement: z.string(),
entreprise_raison_sociale: z.string(),
geo_coordonnees: z.string(),
distance_en_km: z.number(),
})
.strict()
),
"200": z.array(ZEtablissementCatalogueProcheWithDistance),
"4xx": z.union([ZLbarError, ZResError]),
},
securityScheme: {
Expand Down
4 changes: 2 additions & 2 deletions ui/components/espace_pro/CreationOffre.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AUTHTYPE } from "../../common/contants"
import { ArrowDropRightLine } from "../../theme/components/icons"
import { createOffre, getOffre } from "../../utils/api"

import { AjouterVoeux, LoadingEmptySpace } from "."
import { FormulaireCreationOffre, LoadingEmptySpace } from "."

export default function CreationOffre() {
const toast = useToast()
Expand Down Expand Up @@ -81,7 +81,7 @@ export default function CreationOffre() {
)}
</Breadcrumb>
</Box>
<AjouterVoeux fromDashboard handleSave={handleSave} offre={offre} />
<FormulaireCreationOffre fromDashboard handleSave={handleSave} offre={offre} />
</Container>
)
}
Loading
Loading