Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Lbac 1491 multi compte : branchement des nouvelles tables #1099

Merged
merged 92 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
660bb26
fix: wip
remy-auricoste Oct 24, 2023
bf3c23d
Merge branch 'main' into lbac-1494-multi-compte-users-2
remy-auricoste Oct 31, 2023
ecc3285
Merge branch 'main' into lbac-1494-multi-compte-v3
remy-auricoste Feb 22, 2024
f10fe4d
fix: update talisman
remy-auricoste Feb 22, 2024
7fe6d7f
fix: typing + small refactor migration script
remy-auricoste Feb 22, 2024
ca842ed
fix: renommage des champs + refactor
remy-auricoste Feb 22, 2024
87427af
fix: renommage des champs + commande + test ok
remy-auricoste Feb 22, 2024
4ddd68d
fix: import schemas
remy-auricoste Feb 22, 2024
c96b387
Merge branch 'main' into lbac-1494-multi-compte-v3
remy-auricoste Feb 22, 2024
9b73cdd
fix: renommage des champs first_name et last_name
remy-auricoste Feb 26, 2024
b97c652
fix: lbac 1491 : debut de plug des nouvelles tables
remy-auricoste Feb 26, 2024
19fabc0
fix: clean
remy-auricoste Feb 26, 2024
0c568cb
fix: refactor getUser to getUserRecruteurById and getUserRecruteurByE…
remy-auricoste Feb 26, 2024
7c03aa4
fix: suppression jobs obsolètes + remplacement simple de UserRecruteu…
remy-auricoste Feb 26, 2024
1d670c6
fix: refactor updateLastConnectionDate
remy-auricoste Feb 26, 2024
429f8e4
fix: clean vieux jobs
remy-auricoste Feb 26, 2024
6857566
fix: refactor to validateUserEmail and updateUser2Fields
remy-auricoste Feb 27, 2024
6600ac6
fix: refactor export PE
remy-auricoste Feb 27, 2024
26dae98
fix: refactor application.service
remy-auricoste Feb 27, 2024
b8e3b24
fix: refactor email validation
remy-auricoste Feb 27, 2024
c8cbddb
fix: refactor utilisation de getUser
remy-auricoste Feb 27, 2024
04aad26
fix: suppression de la methode getUser
remy-auricoste Feb 27, 2024
d54098e
fix: renommage variable
remy-auricoste Feb 27, 2024
f5a235e
fix: refactor createUser + refactor relanceOpco
remy-auricoste Feb 29, 2024
64266d9
fix: suppression de updateMissingActivationState
remy-auricoste Mar 5, 2024
3c4b5b0
fix: refactor user recruteur
remy-auricoste Mar 5, 2024
9b9c2e0
fix: fichiers manquants + modification d'acces via /history
remy-auricoste Mar 5, 2024
0339d22
fix: update auth
remy-auricoste Mar 6, 2024
3320b3a
fix: renomme permissions.service en roleManagement.service
remy-auricoste Mar 6, 2024
cb3eb0e
fix: toPublicUser
remy-auricoste Mar 6, 2024
e423732
fix: typing server
remy-auricoste Mar 6, 2024
a2cd1d1
fix: refactor using useUserPermissionsActions
remy-auricoste Mar 6, 2024
730bec8
fix: refactor de UserForm
remy-auricoste Mar 6, 2024
0e04ae8
fix: squiz frontend typing en simplifiant les endpoints api
remy-auricoste Mar 6, 2024
2f4d81b
fix: start server et fix __v et champs mongo
remy-auricoste Mar 6, 2024
dea264c
fix: suppression d une occurrence de UserRecruteur
remy-auricoste Mar 6, 2024
24d036c
fix: suppression de establishment_id de Entreprise + refacto anonymis…
remy-auricoste Mar 7, 2024
f72862b
fix: script migration: extraction variable parallelism
remy-auricoste Mar 7, 2024
be2cd4f
fix: ajout indexs + amelioration status migration + essaie lookup
remy-auricoste Mar 7, 2024
4300e36
fix: refactor admin page
remy-auricoste Mar 13, 2024
281020f
fix: admin: ajout des utilisateurs actifs + fix activation/desactivation
remy-auricoste Mar 14, 2024
59ca40b
fix: stockage status entreprise + fix mail desactivation
remy-auricoste Mar 14, 2024
9175d9d
fix: validation d email
remy-auricoste Mar 14, 2024
2dc4710
fix: opco access
remy-auricoste Mar 14, 2024
8ce2022
fix: wip
remy-auricoste Mar 15, 2024
43311bc
fix: backoffice user pour admin et opco
remy-auricoste Mar 19, 2024
fcc18e7
fix: cache les cfa à valider aux opcos
remy-auricoste Mar 19, 2024
c51198f
fix: /admin/users
remy-auricoste Mar 19, 2024
41eb2f7
fix: refactor pages de gestion des utilisateurs admin
remy-auricoste Mar 20, 2024
26d6986
fix: update of user
remy-auricoste Mar 20, 2024
98d1262
fix: migration entreprises et cfa + modification compte
remy-auricoste Mar 20, 2024
d14cfac
fix: refactor ids + clean unused function
remy-auricoste Mar 21, 2024
e8a7039
fix: fill establishment_id
remy-auricoste Mar 21, 2024
904d998
fix: ajout TODO
remy-auricoste Mar 21, 2024
38aac71
fix: creation offre par opco ou admin
remy-auricoste Mar 21, 2024
4214883
fix: expose user access
remy-auricoste Mar 21, 2024
2f9ddf6
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Mar 25, 2024
dae799d
fix: lbajob.service
remy-auricoste Mar 25, 2024
f4e2e48
fix: update seed
remy-auricoste Mar 25, 2024
5be3989
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Mar 26, 2024
768712d
fix: suppression bouton modifier l entreprise
remy-auricoste Mar 26, 2024
a227090
fix: tests cypress + bugs
remy-auricoste Mar 26, 2024
e632483
fix: rename test cypress
remy-auricoste Mar 26, 2024
fd033f1
fix: amelioration fiabilite test cypress
remy-auricoste Mar 27, 2024
3d10e64
fix: 1er jet tests authorization.service
remy-auricoste Mar 27, 2024
4f61e4f
fix: tests create user and log
remy-auricoste Mar 27, 2024
75e5ea7
fix: accessTokenService.test
remy-auricoste Mar 27, 2024
ea4d453
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Mar 27, 2024
8b8785e
fix: token tests
remy-auricoste Mar 27, 2024
297652e
fix: refactor update user
remy-auricoste Mar 28, 2024
3dc1517
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Mar 28, 2024
dd68055
fix: update db
remy-auricoste Mar 28, 2024
443a9fd
fix: search rome
remy-auricoste Mar 28, 2024
8d172a4
fix: ajout validation zod de l'adresse venant de l'api entreprise
remy-auricoste Mar 28, 2024
420cef2
fix: ajout des validations des nouveaux modèles dans le db validate
remy-auricoste Mar 28, 2024
f2bca73
fix: address_detail
remy-auricoste Mar 28, 2024
2b7f630
fix: update db
remy-auricoste Mar 28, 2024
f18ff5c
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Mar 30, 2024
cc722ba
fix: search count on jobs
remy-auricoste Apr 2, 2024
8302b45
fix: amelioration secu acces user depuis le backoffice opco
remy-auricoste Apr 2, 2024
3bd4dd2
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Apr 2, 2024
e562165
fix: adaptation des access logs
remy-auricoste Apr 2, 2024
abc86c8
fix: search
remy-auricoste Apr 3, 2024
9d12dcf
fix: amelioration label des tests
remy-auricoste Apr 4, 2024
0739d11
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Apr 17, 2024
b0b4a23
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Apr 17, 2024
d9fb28c
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Apr 17, 2024
f5fd07f
fix: script de reprise siret: pas de reprise des roles au status DENIED
remy-auricoste Apr 24, 2024
c86a615
fix: script reprise entreprise: gestion du status A_METTRE_A_JOUR
remy-auricoste Apr 24, 2024
ca1b738
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Apr 24, 2024
8903cbe
fix: typing
remy-auricoste Apr 24, 2024
df627a9
Merge branch 'main' into lbac-1491-multi-compte-plug
remy-auricoste Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .infra/files/configs/mongodb/seed.gpg
Git LFS file not shown
4 changes: 3 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fileignoreconfig:
- filename: server/src/security/accessTokenService.ts
checksum: 2183e326a88ae3c10193a7033ab5fd421ce576cd1e234c323df247da335f74d7
- filename: server/src/services/application.service.ts
checksum: d3ae58c0b6a9d42164b69dff4573734a6d854282974c4a10d065f2c2443f144a
checksum: 38021ae663db3a146c848a8d691c0c1bc9bb262a80a6f2dedf9fcdb372eef3ac
- filename: server/src/services/eligibleTrainingsForAppointment.service.ts
checksum: 52bfe91cc0cd07121cad6dc9490a7345dbbbeb285f11fc844a8dd8eb74fe310f
- filename: server/src/services/userRecruteur.service.ts
Expand Down Expand Up @@ -121,6 +121,8 @@ fileignoreconfig:
checksum: a50177afa593bae5707bdba29ef27b8f2ed0bc58487491bfff580e7e1f422243
- filename: ui/components/espace_pro/Admin/utilisateurs/infoDetails/InfoDetails.tsx
checksum: be2ad6ca5c2bd36d26cd7aebb33ab876bd32662be3735fee3b167325c284ccff
- filename: ui/components/footer.tsx
checksum: d82b5a7d6905070fb32383864566fc16eae4797ca18f82782fb32c95a0d50369
- filename: ui/pages/accessibilite.tsx
checksum: d6a7c57500f9de5e47e305f89435b21d717f505acac7b45656931f7ecdd0fcca
- filename: ui/pages/espace-pro/admin/eligible-trainings-for-appointment/search.tsx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { FlowCreationEntreprise } from "../pages/FlowCreationEntreprise"
import { JobPage } from "../pages/JobPage"
import { generateRandomString } from "../utils/generateRandomString"

