2019-09-06 17:20:27 -06:00
|
|
|
const SearchController = require('../controllers/search');
|
|
|
|
|
|
|
|
async function routes(fastify, options) {
|
2019-09-09 14:19:22 -06:00
|
|
|
fastify.get('/api/search', async (request, reply) => {
|
2019-09-06 17:20:27 -06:00
|
|
|
const searchTerm = typeof request.query.for !== 'undefined' ? request.query.for.trim() : '';
|
2019-09-09 14:19:22 -06:00
|
|
|
const language = typeof request.query.lang !== 'undefined' ? request.query.lang.trim().split('-')[0] : undefined; // Get base language in cases like 'en-US'
|
2019-09-11 11:05:47 -06:00
|
|
|
const search = new SearchController(fastify.siteConfig.inventaireDomain, searchTerm, language);
|
2019-09-06 17:20:27 -06:00
|
|
|
|
2019-09-16 12:07:45 -06:00
|
|
|
return await search.quickSearchInventaire();
|
2019-09-06 17:20:27 -06:00
|
|
|
});
|
2019-09-11 10:31:50 -06: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'
|
2019-09-11 11:05:47 -06:00
|
|
|
const search = new SearchController(fastify.siteConfig.inventaireDomain, null, language);
|
2019-09-11 10:31:50 -06:00
|
|
|
|
|
|
|
return await search.getInventaireCovers(inventaireURI);
|
|
|
|
});
|
2019-09-06 17:20:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = routes
|