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 42d4d6c commit 1867566
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions backend/web/server/plugins/entreprisedufutur/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,14 +876,18 @@ const prePutData = async ({model, id, params, user}) => {
}

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

//TODO : fix that thing
const loadCompany = await Company.findOne({name: params['company.name']})

params.company = loadCompany._id
}
}

Expand Down

0 comments on commit 1867566

Please sign in to comment.