move approved channel check to its own method

This commit is contained in:
Travis Eden 2018-09-24 09:22:28 -04:00
parent 69f82d814b
commit 6d6bb40fe6

View file

@ -356,7 +356,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
} }
}; };
Claim.resolveClaim = function (name, claimId) { Claim.fetchClaim = function (name, claimId) {
logger.debug(`Claim.resolveClaim: ${name} ${claimId}`); logger.debug(`Claim.resolveClaim: ${name} ${claimId}`);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this this
@ -364,9 +364,6 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
where: { name, claimId }, where: { name, claimId },
}) })
.then(claimArray => { .then(claimArray => {
if (serveOnlyApproved && !isApprovedChannel({ longId: claimArray[0].dataValues.certificateId }, approvedChannels)) {
reject('This content is unavailable');
}
switch (claimArray.length) { switch (claimArray.length) {
case 0: case 0:
return resolve(null); return resolve(null);
@ -383,6 +380,23 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
}); });
}; };
Claim.resolveClaim = function (name, claimId) {
return new Promise((resolve, reject) => {
this
.fetchClaim(name, claimId)
.then(claim => {
logger.info('resolveClaim claims:', claim);
if (serveOnlyApproved && !isApprovedChannel({ longId: claim.certificateId }, approvedChannels)) {
throw new Error('This content is unavailable');
}
return resolve(claim);
})
.catch(error => {
reject(error);
});
});
};
Claim.getOutpoint = function (name, claimId) { Claim.getOutpoint = function (name, claimId) {
logger.debug(`finding outpoint for ${name}#${claimId}`); logger.debug(`finding outpoint for ${name}#${claimId}`);
return this return this