Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

Commit

Permalink
Return the newest application upon update
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrohee committed Aug 1, 2017
1 parent 0a69187 commit 1be5bed
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions server/api/application/application.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@ class ApplicationController {
return next(new StandardError(`Le PEPITE avec l\'id: ${req.body.pepite.pepite} n'existe pas`, { code: 400 }))
}
return Application
.findByIdAndUpdate(req.params.id, req.body, { new: false })
.then((application) => {
if (!application) {
.findById(req.params.id)
.then((oldApplication) => {
if (!oldApplication) {
return res.sendStatus(404)
}
return Pepite.findById(application.pepite.pepite).then((pepiteOld) => {
this.notifyPepiteTransfer(application, pepiteNew, pepiteOld, req)
return res.json(req.body)
})
return Application
.findByIdAndUpdate(req.params.id, req.body, { new: true })
.then((application) => {
return Pepite.findById(oldApplication.pepite.pepite).then((pepiteOld) => {
this.notifyPepiteTransfer(application, pepiteNew, pepiteOld, req)
return res.json(application)
})
})
})
})
.catch((err) => {
Expand Down

0 comments on commit 1be5bed

Please sign in to comment.