describe("create-recruiter-account-siret-inexistent", () => {
it("tests create-recruiter-account-siret-inexistent", () => {
describe("create-recruiter-account-manual-validation", () => {
it("tests create-recruiter-account-manual-validation", () => {
cy.viewport(1271, 721)

const email = `cypress-manual-validation-${generateRandomString()}@mail.com`
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/create-recruiter-account.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { JobPage } from "../pages/JobPage"
import { LoginBar } from "../pages/LoginBar"
import { generateRandomString } from "../utils/generateRandomString"

describe("create-recruiter-account-siret-inexistent", () => {
it("test create-recruiter-account-siret-inexistent", () => {
describe("create-recruiter-account", () => {
it("test create-recruiter-account", () => {
cy.viewport(1271, 721)

const emailDomain = Cypress.env("ENTREPRISE_AUTOVALIDE_EMAIL_DOMAIN")
Expand Down
4 changes: 4 additions & 0 deletions server/src/common/model/schema/jobs/jobs.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export const jobsSchema = new Schema<IJob>(
type: Number,
description: "Nombre de vues sur une page de recherche",
},
managed_by: {
type: String,
description: "Id de l'utilisateur gérant l'offre",
},
},
{
versionKey: false,
Expand Down
2 changes: 1 addition & 1 deletion server/src/common/model/schema/user/user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const userSchema = new Schema<IUser>(
role: {
type: String,
default: null,
description: "candidat | cfa | administrator",
description: "candidat | administrator",
},
last_action_date: {
type: Date,
Expand Down
108 changes: 54 additions & 54 deletions server/src/http/controllers/etablissementRecruteur.controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import Boom from "boom"
import { IUserRecruteur, toPublicUser, zRoutes } from "shared"
import { assertUnreachable, toPublicUser, zRoutes } from "shared"
import { BusinessErrorCodes } from "shared/constants/errorCodes"
import { ETAT_UTILISATEUR, RECRUITER_STATUS } from "shared/constants/recruteur"
import { RECRUITER_STATUS } from "shared/constants/recruteur"
import { UserEventType } from "shared/models/user2.model"
import { getLastStatusEvent } from "shared/utils/getLastStatusEvent"

import { Recruiter, UserRecruteur } from "@/common/model"
import { Cfa, Recruiter } from "@/common/model"
import { startSession } from "@/common/utils/session.service"
import config from "@/config"
import { user2ToUserForToken } from "@/security/accessTokenService"
import { getUserFromRequest } from "@/security/authenticationService"
import { generateDepotSimplifieToken } from "@/services/appLinks.service"
import { getPublicUserRecruteurPropsOrError } from "@/services/roleManagement.service"
import { getUser2ByEmail, validateUser2Email } from "@/services/user2.service"

import { getAllDomainsFromEmailList, getEmailDomain, isEmailFromPrivateCompany, isUserMailExistInReferentiel } from "../../common/utils/mailUtils"
import { notifyToSlack } from "../../common/utils/slackUtils"
Expand All @@ -21,17 +26,16 @@ import {
getOrganismeDeFormationDataFromSiret,
sendUserConfirmationEmail,
validateCreationEntrepriseFromCfa,
validateEtablissementEmail,
} from "../../services/etablissement.service"
import {
autoValidateUser,
createUser,
getUser,
getUserStatus,
createOrganizationUser,
getUserRecruteurByEmail,
isUserEmailChecked,
sendWelcomeEmailToUserRecruteur,
setUserHasToBeManuallyValidated,
updateLastConnectionDate,
updateUser,
updateUser2Fields,
} from "../../services/userRecruteur.service"
import { Server } from "../server"

Expand Down Expand Up @@ -72,7 +76,7 @@ export default (server: Server) => {
throw Boom.badRequest(cfaVerification.message)
}

const result = await getEntrepriseDataFromSiret({ siret, cfa_delegated_siret })
const result = await getEntrepriseDataFromSiret({ siret, type: cfa_delegated_siret ? CFA : ENTREPRISE })

if ("error" in result) {
throw Boom.badRequest(result.message, result)
Expand Down Expand Up @@ -125,18 +129,18 @@ export default (server: Server) => {
* Retourne les entreprises gérées par un CFA
*/
server.get(
"/etablissement/cfa/:userRecruteurId/entreprises",
"/etablissement/cfa/:cfaId/entreprises",
{
schema: zRoutes.get["/etablissement/cfa/:userRecruteurId/entreprises"],
onRequest: [server.auth(zRoutes.get["/etablissement/cfa/:userRecruteurId/entreprises"])],
schema: zRoutes.get["/etablissement/cfa/:cfaId/entreprises"],
onRequest: [server.auth(zRoutes.get["/etablissement/cfa/:cfaId/entreprises"])],
},
async (req, res) => {
const { userRecruteurId } = req.params
const cfa = await UserRecruteur.findOne({ _id: userRecruteurId }).lean()
const { cfaId } = req.params
const cfa = await Cfa.findOne({ _id: cfaId }).lean()
if (!cfa) {
throw Boom.notFound(`Aucun CFA ayant pour id ${userRecruteurId.toString()}`)
throw Boom.notFound(`Aucun CFA ayant pour id ${cfaId.toString()}`)
}
const cfa_delegated_siret = cfa.establishment_siret
const cfa_delegated_siret = cfa.siret
if (!cfa_delegated_siret) {
throw Boom.internal(`inattendu : le cfa n'a pas de champ cfa_delegated_siret`)
}
Expand All @@ -154,7 +158,8 @@ export default (server: Server) => {
schema: zRoutes.post["/etablissement/creation"],
},
async (req, res) => {
switch (req.body.type) {
const { type } = req.body
switch (type) {
case ENTREPRISE: {
const siret = req.body.establishment_siret
const cfa_delegated_siret = req.body.cfa_delegated_siret ?? undefined
Expand All @@ -163,14 +168,14 @@ export default (server: Server) => {
if (result.errorCode === BusinessErrorCodes.ALREADY_EXISTS) throw Boom.forbidden(result.message, result)
else throw Boom.badRequest(result.message, result)
}
const token = generateDepotSimplifieToken(result.user)
return res.status(200).send({ ...result, token })
const token = generateDepotSimplifieToken(user2ToUserForToken(result.user), result.formulaire.establishment_id)
return res.status(200).send({ formulaire: result.formulaire, user: result.user, token, validated: result.validated })
}
case CFA: {
const { email, establishment_siret } = req.body
const formatedEmail = email.toLocaleLowerCase()
// check if user already exist
const userRecruteurOpt = await getUser({ email: formatedEmail })
const userRecruteurOpt = await getUserRecruteurByEmail(formatedEmail)
if (userRecruteurOpt) {
throw Boom.forbidden("L'adresse mail est déjà associée à un compte La bonne alternance.")
}
Expand All @@ -179,44 +184,45 @@ export default (server: Server) => {
const { contacts } = siretInfos

// Creation de l'utilisateur en base de données
let newCfa: IUserRecruteur = await createUser({ ...req.body, ...siretInfos, is_email_checked: false })
const creationResult = await createOrganizationUser({ ...req.body, ...siretInfos, is_email_checked: false })
const userCfa = creationResult.user

const slackNotification = {
subject: "RECRUTEUR",
message: `Nouvel OF en attente de validation - ${config.publicUrl}/espace-pro/administration/users/${newCfa._id}`,
message: `Nouvel OF en attente de validation - ${config.publicUrl}/espace-pro/administration/users/${userCfa._id}`,
}
if (!contacts.length) {
// Validation manuelle de l'utilisateur à effectuer pas un administrateur
newCfa = await setUserHasToBeManuallyValidated(newCfa._id)
await setUserHasToBeManuallyValidated(creationResult)
await notifyToSlack(slackNotification)
return res.status(200).send({ user: newCfa })
return res.status(200).send({ user: userCfa })
}
if (isUserMailExistInReferentiel(contacts, email)) {
// Validation automatique de l'utilisateur
newCfa = await autoValidateUser(newCfa._id)
await sendUserConfirmationEmail(newCfa)
await autoValidateUser(creationResult)
await sendUserConfirmationEmail(userCfa)
// Keep the same structure as ENTREPRISE
return res.status(200).send({ user: newCfa })
return res.status(200).send({ user: userCfa })
}
if (isEmailFromPrivateCompany(formatedEmail)) {
const domains = getAllDomainsFromEmailList(contacts.map(({ email }) => email))
const userEmailDomain = getEmailDomain(formatedEmail)
if (userEmailDomain && domains.includes(userEmailDomain)) {
// Validation automatique de l'utilisateur
newCfa = await autoValidateUser(newCfa._id)
await sendUserConfirmationEmail(newCfa)
await autoValidateUser(creationResult)
await sendUserConfirmationEmail(userCfa)
// Keep the same structure as ENTREPRISE
return res.status(200).send({ user: newCfa })
return res.status(200).send({ user: userCfa })
}
}
// Validation manuelle de l'utilisateur à effectuer pas un administrateur
newCfa = await setUserHasToBeManuallyValidated(newCfa._id)
await setUserHasToBeManuallyValidated(creationResult)
await notifyToSlack(slackNotification)
// Keep the same structure as ENTREPRISE
return res.status(200).send({ user: newCfa })
return res.status(200).send({ user: userCfa })
}
default: {
throw Boom.badRequest("unsupported type")
assertUnreachable(type)
}
}
}
Expand Down Expand Up @@ -250,11 +256,10 @@ export default (server: Server) => {
},
async (req, res) => {
const { _id, ...rest } = req.body
const exists = await UserRecruteur.findOne({ email: req.body.email?.toLocaleLowerCase(), _id: { $ne: _id } })
if (exists) {
const result = await updateUser2Fields(req.params.id, rest)
if ("error" in result) {
throw Boom.badRequest("L'adresse mail est déjà associée à un compte La bonne alternance.")
}
await updateUser({ _id: req.params.id }, rest)
return res.status(200).send({ ok: true })
}
)
Expand All @@ -266,30 +271,25 @@ export default (server: Server) => {
onRequest: [server.auth(zRoutes.post["/etablissement/validation"])],
},
async (req, res) => {
const user = getUserFromRequest(req, zRoutes.post["/etablissement/validation"]).value

// Validate email
const userRecruteur = await validateEtablissementEmail(user.identity.email.toLocaleLowerCase())
const userFromRequest = getUserFromRequest(req, zRoutes.post["/etablissement/validation"]).value
const email = userFromRequest.identity.email.toLocaleLowerCase()

if (!userRecruteur) {
const user = await getUser2ByEmail(email)
if (!user) {
throw Boom.badRequest("La validation de l'adresse mail a échoué. Merci de contacter le support La bonne alternance.")
}

const isUserAwaiting = getUserStatus(userRecruteur.status) === ETAT_UTILISATEUR.ATTENTE

if (!isUserAwaiting) {
await sendWelcomeEmailToUserRecruteur(userRecruteur)
const userStatus = getLastStatusEvent(user.status)?.status
if (userStatus === UserEventType.DESACTIVE) {
throw Boom.forbidden("Votre compte est désactivé. Merci de contacter le support La bonne alternance.")
}

const connectedUser = await updateLastConnectionDate(userRecruteur.email)

if (!connectedUser) {
throw Boom.forbidden()
if (!isUserEmailChecked(user)) {
await validateUser2Email(user._id.toString())
await sendWelcomeEmailToUserRecruteur(user)
}

await startSession(userRecruteur.email, res)

return res.status(200).send(toPublicUser(connectedUser))
await updateLastConnectionDate(email)
await startSession(email, res)
return res.status(200).send(toPublicUser(user, await getPublicUserRecruteurPropsOrError(user._id, true)))
}
)
}
25 changes: 16 additions & 9 deletions server/src/http/controllers/formulaire.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Boom from "boom"
import { zRoutes } from "shared/index"

import { UserRecruteur } from "@/common/model"
import { getUserFromRequest } from "@/security/authenticationService"
import { generateOffreToken } from "@/services/appLinks.service"
import { getUser2ByEmail } from "@/services/user2.service"
import { getUserRecruteurById } from "@/services/userRecruteur.service"

import { getApplicationsByJobId } from "../../services/application.service"
import { entrepriseOnboardingWorkflow } from "../../services/etablissement.service"
Expand All @@ -21,7 +23,6 @@ import {
provideOffre,
updateFormulaire,
} from "../../services/formulaire.service"
import { getUser } from "../../services/userRecruteur.service"
import { Server } from "../server"

export default (server: Server) => {
Expand Down Expand Up @@ -105,7 +106,7 @@ export default (server: Server) => {
async (req, res) => {
const { userId: userRecruteurId } = req.params
const { establishment_siret, email, last_name, first_name, phone, opco, idcc } = req.body
const userRecruteurOpt = await getUser({ _id: userRecruteurId })
const userRecruteurOpt = await getUserRecruteurById(userRecruteurId)
if (!userRecruteurOpt) {
throw Boom.badRequest("Nous n'avons pas trouvé votre compte utilisateur")
}
Expand Down Expand Up @@ -202,6 +203,7 @@ export default (server: Server) => {
},
async (req, res) => {
const { establishment_id } = req.params
const user = getUserFromRequest(req, zRoutes.post["/formulaire/:establishment_id/offre"]).value
const {
is_disabled_elligible,
job_type,
Expand Down Expand Up @@ -231,13 +233,15 @@ export default (server: Server) => {
rome_code,
rome_label,
},
user,
establishment_id,
})
const job = updatedFormulaire.jobs.at(0)
if (!job) {
throw new Error("unexpected")
}
return res.status(200).send({ recruiter: updatedFormulaire })
const token = generateOffreToken(user, job)
return res.status(200).send({ recruiter: updatedFormulaire, token })
}
)

Expand All @@ -253,6 +257,12 @@ export default (server: Server) => {
},
async (req, res) => {
const { establishment_id } = req.params
const tokenUser = getUserFromRequest(req, zRoutes.post["/formulaire/:establishment_id/offre/by-token"]).value
const { email } = tokenUser.identity
const user = await getUser2ByEmail(email)
if (!user) {
throw Boom.internal(`inattendu : impossible de récupérer l'utilisateur de type token ayant pour email=${email}`)
}
const {
is_disabled_elligible,
job_type,
Expand All @@ -267,10 +277,6 @@ export default (server: Server) => {
rome_code,
rome_label,
} = req.body
const userRecruteur = await UserRecruteur.findOne({ establishment_id }).lean()
if (!userRecruteur) {
throw Boom.notFound()
}
const updatedFormulaire = await createJob({
job: {
is_disabled_elligible,
Expand All @@ -287,12 +293,13 @@ export default (server: Server) => {
rome_label,
},
establishment_id,
user,
})
const job = updatedFormulaire.jobs.at(0)
if (!job) {
throw new Error("unexpected")
}
const token = generateOffreToken(userRecruteur, job)
const token = generateOffreToken(user, job)
return res.status(200).send({ recruiter: updatedFormulaire, token })
}
)
Expand Down
Loading
Loading