Sequelize queries #234
3 changed files with 25 additions and 22 deletions
|
@ -168,7 +168,7 @@ module.exports = {
|
||||||
return NO_CHANNEL;
|
return NO_CHANNEL;
|
||||||
}
|
}
|
||||||
shortChannelId = result;
|
shortChannelId = result;
|
||||||
return db.getAllChannelClaims(longChannelId);
|
return db.Claim.getAllChannelClaims(longChannelId);
|
||||||
})
|
})
|
||||||
.then(result => { // 4. add extra data not available from Claim table
|
.then(result => { // 4. add extra data not available from Claim table
|
||||||
if (result === NO_CHANNEL) {
|
if (result === NO_CHANNEL) {
|
||||||
|
|
|
@ -181,11 +181,11 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
|
||||||
};
|
};
|
||||||
|
|
||||||
Claim.getShortClaimIdFromLongClaimId = function (claimId, claimName) {
|
Claim.getShortClaimIdFromLongClaimId = function (claimId, claimName) {
|
||||||
|
logger.debug(`Claim.getShortClaimIdFromLongClaimId for ${claimId}#${claimId}`);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
logger.debug(`finding short claim id for ${claimId}#${claimId}`);
|
|
||||||
this
|
this
|
||||||
.findAll({
|
.findAll({
|
||||||
where: {name: claimName},
|
where: { name: claimName },
|
||||||
order: [['height', 'ASC']],
|
order: [['height', 'ASC']],
|
||||||
})
|
})
|
||||||
.then(result => {
|
.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;
|
return Claim;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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) => {
|
db['getLongClaimId'] = (claimName, claimId) => {
|
||||||
logger.debug(`getLongClaimId(${claimName}, ${claimId})`);
|
logger.debug(`getLongClaimId(${claimName}, ${claimId})`);
|
||||||
if (claimId && (claimId.length === 40)) { // if a full claim id is provided
|
if (claimId && (claimId.length === 40)) { // if a full claim id is provided
|
||||||
|
|
Loading…
Reference in a new issue