2018-04-27 18:54:36 +02:00
|
|
|
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
|
|
|
|
const getChannelClaims = require('./getChannelClaims.js');
|
2018-06-14 22:06:19 +02:00
|
|
|
const logger = require('winston');
|
2018-03-29 02:35:41 +02:00
|
|
|
|
|
|
|
const NO_CHANNEL = 'NO_CHANNEL';
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
route to get all claims for channel
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-03-29 20:24:52 +02:00
|
|
|
const channelClaims = ({ ip, originalUrl, body, params }, res) => {
|
|
|
|
const channelName = params.channelName;
|
|
|
|
let channelClaimId = params.channelClaimId;
|
|
|
|
if (channelClaimId === 'none') channelClaimId = null;
|
|
|
|
const page = params.page;
|
|
|
|
getChannelClaims(channelName, channelClaimId, page)
|
|
|
|
.then(data => {
|
|
|
|
res.status(200).json({success: true, data});
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2018-05-01 00:58:04 +02:00
|
|
|
if (error === NO_CHANNEL) {
|
|
|
|
return res.status(404).json({
|
|
|
|
success: false,
|
|
|
|
message: 'No matching channel was found',
|
|
|
|
});
|
|
|
|
}
|
2018-03-29 20:24:52 +02:00
|
|
|
handleErrorResponse(originalUrl, ip, error, res);
|
|
|
|
});
|
2018-03-29 02:35:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = channelClaims;
|