require at least 2 filled out fields to publish

pull/39/head
unknown 2019-02-20 13:24:13 -05:00
parent 9796a10409
commit 810d7b8e5c
1 changed files with 7 additions and 1 deletions

View File

@ -24,7 +24,13 @@ module.exports = {
if (bookExists) {
throw new HttpError(400, 'Version already exists')
} else {
result = await Book.create(body).fetch()
const { title, isbn, author, publisher } = body
// require at least 2 fields to be filled out
if ([title, isbn, author, publisher].reduce((a, x) => a + (x ? 1 : 0), 0) >= 2) {
result = await Book.create(body).fetch()
} else {
throw new HttpError(400, 'Please fill out at least 2 fields (title, author, publisher, isbn)')
}
}
req.file('opds').upload(sails.config.skipperConfig, async function (err, uploaded) {