.sequelize.query(`SELECT claimId FROM Claim WHERE name = '${name}' AND claimId LIKE '${shortId}%' ORDER BY height ASC LIMIT 1;`,{type:db.sequelize.QueryTypes.SELECT})
.then(result=>{
switch(result.length){
case0:
returnreject(newError('That is an invalid Short Claim Id'));
default:// note results must be sorted
returnresolve(result[0].claimId);
}
})
.catch(error=>{
reject(error);
});
});
}
functiongetTopFreeClaimIdByClaimName(name){
returnnewPromise((resolve,reject)=>{
db
.sequelize.query(`SELECT claimId FROM Claim WHERE name = '${name}' ORDER BY amount DESC, height ASC LIMIT 1`,{type:db.sequelize.QueryTypes.SELECT})
.sequelize.query(`SELECT claimId, height FROM Certificate WHERE name = '${channelName}' AND claimId LIKE '${channelId}%' ORDER BY height ASC LIMIT 1;`,{type:db.sequelize.QueryTypes.SELECT})
.then(result=>{
switch(result.length){
case0:
thrownewError('That is an invalid Short Channel Id');
.sequelize.query(`SELECT claimId, amount, height FROM Certificate WHERE name = '${channelName}' ORDER BY amount DESC, height ASC LIMIT 1;`,{type:db.sequelize.QueryTypes.SELECT})
returndb.sequelize.query(`SELECT COUNT(*), File.* FROM Request LEFT JOIN File ON Request.FileId = File.id WHERE FileId IS NOT NULL AND nsfw != 1 AND trendingEligible = 1 AND Request.createdAt > "${startDate}" GROUP BY FileId ORDER BY COUNT(*) DESC LIMIT 25;`,{type:db.sequelize.QueryTypes.SELECT});
};
db['getRecentClaims']=()=>{
returndb.sequelize.query(`SELECT * FROM File WHERE nsfw != 1 AND trendingEligible = 1 ORDER BY createdAt DESC LIMIT 25;`,{type:db.sequelize.QueryTypes.SELECT});
.sequelize.query(`SELECT claimId, height FROM Certificate WHERE name = '${channelName}' ORDER BY height;`,{type:db.sequelize.QueryTypes.SELECT})
.then(result=>{
switch(result.length){
case0:
returnreject(newError('That is an invalid channel name'));
default:
returnresolve(sortResult(result,longChannelId));
}
})
.catch(error=>{
reject(error);
});
});
};
db['getAllFreeClaims']=(name)=>{
returnnewPromise((resolve,reject)=>{
db
.sequelize.query(`SELECT name, claimId, outpoint, height, address FROM Claim WHERE name = '${name}' ORDER BY amount DESC, height ASC`,{type:db.sequelize.QueryTypes.SELECT})
.sequelize.query(`SELECT name, claimId, outpoint, height, address, title, description, thumbnail FROM Claim WHERE name = '${name}' AND claimId = '${claimId}'`,{type:db.sequelize.QueryTypes.SELECT})
logger.debug(`finding claim id for claim "${claimName}" from channel "${channelId}"`);
db
.sequelize.query(`SELECT claimId FROM Claim WHERE name = '${claimName}' AND certificateId = '${channelId}' LIMIT 1;`,{type:db.sequelize.QueryTypes.SELECT})
.then(result=>{
switch(result.length){
case0:
returnreject(newError('There is no such claim for that channel'));
default:
returnresolve(result[0].claimId);
}
})
.catch(error=>{
reject(error);
});
});
};
db['getAllChannelClaims']=(channelId)=>{
returnnewPromise((resolve,reject)=>{
logger.debug(`finding all claims in channel "${channelId}"`);