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

29 lines
992 B
JavaScript
Raw Normal View History

const db = require('../../../../models');
2018-04-27 18:54:36 +02:00
const { returnPaginatedChannelClaims } = require('./channelPagination.js');
const getChannelClaims = (channelName, channelClaimId, page) => {
return new Promise((resolve, reject) => {
let longChannelClaimId;
2018-04-27 18:54:36 +02:00
// 1. get the long channel Id (make sure channel exists)
db.Certificate
.getLongChannelId(channelName, channelClaimId)
.then(result => {
longChannelClaimId = result;
return db
.Claim
.getAllChannelClaims(longChannelClaimId);
2018-04-27 18:54:36 +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;