spee.ch/server/routes/api/channelData.js

31 lines
860 B
JavaScript
Raw Normal View History

2018-03-29 18:26:55 +02:00
const { getChannelData } = require('controllers/serveController.js');
2018-03-29 02:35:41 +02:00
const { handleErrorResponse } = require('helpers/errorHandlers.js');
const NO_CHANNEL = 'NO_CHANNEL';
/*
route to get data for a channel
*/
const channelData = () => {
return ({ ip, originalUrl, body, params }, res) => {
const channelName = params.channelName;
let channelClaimId = params.channelClaimId;
if (channelClaimId === 'none') channelClaimId = null;
getChannelData(channelName, channelClaimId, 0)
.then(data => {
if (data === NO_CHANNEL) {
return res.status(404).json({success: false, message: 'No matching channel was found'});
}
res.status(200).json({success: true, data});
})
.catch(error => {
handleErrorResponse(originalUrl, ip, error, res);
});
};
};
module.exports = channelData;