Skip to content

Commit

Permalink
EDF: [#182] find or create a company when updating a user
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien-Wappizy committed Dec 30, 2024
1 parent d6d5ff6 commit 42d4d6c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/web/server/plugins/entreprisedufutur/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,18 @@ const prePutData = async ({model, id, params, user}) => {
}
}

if (model == 'user') {
if (params.company) {
const nameRegexp = new RegExp(`^${params.company}$`,'i')
const company = await Company.findOneAndUpdate(
{name: nameRegexp},
{name: nameRegexp},
{upsert: true}
)
params.company = company._id
}
}

return {model, id, params, user}
}

Expand Down

0 comments on commit 42d4d6c

Please sign in to comment.