spee.ch/server/controllers/api/channel/data/getChannelData.js

33 lines
1 KiB
JavaScript
Raw Normal View History

2018-04-27 18:54:36 +02:00
const db = require('../../../../models');
const NO_CHANNEL = 'NO_CHANNEL';
const getChannelData = (channelName, channelClaimId, page) => {
return new Promise((resolve, reject) => {
// 1. get the long channel Id (make sure channel exists)
db.Certificate.getLongChannelId(channelName, channelClaimId)
.then(longChannelClaimId => {
if (!longChannelClaimId) {
return [null, null, null];
}
// 2. get the short ID and all claims for that channel
return Promise.all([longChannelClaimId, db.Certificate.getShortChannelIdFromLongChannelId(longChannelClaimId, channelName)]);
})
.then(([longChannelClaimId, shortChannelClaimId]) => {
if (!longChannelClaimId) {
return resolve(NO_CHANNEL);
}
// 3. return all the channel information
resolve({
channelName,
longChannelClaimId,
shortChannelClaimId,
});
})
.catch(error => {
reject(error);
});
});
};
module.exports = getChannelData;