Improve merge on update
This commit is contained in:
@@ -147,22 +147,19 @@ export class WorkItemRoutes {
|
||||
}
|
||||
|
||||
let WorkItem = this.db.WorkItem
|
||||
let workItemUpdates = req.body
|
||||
let foundWorkItem = await WorkItem.findById(workItemUpdates._id)
|
||||
let workItem = await WorkItem.findById(req.body._id)
|
||||
|
||||
if (!foundWorkItem) {
|
||||
if (!workItem) {
|
||||
return next(
|
||||
createError.NotFound(`WorkItem with _id ${_id} was not found`)
|
||||
createError.NotFound(`WorkItem with _id ${req.body_id} was not found`)
|
||||
)
|
||||
}
|
||||
|
||||
// Strip off all BSON types
|
||||
foundWorkItem = JSON.parse(JSON.stringify(foundWorkItem))
|
||||
const workItemUpdates = new WorkItem(req.body)
|
||||
|
||||
const mergedWorkItem = WorkItem.hydrate(
|
||||
merge(foundWorkItem, workItemUpdates)
|
||||
)
|
||||
const savedWorkItem = await mergedWorkItem.save()
|
||||
workItem.merge(workItemUpdates)
|
||||
|
||||
const savedWorkItem = await workItem.save()
|
||||
|
||||
res.json(savedWorkItem.toClient())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user