spee.ch/server/controllers/api/channel/claims/getChannelClaims.js

33 lines
1.2 KiB
JavaScript
Raw Normal View History

const db = require('../../../../models');
2018-12-14 18:42:37 +01:00
const chainquery = require('chainquery').default;
2018-09-26 03:20:59 +02:00
const getClaimData = require('server/utils/getClaimData');
2018-04-27 18:54:36 +02:00
const { returnPaginatedChannelClaims } = require('./channelPagination.js');
2018-09-26 03:20:59 +02:00
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);
}
2018-09-26 03:20:59 +02:00
const split = channelClaims.reduce(
(acc, val) => val.dataValues.height === 0 ? { ...acc, zero: acc.zero.concat(val) } : { ...acc, nonzero: acc.nonzero.concat(val) },
{ zero: [], nonzero: [] }
);
channelClaims = split.zero.concat(split.nonzero);
const processingChannelClaims = channelClaims ? channelClaims.map((claim) => getClaimData(claim)) : [];
const processedChannelClaims = await Promise.all(processingChannelClaims);
2018-09-26 03:20:59 +02:00
return returnPaginatedChannelClaims(channelName, channelId, processedChannelClaims, page);
2018-04-27 18:54:36 +02:00
};
module.exports = getChannelClaims;