spee.ch/server/controllers/api/channel/claims/getChannelClaims.js
2018-11-25 23:54:23 -05:00

26 lines
968 B
JavaScript

const db = require('../../../../models');
const chainquery = require('chainquery');
const getClaimData = require('server/utils/getClaimData');
const { returnPaginatedChannelClaims } = require('./channelPagination.js');
const getChannelClaims = async (channelName, channelShortId, page) => {
const channelId = await chainquery.claim.queries.getLongClaimId(channelName, channelShortId);
const params = { content_type: [
'image/jpeg',
'image/jpg',
'image/png',
'image/gif',
'video/mp4',
] };
let channelClaims;
if (channelId) {
channelClaims = await chainquery.claim.queries.getAllChannelClaims(channelId, params);
}
const processingChannelClaims = channelClaims ? channelClaims.map((claim) => getClaimData(claim)) : [];
const processedChannelClaims = await Promise.all(processingChannelClaims);
return returnPaginatedChannelClaims(channelName, channelId, processedChannelClaims, page);
};
module.exports = getChannelClaims;