add endpoint to list all books

pull/2/head
unknown 2018-10-23 23:42:46 -04:00
parent c21bcdb9c8
commit 39c706b95a
2 changed files with 25 additions and 0 deletions

View File

@ -31,5 +31,25 @@ module.exports = {
error: e.message error: e.message
}) })
} }
},
list: async function (req, res) {
try {
const body = req.allParams()
if (!body) throw new Error('Missing parameters')
const books = await Book.find(body)
if (!books.length) {
return res.status(404).json({
error: 'No books matching those parameters were found.'
})
}
return res.json(books)
} catch (e) {
return res.status(500).json({
error: e.message
})
}
} }
} }

View File

@ -47,6 +47,11 @@ module.exports.routes = {
action: 'publish' action: 'publish'
}, },
'GET /api/books': {
controller: 'books',
action: 'list'
},
// ╦ ╦╔═╗╔╗ ╦ ╦╔═╗╔═╗╦╔═╔═╗ // ╦ ╦╔═╗╔╗ ╦ ╦╔═╗╔═╗╦╔═╔═╗
// ║║║║╣ ╠╩╗╠═╣║ ║║ ║╠╩╗╚═╗ // ║║║║╣ ╠╩╗╠═╣║ ║║ ║╠╩╗╚═╗