2017-06-19 18:37:35 +02:00
|
|
|
const errorHandlers = require('../helpers/libraries/errorHandlers.js');
|
|
|
|
const showController = require('../controllers/showController.js');
|
2017-06-13 20:00:50 +02:00
|
|
|
|
2017-06-17 22:51:30 +02:00
|
|
|
module.exports = (app, ua, googleAnalyticsId) => {
|
|
|
|
// route to fetch all free public claims
|
|
|
|
app.get('/:name/all', ({ params }, res) => {
|
2017-06-19 18:37:35 +02:00
|
|
|
console.log(`>> GET request on /${params.name}/all`);
|
2017-06-17 22:51:30 +02:00
|
|
|
// google analytics
|
2017-06-19 18:37:35 +02:00
|
|
|
ua(googleAnalyticsId, { https: true }).event('Show Routes', '/name/all', `${params.name}/all`).send();
|
2017-06-17 22:51:30 +02:00
|
|
|
// fetch all free public claims
|
|
|
|
showController
|
|
|
|
.getAllClaims(params.name)
|
|
|
|
.then(orderedFreePublicClaims => {
|
2017-06-19 18:37:35 +02:00
|
|
|
console.log('/:name/all success.');
|
|
|
|
res.status(200).render('allClaims', { claims: orderedFreePublicClaims });
|
2017-06-17 22:51:30 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-06-19 18:37:35 +02:00
|
|
|
console.log('/:name/all error:', error);
|
|
|
|
errorHandlers.handleRequestError(error, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|