Skip to content

Commit

Permalink
fix: post v2/jobs: traduction & workplace_name (#1519)
Browse files Browse the repository at this point in the history
* fix: traduction & workplace_name

* fix: snapshot
  • Loading branch information
kevbarns authored Sep 18, 2024
1 parent ad35cb0 commit dd2ca17
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
34 changes: 27 additions & 7 deletions server/src/services/etablissement.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,28 +462,48 @@ export const validateCreationEntrepriseFromCfa = async ({ siret, cfa_delegated_s
}
}

export const getEntrepriseDataFromSiret = async ({ siret, type }: { siret: string; type: "CFA" | "ENTREPRISE" }): Promise<EntrepriseData | IBusinessError> => {
export const getEntrepriseDataFromSiret = async ({
siret,
type,
isApiApprentissage = false,
}: {
siret: string
type: "CFA" | "ENTREPRISE"
isApiApprentissage?: boolean
}): Promise<EntrepriseData | IBusinessError> => {
const result = await getEtablissementFromGouvSafe(siret)
if (!result) {
return errorFactory("Le numéro siret est invalide.")
}
if (result === BusinessErrorCodes.NON_DIFFUSIBLE) {
return errorFactory(
`Les informations de votre entreprise sont non diffusibles. <a href="mailto:[email protected]?subject=Espace%20pro%20-%20Donnees%20entreprise%20non%20diffusibles" target="_blank" title="contacter le support - nouvelle fenêtre">Contacter le support pour en savoir plus</a>`,
BusinessErrorCodes.NON_DIFFUSIBLE
)
if (isApiApprentissage) {
return errorFactory("Non-distributable company.", BusinessErrorCodes.NON_DIFFUSIBLE)
} else {
return errorFactory(
`Les informations de votre entreprise sont non diffusibles. <a href="mailto:[email protected]?subject=Espace%20pro%20-%20Donnees%20entreprise%20non%20diffusibles" target="_blank" title="contacter le support - nouvelle fenêtre">Contacter le support pour en savoir plus</a>`,
BusinessErrorCodes.NON_DIFFUSIBLE
)
}
}

const { etat_administratif, activite_principale } = result.data

if (etat_administratif === "F") {
return errorFactory("Cette entreprise est considérée comme fermée.", BusinessErrorCodes.CLOSED)
if (isApiApprentissage) {
return errorFactory("The company is considered closed.", BusinessErrorCodes.CLOSED)
} else {
return errorFactory("Cette entreprise est considérée comme fermée.", BusinessErrorCodes.CLOSED)
}
}
// Check if a CFA already has the company as partenaire
if (type === ENTREPRISE) {
// Allow cfa to add themselves as a company
if (activite_principale.code.startsWith("85")) {
return errorFactory("Le numéro siret n'est pas référencé comme une entreprise.", BusinessErrorCodes.IS_CFA)
if (isApiApprentissage) {
return errorFactory("The SIRET number is not referenced as a company.", BusinessErrorCodes.IS_CFA)
} else {
return errorFactory("Le numéro siret n'est pas référencé comme une entreprise.", BusinessErrorCodes.IS_CFA)
}
}
}
const entrepriseData = formatEntrepriseData(result.data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exports[`createJobOffer > should create a job offer with the minimal data 1`] =
"workplace_legal_name": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
"workplace_naf_code": "84.11Z",
"workplace_naf_label": "Administration publique générale",
"workplace_name": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
"workplace_name": null,
"workplace_opco": "AKTO / Opco entreprises et salariés des services à forte intensité de main d'oeuvre",
"workplace_siret": "13002526500013",
"workplace_size": "100 à 199 salariés",
Expand Down Expand Up @@ -287,7 +287,7 @@ exports[`updateJobOffer > should update a job offer with the minimal data 1`] =
"workplace_legal_name": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
"workplace_naf_code": "84.11Z",
"workplace_naf_label": "Administration publique générale",
"workplace_name": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
"workplace_name": null,
"workplace_opco": "AKTO / Opco entreprises et salariés des services à forte intensité de main d'oeuvre",
"workplace_siret": "13002526500013",
"workplace_size": "100 à 199 salariés",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ type WorkplaceSiretData = Pick<
IJobsPartnersOfferApi,
| "workplace_geopoint"
| "workplace_address"
| "workplace_name"
| "workplace_legal_name"
| "workplace_brand"
| "workplace_naf_label"
Expand All @@ -567,7 +566,10 @@ type WorkplaceSiretData = Pick<
>

async function resolveWorkplaceDataFromSiret(workplace_siret: string, zodError: ZodError): Promise<WorkplaceSiretData | null> {
const [entrepriseData, opcoData] = await Promise.all([getEntrepriseDataFromSiret({ siret: workplace_siret, type: "ENTREPRISE" }), getOpcoData(workplace_siret)])
const [entrepriseData, opcoData] = await Promise.all([
getEntrepriseDataFromSiret({ siret: workplace_siret, type: "ENTREPRISE", isApiApprentissage: true }),
getOpcoData(workplace_siret),
])

if ("error" in entrepriseData) {
zodError.addIssue({ code: "custom", path: ["workplace_siret"], message: entrepriseData.message })
Expand All @@ -577,7 +579,6 @@ async function resolveWorkplaceDataFromSiret(workplace_siret: string, zodError:
return {
workplace_geopoint: entrepriseData.geopoint,
workplace_address: { label: entrepriseData.address! },
workplace_name: entrepriseData.establishment_enseigne ?? entrepriseData.establishment_raison_sociale ?? null,
workplace_brand: entrepriseData.establishment_enseigne ?? null,
workplace_legal_name: entrepriseData.establishment_raison_sociale ?? null,
workplace_naf_label: entrepriseData.naf_label ?? null,
Expand Down

0 comments on commit dd2ca17

Please sign in to comment.