updated Claim.getAllChannelClaims

This commit is contained in:
bill bittner 2017-10-31 11:54:33 -07:00
parent d6be5c4dbe
commit 409a9346de
3 changed files with 25 additions and 22 deletions

View file

@ -168,7 +168,7 @@ module.exports = {
return NO_CHANNEL;
}
shortChannelId = result;
return db.getAllChannelClaims(longChannelId);
return db.Claim.getAllChannelClaims(longChannelId);
})
.then(result => { // 4. add extra data not available from Claim table
if (result === NO_CHANNEL) {

View file

@ -181,11 +181,11 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
};
Claim.getShortClaimIdFromLongClaimId = function (claimId, claimName) {
logger.debug(`Claim.getShortClaimIdFromLongClaimId for ${claimId}#${claimId}`);
return new Promise((resolve, reject) => {
logger.debug(`finding short claim id for ${claimId}#${claimId}`);
this
.findAll({
where: {name: claimName},
where: { name: claimName },
order: [['height', 'ASC']],
})
.then(result => {
@ -202,5 +202,27 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
});
};
Claim.getAllChannelClaims = function (channelId) {
logger.debug(`Claim.getAllChannelClaims for ${channelId}`);
return new Promise((resolve, reject) => {
this
.findAll({
where: { certificateId: channelId },
order: [['height', 'ASC']],
})
.then(result => {
switch (result.length) {
case 0:
return resolve(null);
default:
return resolve(result);
}
})
.catch(error => {
reject(error);
});
});
};
return Claim;
};

View file

@ -209,25 +209,6 @@ db['getClaimIdByLongChannelId'] = (channelId, claimName) => {
});
};
db['getAllChannelClaims'] = (channelId) => {
return new Promise((resolve, reject) => {
logger.debug(`finding all claims in channel "${channelId}"`);
db
.sequelize.query(`SELECT name, claimId, outpoint, height, address, contentType, title, description, license, thumbnail FROM Claim WHERE certificateId = '${channelId}' ORDER BY height DESC;`, { type: db.sequelize.QueryTypes.SELECT })
.then(result => {
switch (result.length) {
case 0:
return resolve(null);
default:
return resolve(result);
}
})
.catch(error => {
reject(error);
});
});
};
db['getLongClaimId'] = (claimName, claimId) => {
logger.debug(`getLongClaimId(${claimName}, ${claimId})`);
if (claimId && (claimId.length === 40)) { // if a full claim id is provided