Skip to content

Commit

Permalink
feat: LBA-2255 enregistrement du caller pour l'utilisation du widget …
Browse files Browse the repository at this point in the history
…pour les envois de candidatures (#1299)

* feat: ajustement gestion d'erreurs

* feat: restauration transmission caller

* feat: caller restauré ok

* fix: typing

* feat: openapi

* feat: masquage caller dans openapi
  • Loading branch information
alanlr authored Jun 18, 2024
1 parent d47abd1 commit f392177
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 31 deletions.
2 changes: 1 addition & 1 deletion server/src/http/controllers/application.controller.v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function (server: Server) {
bodyLimit: 5 * 1024 ** 2, // 5MB
},
async (req, res) => {
await sendApplicationV2({ newApplication: req.body })
await sendApplicationV2({ newApplication: req.body, caller: req.body.caller || undefined })
return res.status(200).send({})
}
)
Expand Down
2 changes: 1 addition & 1 deletion server/src/services/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export const sendApplicationV2 = async ({

const recruteurEmail = (type === LBA_ITEM_TYPE.OFFRES_EMPLOI_LBA ? recruiter.email : job.email)?.toLowerCase()
if (!recruteurEmail) {
sentryCaptureException(`Aucun email trouver pour l'offre trouvé. ${type === LBA_ITEM_TYPE.OFFRES_EMPLOI_LBA ? `recruiter: ${recruiter._id} ` : `LbaCompany: ${job._id}`}`)
sentryCaptureException(`${BusinessErrorCodes.INTERNAL_EMAIL} ${type === LBA_ITEM_TYPE.OFFRES_EMPLOI_LBA ? `recruiter: ${recruiter._id} ` : `LbaCompany: ${job._id}`}`)
throw Boom.internal(BusinessErrorCodes.INTERNAL_EMAIL)
}
try {
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/errorCodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export enum BusinessErrorCodes {
BURNER = "L'email est invalide.",
NOTFOUND = "Aucune offre correspondante trouvée.",
ATTACHMENT = "Pièce jointe invalide.",
INTERNAL_EMAIL = "Aucun email trouver pour l'offre trouvé.",
INTERNAL_EMAIL = "Aucun email pour l'offre trouvée.",
}
2 changes: 1 addition & 1 deletion shared/models/applications.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const ZApplication = z
}),
to_applicant_message_id: z.string().nullable().describe("Identifiant chez le transporteur du mail envoyé au candidat"),
to_company_message_id: z.string().nullable().describe("Identifiant chez le transporteur du mail envoyé à l'entreprise"),
caller: z.string().nullable().describe("L'identification de la source d'émission de la candidature (pour widget et api)"),
caller: z.string().nullish().describe("L'identification de la source d'émission de la candidature"),
created_at: z.date().nullable().describe("La date création de la demande"),
last_update_at: z.date().nullable().describe("Date de dernières mise à jour"),
})
Expand Down
9 changes: 8 additions & 1 deletion shared/routes/application.routes.v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ const ZNewApplicationV2NEWJobId = ZApplication.pick({ applicant_first_name: true
})
.openapi("V2 - Application")

const ZNewApplicationV2NEWCompanySiretPrivate = ZNewApplicationV2NEWCompanySiret.extend({
caller: z.string().nullish().describe("L'identification de la source d'émission de la candidature (pour widget uniquement)"),
})
const ZNewApplicationV2NEWJobIdPrivate = ZNewApplicationV2NEWJobId.extend({
caller: z.string().nullish().describe("L'identification de la source d'émission de la candidature (pour widget uniquement)"),
})

export type INewApplicationV2NEWCompanySiret = z.output<typeof ZNewApplicationV2NEWCompanySiret>
export type INewApplicationV2NEWJobId = z.output<typeof ZNewApplicationV2NEWJobId>

