spee.ch/routes/show-routes.js

24 lines
984 B
JavaScript
Raw Normal View History

const errorHandlers = require('../helpers/libraries/errorHandlers.js');
const showController = require('../controllers/showController.js');
const logger = require('winston');
2017-06-13 20:00:50 +02:00
module.exports = (app, ua, googleAnalyticsId) => {
// route to fetch all free public claims
app.get('/:name/all', ({ originalUrl, params }, res) => {
logger.debug(`Get request on ${originalUrl}`);
// google analytics
ua(googleAnalyticsId, { https: true }).event('Show Routes', '/name/all', `${params.name}/all`).send();
// fetch all free public claims
showController
.getAllClaims(params.name)
.then(orderedFreePublicClaims => {
2017-06-20 00:25:14 +02:00
logger.debug(`${originalUrl} getAllClaims returned successfully.`);
res.status(200).render('allClaims', { claims: orderedFreePublicClaims });
})
.catch(error => {
2017-06-20 00:25:14 +02:00
logger.error(`${originalUrl} getAllClaims returned an error.`, error);
errorHandlers.handleRequestError(error, res);
});
});
};