Skip to content

Commit

Permalink
Cyberleague: [premieroctet#115] Move rate computing to postPut
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien-Wappizy committed Sep 6, 2024
1 parent 5fa2bfa commit d0c788f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions backend/web/server/plugins/cyberleague/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,6 @@ const preCreate = async ({model, params, user}) => {
}
}

if (model == 'score') {
//todo : vérifier le format sous lequel arrive les questions dans params et adapter si besoin
const computedScores = computeScores(params.questions)
params = {...params, ...computedScores}
}

return Promise.resolve({model, params})
}

Expand All @@ -396,6 +390,7 @@ const postCreate = async ({ model, params, data, user }) => {
if (model == `customerSuccess`) {
await Company.findByIdAndUpdate(params.parent, {$push: {customer_successes: data._id}})
}

if (model == `certification`) {
const model = await getModel(params.parent, [`company`,`user`])
await mongoose.models[model].findByIdAndUpdate(params.parent, {$push: {certifications: data._id}})
Expand All @@ -416,6 +411,11 @@ const postPutData = async ({model, id, params, user}) => {
await Group.updateOne({_id:id}, {$pull: {pending_users: params.users}})
}
}

if (model == 'score' && params.is_drafted) {
const computedScores = computeScores(params.answers)
params = {...params, ...computedScores}
}
return {model, id, params, user}
}

Expand Down

0 comments on commit d0c788f

Please sign in to comment.