Accept ordered doc and file updates

Add an `updates` parameter to the project update endpoint. It can be
used instead of `docUpdates` and `fileUpdates` to provide a single list
of updates in the order they should be processed.
This commit is contained in:
Eric Mc Sween
2020-05-20 07:57:32 -04:00
parent 65fe74fd2d
commit 9799b94752
5 changed files with 250 additions and 115 deletions
@@ -330,19 +330,23 @@ function updateProject(req, res, next) {
userId,
docUpdates,
fileUpdates,
updates,
version
} = req.body
logger.log(
{ projectId, docUpdates, fileUpdates, version },
{ projectId, updates, docUpdates, fileUpdates, version },
'updating project via http'
)
const allUpdates = _mergeUpdates(
docUpdates || [],
fileUpdates || [],
updates || []
)
ProjectManager.updateProjectWithLocks(
projectId,
projectHistoryId,
userId,
docUpdates,
fileUpdates,
allUpdates,
version,
(error) => {
timer.done()
@@ -412,3 +416,23 @@ function flushQueuedProjects(req, res, next) {
}
})
}
/**
* Merge updates from the previous project update interface (docUpdates +
* fileUpdates) and the new update interface (updates).
*/
function _mergeUpdates(docUpdates, fileUpdates, updates) {
const mergedUpdates = []
for (const update of docUpdates) {
const type = update.docLines != null ? 'add-doc' : 'rename-doc'
mergedUpdates.push({ type, ...update })
}
for (const update of fileUpdates) {
const type = update.url != null ? 'add-file' : 'rename-file'
mergedUpdates.push({ type, ...update })
}
for (const update of updates) {
mergedUpdates.push(update)
}
return mergedUpdates
}