Skip to content

Commit

Permalink
Merge branch 'main' into feat/lba-2262-evolution-reponse-a-candidat
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlr authored Dec 19, 2024
2 parents cf58212 + c74c7dc commit 813428a
Show file tree
Hide file tree
Showing 71 changed files with 2,164 additions and 566 deletions.
4 changes: 2 additions & 2 deletions .infra/files/configs/mongodb/seed.gpg
Git LFS file not shown
8 changes: 7 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fileignoreconfig:
- filename: .infra/files/configs/mongodb/seed.gpg
checksum: 48548e14d0a795a0a2e594a28177c3bf6893dc2dcb395a83ee38e1ac167fb5d9
checksum: 6e1a4701b1bf47e426614115bd0f24902da998efd9a51dd3427ac189f399e248
- filename: .infra/vault/vault.yml
checksum: 40717e8b277d9c9812c89d62fd3e09d0d70cdd0bb76a460f09486a31b6dd9cc7
- filename: cypress/e2e/manual/create-many-applications.cy.ts
Expand Down Expand Up @@ -79,6 +79,8 @@ fileignoreconfig:
checksum: 0e6d208dc8de66d2a440ff40a1260a76e41bf69fb414ccbfc6d99396df3f3b91
- filename: server/src/services/__snapshots__/formulaire.service.test.ts.snap
checksum: 71d9956fd03fcec52d37b3799fc5bc806d42ec40200254b1740819b3d5a2b0d1
- filename: server/src/services/__snapshots__/partnerJob.service.test.ts.snap
checksum: 4f9393678b2ba8ea72cfd832d6a33ede3bc4024382b624464481a5f09636e152
- filename: server/src/services/application.service.test.ts
checksum: d11d73a73ed489475d6a2f7dd693787fc71a7dfd9150bb88cec4f88c92c19d02
- filename: server/src/services/application.service.ts
Expand All @@ -95,6 +97,8 @@ fileignoreconfig:
checksum: 6ed0939b188ffec96f7698b353e87c660e77c802c4d03b24620125291e06334c
- filename: server/src/services/jobs/jobOpportunity/jobOpportunity.service.test.ts
checksum: e192df6796f90fd76e38f3d7218e95d7ff2ef4615b5199e99052feb39ce374ec
- filename: server/src/services/partnerJob.service.test.ts
checksum: b488a3b67b801c3fa5b012d2ba2b120b21af4f459b966c6629e6e681ead97913
- filename: server/src/services/recruteurLba.service.test.ts
checksum: 38c947c87cfb508fec88cbce878f89725cbb6679e833a66bdb7fca60e3685a0a
- filename: server/src/services/referrers.service.ts
Expand Down Expand Up @@ -207,6 +211,8 @@ fileignoreconfig:
checksum: 74951335936fd8df7dbbda0dfcb9fd36d01ec96a34d04d61761e5b081ac2bd96
- filename: ui/components/ItemDetail/LbaRecruteurComponents/LbaRecruteurDetail.tsx
checksum: 6e552b66f9238645f70705a0c43c81905e8dbee1c83d364cd89f951f80cb7ea0
- filename: ui/components/ItemDetail/PartnerJobComponents/PartnerJobDetail.tsx
checksum: 88c8bf2cf48aa2c93a73eea7dcd9a040f44cbba3c82ae1b41b80d9939112d0c5
- filename: ui/components/ItemDetail/RecruteurLbaComponents/RecruteurLbaDetail.tsx
checksum: 5d8d24178d6390f4745bcddcaca7e7ea3f8f6af79ef304bb48187a6bea7ccfa1
- filename: ui/components/ItemDetail/TrainingDetail.tsx
Expand Down
100 changes: 58 additions & 42 deletions server/src/common/apis/franceTravail/franceTravail.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@ import { FTResponse } from "@/services/ftjob.service.types"
import { ZFTApiToken } from "@/services/rome.service.types"

import { logger } from "../../logger"
import { apiRateLimiter } from "../../utils/apiUtils"
import { getDbCollection } from "../../utils/mongodbUtils"
import { sentryCaptureException } from "../../utils/sentryUtils"
import getApiClient from "../client"

const axiosClient = getApiClient({}, { cache: false })

const RomeoLimiter = apiRateLimiter("apiRomeo", {
nbRequests: 1,
durationInSeconds: 1,
client: axiosClient,
})

const OffreFranceTravailLimiter = apiRateLimiter("apiOffreFT", {
nbRequests: 10,
durationInSeconds: 1,
client: axiosClient,
})

