spee.ch/server/controllers/api/special/claims/index.js

43 lines
1 KiB
JavaScript
Raw Normal View History

2018-10-24 10:43:30 +02:00
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const db = require('server/models');
const getClaimData = require('server/utils/getClaimData');
/*
route to get all claims for special
*/
const channelClaims = async ({ ip, originalUrl, body, params }, res) => {
const {
name,
page,
} = params;
2018-11-11 01:11:12 +01:00
if (name === 'trending') {
2018-10-24 10:43:30 +02:00
const result = await db.Trending.getTrendingClaims();
const claims = await Promise.all(result.map((claim) => getClaimData(claim)));
return res.status(200).json({
success: true,
2018-11-11 01:11:12 +01:00
data : {
channelName : name,
2018-10-24 10:43:30 +02:00
claims,
longChannelClaimId: name,
2018-11-11 01:11:12 +01:00
currentPage : 1,
nextPage : null,
previousPage : null,
totalPages : 1,
totalResults : claims.length,
},
2018-10-24 10:43:30 +02:00
});
}
res.status(404).json({
success: false,
message: 'Feature endpoint not found',
});
handleErrorResponse(originalUrl, ip, 'Feature endpoint not found', res);
};
module.exports = channelClaims;