Skip to content

Commit

Permalink
Merge branch 'main' into lbac-2428-emails
Browse files Browse the repository at this point in the history
  • Loading branch information
remy-auricoste authored Sep 17, 2024
2 parents 8853719 + 3b613a9 commit 3d6e6f9
Show file tree
Hide file tree
Showing 33 changed files with 301 additions and 430 deletions.
4 changes: 2 additions & 2 deletions .infra/files/configs/mongodb/seed.gpg
Git LFS file not shown
5 changes: 3 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fileignoreconfig:
- filename: .infra/files/configs/mongodb/mongod.conf
checksum: 718bee5f44edc101636be8f11173ede5b728f2858abc3c26466ff9435f0d11de
- filename: .infra/files/configs/mongodb/seed.gpg
checksum: 646eab49f6ff33a2d4d2dc9892ae14ca7871404c81459fc4832b1fb12abbe1c9
checksum: 89f95ec4e20c1c7563fc94704501cc71f1c36c4d27092e43e0ebf2fd939dc6da
- filename: .infra/files/scripts/seed.sh
checksum: b1361c237cee243b74fc9e66fd59af80c538d6884b8f94c3659d25cdc2b873c2
- filename: .infra/local/mongod.conf
Expand Down Expand Up @@ -190,7 +190,7 @@ fileignoreconfig:
- filename: ui/components/espace_pro/AjouterVoeux.tsx
checksum: 8ba50b9d7127114cd71789bbf7c26dc19b4b915ab4ae2e2e033c1ca65accee94
- filename: ui/components/footer.tsx
checksum: d82b5a7d6905070fb32383864566fc16eae4797ca18f82782fb32c95a0d50369
checksum: e0dd3ec2ac813053ee5e672472b545719c95e49f0891cf2f8e1b5db484d00479
- filename: ui/pages/accessibilite.tsx
checksum: d6a7c57500f9de5e47e305f89435b21d717f505acac7b45656931f7ecdd0fcca
- filename: ui/pages/espace-pro/admin/eligible-trainings-for-appointment/search.tsx
Expand All @@ -205,6 +205,7 @@ fileignoreconfig:
checksum: 1ad48425b890a5ed3de19d079692e2ef7eac76483339a469a6cd9bc6d796ad26
- filename: ui/utils/api.utils.ts
checksum: 324cd501354cfff65447c2599c4cc8966aa8aac30dda7854623dd6f7f7b0d34e
threshold: medium
scopeconfig:
- scope: node
custom_patterns:
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/manual/create-many-applications.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { givenAMatchaOffer } from "../../pages/givenAMatchaOffer"
import { generateRandomString } from "../../utils/generateRandomString"

describe("create-many-applications", () => {
it("create-many-applications", () => {
it.skip("create-many-applications", () => {
cy.viewport(1271, 721)

givenAMatchaOffer((recruiter) => {
Expand Down
8 changes: 0 additions & 8 deletions server/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ import server from "./http/server"

async function startProcessor(signal: AbortSignal) {
logger.info(`Process jobs queue - start`)
if (config.env !== "local" && config.env !== "preview") {
await addJob({
name: "crons:init",
queued: true,
payload: {},
})
}

await startJobProcessor(signal)
logger.info(`Processor shut down`)
}
Expand Down
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
36 changes: 4 additions & 32 deletions server/src/security/accessTokenService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { PathParam, QueryString } from "shared/helpers/generateUri"
import { IUserRecruteur } from "shared/models"
import { IUserWithAccount } from "shared/models/userWithAccount.model"
import { IRouteSchema, WithSecurityScheme } from "shared/routes/common.routes"
import { assertUnreachable } from "shared/utils"
import { Jsonify } from "type-fest"
import { AnyZodObject, z } from "zod"

Expand All @@ -31,18 +30,7 @@ type AuthorizedValuesRecord<ZodObject> = ZodObject extends AnyZodObject
}
: undefined

// TODO à retirer à partir du 01/02/2024
type OldIScope<Schema extends SchemaWithSecurity> = {
schema: Schema
options:
| "all"
| {
params: AuthorizedValuesRecord<Schema["params"]>
querystring: AuthorizedValuesRecord<Schema["querystring"]>
}
}

type NewIScope<Schema extends SchemaWithSecurity> = {
type IScope<Schema extends SchemaWithSecurity> = {
method: Schema["method"]
path: Schema["path"]
options:
Expand All @@ -52,10 +40,7 @@ type NewIScope<Schema extends SchemaWithSecurity> = {
querystring: AuthorizedValuesRecord<Schema["querystring"]>
}
}

type IScope<Schema extends SchemaWithSecurity> = NewIScope<Schema> | OldIScope<Schema>

export const generateScope = <Schema extends SchemaWithSecurity>(scope: Omit<NewIScope<Schema>, "method" | "path"> & { schema: Schema }): NewIScope<Schema> => {
export const generateScope = <Schema extends SchemaWithSecurity>(scope: Omit<IScope<Schema>, "method" | "path"> & { schema: Schema }): IScope<Schema> => {
const { schema, options } = scope
return { options, path: schema.path, method: schema.method }
}
Expand Down Expand Up @@ -96,7 +81,7 @@ export const applicationToUserForToken = ({ company_siret, jobId }: IApplication
}
}

export function generateAccessToken(user: UserForAccessToken, scopes: ReadonlyArray<NewIScope<SchemaWithSecurity>>, options: { expiresIn?: string } = {}): string {
export function generateAccessToken(user: UserForAccessToken, scopes: ReadonlyArray<IScope<SchemaWithSecurity>>, options: { expiresIn?: string } = {}): string {
const identity: IAccessToken["identity"] = "_id" in user ? { type: "IUser2", _id: user._id.toString(), email: user.email.toLowerCase() } : user
const data: IAccessToken<SchemaWithSecurity> = {
identity,
Expand All @@ -113,19 +98,6 @@ export function generateAccessToken(user: UserForAccessToken, scopes: ReadonlyAr
return token
}

function getMethodAndPath<Schema extends SchemaWithSecurity>(scope: IScope<Schema>) {
if ("schema" in scope) {
const { schema } = scope
const { method, path } = schema
return { method, path }
} else if ("method" in scope && "path" in scope) {
const { method, path } = scope
return { method, path }
} else {
assertUnreachable(scope)
}
}

function isAllowAllValue(x: unknown): x is AllowAllType {
return !!x && typeof x === "object" && "allowAll" in x && x.allowAll === true
}
Expand All @@ -142,7 +114,7 @@ export function getAccessTokenScope<Schema extends SchemaWithSecurity>(
): IScope<Schema> | null {
return (
token?.scopes.find((scope) => {
const { method, path } = getMethodAndPath(scope)
const { method, path } = scope
if (path !== schema.path || method !== schema.method) {
return false
}
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
Loading

0 comments on commit 3d6e6f9

Please sign in to comment.