const getFranceTravailTokenFromDB = async (access_type: IAccessParams): Promise<IFranceTravailAccess["access_token"] | undefined> => {
const data = await getDbCollection("francetravail_access").findOne({ access_type }, { projection: { access_token: 1, _id: 0 } })
return data?.access_token
Expand Down Expand Up @@ -97,33 +110,34 @@ export const searchForFtJobs = async (
}
): Promise<FTResponse | null | ""> => {
const token = await getToken("OFFRE")
return OffreFranceTravailLimiter(async (client) => {
try {
const extendedParams = {
...params,
// paramètres exclurant les offres LBA des résultats de l'api PE
partenaires: "LABONNEALTERNANCE",
modeSelectionPartenaires: "EXCLU",
}

try {
const extendedParams = {
...params,
// paramètres exclurant les offres LBA des résultats de l'api PE
partenaires: "LABONNEALTERNANCE",
modeSelectionPartenaires: "EXCLU",
}

const { data } = await axiosClient.get(`${config.franceTravailIO.baseUrl}/offresdemploi/v2/offres/search`, {
params: extendedParams,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
})
const { data } = await client.get(`${config.franceTravailIO.baseUrl}/offresdemploi/v2/offres/search`, {
params: extendedParams,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
})

return data
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (options.throwOnError) {
throw error
return data
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (options.throwOnError) {
throw error
}
sentryCaptureException(error, { extra: { responseData: error.response?.data } })
return null
}
sentryCaptureException(error, { extra: { responseData: error.response?.data } })
return null
}
})
}

/**
Expand Down Expand Up @@ -184,22 +198,24 @@ type IRomeoOptions = {
export const getRomeoPredictions = async (payload: IRomeoPayload[], options: IRomeoOptions = { nomAppelant: "La bonne alternance" }): Promise<IRomeoAPIResponse | null> => {
if (payload.length > 50) throw Error("Maximum recommanded array size is 50") // Louis feeback https://mna-matcha.atlassian.net/browse/LBA-2232?focusedCommentId=13000
const token = await getToken("ROMEO")
try {
const result = await axiosClient.post(
`${config.franceTravailIO.baseUrl}/romeo/v2/predictionMetiers`,
{ appellations: payload, options },
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
}
)
return result.data
} catch (error: any) {
logger.error("error", error)
sentryCaptureException(error, { extra: { responseData: error.response?.data } })
return null
}
return RomeoLimiter(async (client) => {
try {
const result = await client.post(
`${config.franceTravailIO.baseUrl}/romeo/v2/predictionMetiers`,
{ appellations: payload, options },
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
}
)
return result.data
} catch (error: any) {
logger.error("error", error)
sentryCaptureException(error, { extra: { responseData: error.response?.data } })
return null
}
})
}
40 changes: 40 additions & 0 deletions server/src/http/controllers/jobs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { OPCOS_LABEL } from "shared/constants"
import { getSourceFromCookies } from "@/common/utils/httpUtils"
import { getDbCollection } from "@/common/utils/mongodbUtils"
import { getUserFromRequest } from "@/security/authenticationService"
import { getPartnerJobById } from "@/services/partnerJob.service"
import { Appellation } from "@/services/rome.service.types"
import { getUserWithAccountByEmail } from "@/services/userWithAccount.service"

Expand Down Expand Up @@ -443,6 +444,45 @@ export default (server: Server) => {
}
)

server.get(
"/v1/jobs/partnerJob/:id",
{
schema: zRoutes.get["/v1/jobs/partnerJob/:id"],
config,
},
async (req, res) => {
const { id } = req.params
const { caller } = req.query
const result = await getPartnerJobById({
id,
caller,
})

if ("error" in result) {
switch (result.error) {
case "wrong_parameters": {
res.status(400)
break
}
case "not_found": {
res.status(404)
break
}
case "expired_job": {
res.status(419)
break
}
default: {
res.status(500)
break
}
}
}

return res.send(result)
}
)

server.post(
"/v1/jobs/matcha/:id/stats/view-details",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe("jobEtFormationV1", () => {
expect(response.statusCode).toBe(400)
assert.deepStrictEqual(
JSON.parse(response.body).message,
"querystring.sources: Invalid source format. Must be a comma-separated list of valid sources of formation,matcha,lba,lbb,offres,peJob"
"querystring.sources: Invalid source format. Must be a comma-separated list of valid sources of formation,matcha,lba,lbb,offres,peJob,partnerJob"
)
})

Expand Down
4 changes: 4 additions & 0 deletions server/src/http/controllers/jobsEtFormations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ export default (server: Server) => {
job_count += jobs.matchas.results.length
}

if (jobs && "partnerJobs" in jobs && jobs.partnerJobs && "results" in jobs.partnerJobs) {
job_count += jobs.partnerJobs.results.length
}

const training_count = formations && "results" in formations ? formations.results.length : 0

trackApiCall({
Expand Down
Loading

0 comments on commit 813428a

Please sign in to comment.