Skip to content
Snippets Groups Projects
Commit 3e29633a authored by Sebastian Mihalache's avatar Sebastian Mihalache
Browse files

feat(component-manuscript-manager): throw error when no previous version is found

parent ffb44fe5
No related branches found
No related tags found
1 merge request!13Sprint #14
...@@ -17,6 +17,12 @@ module.exports = models => async (req, res) => { ...@@ -17,6 +17,12 @@ module.exports = models => async (req, res) => {
return res.status(400).json({ return res.status(400).json({
error: `Collection and fragment do not match.`, error: `Collection and fragment do not match.`,
}) })
const fragLength = collection.fragments.length
if (fragLength < 2) {
return res.status(400).json({
error: 'No previous version has been found.',
})
}
fragment = await models.Fragment.find(fragmentId) fragment = await models.Fragment.find(fragmentId)
const authsome = authsomeHelper.getAuthsome(models) const authsome = authsomeHelper.getAuthsome(models)
...@@ -79,12 +85,7 @@ module.exports = models => async (req, res) => { ...@@ -79,12 +85,7 @@ module.exports = models => async (req, res) => {
}) })
} }
const fragLength = collection.fragments.length fragment.save()
if (fragLength < 2) {
return res.status(400).json({
error: 'No previous version has been found.',
})
}
const previousFragment = await models.Fragment.find( const previousFragment = await models.Fragment.find(
collection.fragments[fragLength - 2], collection.fragments[fragLength - 2],
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment