2018-04-27 18:54:36 +02:00
|
|
|
const db = require('../../../../models');
|
2018-05-01 00:58:04 +02:00
|
|
|
|
2018-04-27 18:54:36 +02:00
|
|
|
const { returnPaginatedChannelClaims } = require('./channelPagination.js');
|
|
|
|
|
|
|
|
const getChannelClaims = (channelName, channelClaimId, page) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2018-05-01 00:58:04 +02:00
|
|
|
let longChannelClaimId;
|
2018-04-27 18:54:36 +02:00
|
|
|
// 1. get the long channel Id (make sure channel exists)
|
2018-05-01 00:58:04 +02:00
|
|
|
db.Certificate
|
|
|
|
.getLongChannelId(channelName, channelClaimId)
|
|
|
|
.then(result => {
|
|
|
|
longChannelClaimId = result;
|
|
|
|
return db
|
|
|
|
.Claim
|
|
|
|
.getAllChannelClaims(longChannelClaimId);
|
2018-04-27 18:54:36 +02:00
|
|
|
})
|
2018-05-01 00:58:04 +02:00
|
|
|
.then(channelClaimsArray => {
|
2018-04-27 18:54:36 +02:00
|
|
|
// 3. format the data for the view, including pagination
|
|
|
|
let paginatedChannelViewData = returnPaginatedChannelClaims(channelName, longChannelClaimId, channelClaimsArray, page);
|
|
|
|
// 4. return all the channel information and contents
|
|
|
|
resolve(paginatedChannelViewData);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = getChannelClaims;
|