Expand All @@ -61,7 +68,7 @@ export const zApplicationRoutesV2 = {
"/_private/application": {
path: "/_private/application",
method: "post",
body: z.union([ZNewApplicationV2NEWCompanySiret, ZNewApplicationV2NEWJobId]),
body: z.union([ZNewApplicationV2NEWCompanySiretPrivate, ZNewApplicationV2NEWJobIdPrivate]),
response: {
"200": z.object({}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const sendingStateValues = {
text: "Vous pourrez en envoyer de nouveau demain",
dataTestId: "CandidatureSpontaneeFailedTooManyApplicationsPerCompanyPerCaller",
},
[BusinessErrorCodes.INTERNAL_EMAIL]: {
title: "Aucune information de contact disponible pour postuler",
text: "Nous ne disposons pas des éléments de contact nécessaires pour relayer votre candidatuer à cette entreprise",
dataTestId: "CandidatureSpontaneeFailedNoEmail",
},
"Internal Server Error": {
title: "Erreur technique",
text: "Veuillez patienter quelques instants et réessayer. Si l'erreur persiste merci de nous contacter.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import hasAlreadySubmittedCandidature from "./services/hasAlreadySubmittedCandid
import submitCandidature from "./services/submitCandidature"
import useLocalStorage from "./services/useLocalStorage"

const WidgetCandidatureLba = ({ item, fakeLocalStorage = null }) => {
const WidgetCandidatureLba = ({ item, caller, fakeLocalStorage = null }) => {
const [sendingState, setSendingState] = useState("not_sent")
const kind: LBA_ITEM_TYPE_OLD = item?.ideaType || ""

Expand Down Expand Up @@ -55,6 +55,7 @@ const WidgetCandidatureLba = ({ item, fakeLocalStorage = null }) => {
formValues,
setSendingState,
LbaJob: item,
caller,
})
if (success) {
setApplied(Date.now().toString())
Expand Down
43 changes: 20 additions & 23 deletions ui/components/ItemDetail/CandidatureLba/WidgetPostuler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,25 @@ const WidgetPostuler = () => {
const fetchPostulerItem = async (parameters) => {
let item = null

switch (parameters.type) {
case LBA_ITEM_TYPE_OLD.MATCHA: {
item = await fetchLbaJobDetails({ id: parameters.itemId })
break
}
case LBA_ITEM_TYPE_OLD.LBA: {
item = await fetchLbaCompanyDetails({ id: parameters.itemId })
break
}
default: {
assertUnreachable("shouldNotHappen" as never)
break
}
}

if (item) {
if (!item?.contact?.email || !item?.contact?.iv) {
setHasError("missing_email")
} else {
setItem(item)
try {
switch (parameters.type) {
case LBA_ITEM_TYPE_OLD.MATCHA: {
item = await fetchLbaJobDetails({ id: parameters.itemId })
break
}
case LBA_ITEM_TYPE_OLD.LBA: {
item = await fetchLbaCompanyDetails({ id: parameters.itemId })
break
}
default: {
assertUnreachable("shouldNotHappen" as never)
break
}
}
} else {
setHasError("item_not_found")
setCaller(parameters.caller)
setItem(item)
} catch (err) {
setHasError(err.message)
}

setIsLoading(false)
Expand All @@ -55,6 +51,7 @@ const WidgetPostuler = () => {
const [isLoading, setIsLoading] = useState(true)
const [hasError, setHasError] = useState(null)
const [item, setItem] = useState(null)
const [caller, setCaller] = useState(null)

return hasError ? (
<WidgetPostulerError hasError={hasError} />
Expand All @@ -64,7 +61,7 @@ const WidgetPostuler = () => {
Veuillez patienter
</Flex>
) : (
<WidgetCandidatureLba item={item} />
<WidgetCandidatureLba item={item} caller={caller} />
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { BusinessErrorCodes } from "@/../shared/constants/errorCodes"
import { Box } from "@chakra-ui/react"
import React from "react"

const WidgetPostulerError = ({ hasError }) => {
const getErrorText = () => {
switch (hasError) {
case "Société non trouvée":
case "item_not_found": {
return "L'offre n'est plus disponible"
}
case "missing_email": {
return "Nous ne disposons pas des informations permettant de postuler en ligne."
case BusinessErrorCodes.INTERNAL_EMAIL: {
return "Les informations de contact disponibles ne permettent pas de postuler auprès de cette société."
}
case "missing_caller_parameter": {
return "La source de l'appel au service est manquante (caller)."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export default async function submitCandidature({
formValues,
setSendingState,
LbaJob = {},
caller,
}: {
formValues: any // TODO
setSendingState: (state: string) => void
LbaJob?: any // TODO
caller?: string
}) {
setSendingState("currently_sending")

Expand All @@ -23,6 +25,7 @@ export default async function submitCandidature({
applicant_file_content: formValues.fileContent,
company_siret: LbaJob.ideaType === LBA_ITEM_TYPE_OLD.LBA ? LbaJob.company?.siret : undefined, // either company_siret or job_id
job_id: LbaJob.ideaType === LBA_ITEM_TYPE_OLD.MATCHA ? LbaJob.job?.id : undefined, // either company_siret or job_id
caller,
}

try {
Expand Down

0 comments on commit f392177

Please sign in to comment.