From 6d6bb40fe65a756f841f663e36ed62a3fb0d30eb Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Mon, 24 Sep 2018 09:22:28 -0400 Subject: [PATCH] move approved channel check to its own method --- server/models/claim.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/server/models/claim.js b/server/models/claim.js index 0385cc02..63aa8b94 100644 --- a/server/models/claim.js +++ b/server/models/claim.js @@ -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}`); return new Promise((resolve, reject) => { this @@ -364,9 +364,6 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => { where: { name, claimId }, }) .then(claimArray => { - if (serveOnlyApproved && !isApprovedChannel({ longId: claimArray[0].dataValues.certificateId }, approvedChannels)) { - reject('This content is unavailable'); - } switch (claimArray.length) { case 0: 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) { logger.debug(`finding outpoint for ${name}#${claimId}`); return this