Fix update bug with work items and activities. Fix placement of item in AR view

This commit is contained in:
John Lyon-Smith
2018-05-01 09:44:23 -07:00
parent edb078b38a
commit 0dce0b5858
11 changed files with 126 additions and 89 deletions

View File

@@ -1,6 +1,7 @@
import passport from "passport"
import createError from "http-errors"
import autobind from "autobind-decorator"
import merge from "deepmerge"
import { catchAll } from "."
@autobind
@@ -146,15 +147,8 @@ export class WorkItemRoutes {
}
let WorkItem = this.db.WorkItem
let workItemUpdates = null
try {
workItemUpdates = new WorkItem(req.body)
} catch (err) {
throw createError.BadRequest("Invalid data")
}
const foundWorkItem = await WorkItem.findById(workItemUpdates._id)
let workItemUpdates = req.body
let foundWorkItem = await WorkItem.findById(workItemUpdates._id)
if (!foundWorkItem) {
return next(
@@ -162,9 +156,13 @@ export class WorkItemRoutes {
)
}
foundWorkItem.merge(workItemUpdates)
// Strip off all BSON types
foundWorkItem = JSON.parse(JSON.stringify(foundWorkItem))
const savedWorkItem = await foundWorkItem.save()
const mergedWorkItem = WorkItem.hydrate(
merge(foundWorkItem, workItemUpdates)
)
const savedWorkItem = await mergedWorkItem.save()
res.json(savedWorkItem.toClient())
}