Fix update bug with work items and activities. Fix placement of item in AR view
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user