2019-09-07 01:20:27 +02:00
|
|
|
const SearchController = require('../controllers/search');
|
|
|
|
|
|
|
|
async function routes(fastify, options) {
|
2019-09-09 22:19:22 +02:00
|
|
|
fastify.get('/api/search', async (request, reply) => {
|
2019-09-07 01:20:27 +02:00
|
|
|
const searchTerm = typeof request.query.for !== 'undefined' ? request.query.for.trim() : '';
|
2019-09-26 20:22:58 +02:00
|
|
|
const searchBy = typeof request.query.by !== 'undefined' ? request.query.by.trim() : 'title';
|
2019-09-09 22:19:22 +02:00
|
|
|
const language = typeof request.query.lang !== 'undefined' ? request.query.lang.trim().split('-')[0] : undefined; // Get base language in cases like 'en-US'
|
2020-02-06 21:55:17 +01:00
|
|
|
const source = typeof request.query.source !== 'undefined' ? request.query.source.trim() : undefined; // Get base language in cases like 'en-US'
|
2020-02-07 23:28:59 +01:00
|
|
|
const controller = new SearchController(fastify.models);
|
2019-09-07 01:20:27 +02:00
|
|
|
|
2020-02-07 23:28:59 +01:00
|
|
|
return await controller.search(searchTerm, { searchBy, source, language });
|
2019-09-07 01:20:27 +02:00
|
|
|
});
|
2019-09-11 18:31:50 +02:00
|
|
|
|
|
|
|
fastify.get('/api/search/cover', async (request, reply) => {
|
|
|
|
const inventaireURI = typeof request.query.uri !== 'undefined' ? request.query.uri.trim() : false;
|
|
|
|
const language = typeof request.query.lang !== 'undefined' ? request.query.lang.trim().split('-')[0] : undefined; // Get base language in cases like 'en-US'
|
2020-02-06 21:55:17 +01:00
|
|
|
const search = new SearchController(fastify.models, null, language);
|
2019-09-11 18:31:50 +02:00
|
|
|
|
|
|
|
return await search.getInventaireCovers(inventaireURI);
|
|
|
|
});
|
2019-09-07 01:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = routes
|