Skip to content

Commit

Permalink
feat: LBAC-1559 enregistrer l'intention au clic sur le bouton (#752)
Browse files Browse the repository at this point in the history
* feat: feat: LBAC-1559 enregistrer l'intention au clic sur le bouton

* feat: cleaning comment
  • Loading branch information
alanlr authored Oct 30, 2023
1 parent 0c4c556 commit 865ec4f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
19 changes: 19 additions & 0 deletions server/src/http/routes/sendApplication.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ export default function (server: Server) {
}
)

server.post(
"/application/intention",
{
schema: zRoutes.post["/application/intention"],
config: rateLimitConfig,
},
async (req, res) => {
const decryptedId = decryptWithIV(req.body.id, req.body.iv)

const application = await Application.findOneAndUpdate(
{ _id: new mongoose.Types.ObjectId(decryptedId) },
{ company_recruitment_intention: req.body.intention, company_feedback_date: new Date() }
)
if (!application) throw new Error("application not found")

return res.status(200).send({ result: "ok" })
}
)

server.post(
"/application/webhook",
{
Expand Down
20 changes: 20 additions & 0 deletions shared/routes/application.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ export const zApplicationRoutes = {
"Envoi d'un email de candidature à une offre postée sur La bonne alternance recruteur ou une candidature spontanée à une entreprise identifiée par La bonne alternance.\nL'email est envoyé depuis l'adresse générique \"Ne pas répondre\" de La bonne alternance.\n",
},
},
"/application/intention": {
// TODO_SECURITY_FIX
path: "/application/intention",
method: "post",
body: z
.object({
id: z.string(), // inutile de chiffrer l'id, rajouter un champ token qui contiendra l'id
iv: z.string(),
intention: z.string(),
})
.strict(),
response: {
"200": z
.object({
result: z.literal("ok"),
})
.strict(),
},
securityScheme: null,
},
"/application/intentionComment": {
// TODO_SECURITY_FIX
path: "/application/intentionComment",
Expand Down
16 changes: 0 additions & 16 deletions shared/routes/v1Formations.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,8 @@ export const zV1FormationsRoutes = {
})
.strict(),
response: {
// Strip souhaité. Appel à une API décommissionnée en attente de remplacement
// eslint-disable-next-line zod/require-strict
"200": z.any(),
// .object({
// // eslint-disable-next-line zod/require-strict
// organisme: z
// .object({
// // eslint-disable-next-line zod/require-strict
// contact: z
// .object({
// tel: z.string().nullish(),
// url: z.string().nullish(),
// })
// .strip(),
// })
// .strip(),
// })
// .strip(),
"400": z.union([ZResError, ZLbacError]).openapi({
description: "Bad Request",
}),
Expand Down
10 changes: 10 additions & 0 deletions ui/components/SatisfactionForm/SatisfactionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getValueFromPath } from "../../utils/tools"

import SatisfactionFormNavigation from "./SatisfactionFormNavigation"
import SatisfactionFormSuccess from "./SatisfactionFormSuccess"
import postIntention from "./services/postIntention"
import submitCommentaire from "./services/submitCommentaire"

let iv = null
Expand Down Expand Up @@ -102,9 +103,18 @@ const SatisfactionForm = ({ formType }) => {
return text
}

const sendIntention = async () => {
await postIntention({
id,
intention,
iv,
})
}

useEffect(() => {
// enregistrement en state des params provenant du path
initParametersFromPath()
sendIntention()
}, [])

const [sendingState, setSendingState] = useState("not_sent")
Expand Down

0 comments on commit 865ec4f

Please sign in to comment.