Skip to content
Snippets Groups Projects
Commit 5e3de31e authored by Sebastian's avatar Sebastian
Browse files

added name and email validations

parent 934a4e5f
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,28 @@ const AuthorBackend = app => {
req.params.fragmentId,
)
fragment.authors = fragment.authors ? fragment.authors : []
if (fragment.authors.length > 0) {
const emailAuthors = fragment.authors.filter(
author => author.email === req.body.email,
)
if (emailAuthors.length > 0) {
res.status(400).json({ error: 'Author already exists' })
return
}
const nameAuthors = fragment.authors.filter(
author =>
author.first_name === req.body.first_name &&
author.middle_name === req.body.middle_name &&
author.last_name === req.body.last_name,
)
if (nameAuthors.length > 0) {
res.status(400).json({ error: 'Author already exists' })
return
}
}
fragment.authors.push(req.body)
fragment = await fragment.save()
res.status(200).json(fragment)
......
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