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-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'
|
|
|
|
const search = new SearchController(searchTerm, language);
|
2019-09-07 01:20:27 +02:00
|
|
|
|
2019-09-09 22:19:22 +02:00
|
|
|
return await search.searchInventaire();
|
2019-09-07 01:20:27 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = routes
|