moved channel pagination logic to controller layer

This commit is contained in:
bill bittner 2017-12-07 12:23:21 -08:00
parent 46f9b3d8e1
commit 7791b4f685
3 changed files with 85 additions and 88 deletions

View file

@ -1,5 +1,6 @@
const db = require('../models');
const logger = require('winston');
const { returnPaginatedChannelViewData } = require('../helpers/channelPagination.js');
const NO_CHANNEL = 'NO_CHANNEL';
const NO_CLAIM = 'NO_CLAIM';
@ -52,7 +53,7 @@ module.exports = {
});
});
},
getChannelInfoAndClaims (channelName, channelClaimId) {
getChannelViewData (channelName, channelClaimId, query) {
return new Promise((resolve, reject) => {
// 1. get the long channel Id (make sure channel exists)
db.Certificate.getLongChannelId(channelName, channelClaimId)
@ -67,8 +68,10 @@ module.exports = {
if (!longChannelClaimId) {
return resolve(NO_CHANNEL);
}
// 3. return all the channel information and contents
resolve({ channelName, longChannelClaimId, shortChannelClaimId, claims: channelClaimsArray });
// 3. format the data for the view, including pagination
let paginatedChannelViewData = returnPaginatedChannelViewData(channelName, longChannelClaimId, shortChannelClaimId, channelClaimsArray, query);
// 4. return all the channel information and contents
resolve(paginatedChannelViewData);
})
.catch(error => {
reject(error);