require at least 2 filled out fields to publish
parent
9796a10409
commit
810d7b8e5c
|
@ -24,7 +24,13 @@ module.exports = {
|
|||
if (bookExists) {
|
||||
throw new HttpError(400, 'Version already exists')
|
||||
} else {
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue