updated getClaimIdByLongChannelId
This commit is contained in:
parent
409a9346de
commit
c6878eb0a3
3 changed files with 27 additions and 38 deletions
|
@ -136,7 +136,7 @@ module.exports = {
|
|||
resolve(NO_CHANNEL);
|
||||
return;
|
||||
}
|
||||
return db.getClaimIdByLongChannelId(result, claimName);
|
||||
return db.Claim.getClaimIdByLongChannelId(result, claimName);
|
||||
})
|
||||
.then(result => { // 3. get the asset using the long claim id
|
||||
logger.debug('asset claim id =', result);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const logger = require('winston');
|
||||
const NO_CLAIM = 'NO_CLAIM';
|
||||
|
||||
function sortResult (result, longId) {
|
||||
let claimIndex;
|
||||
|
@ -224,5 +225,30 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
|
|||
});
|
||||
};
|
||||
|
||||
Claim.getClaimIdByLongChannelId = function (channelId, claimName) {
|
||||
logger.debug(`finding claim id for claim ${claimName} from channel ${channelId}`);
|
||||
return new Promise((resolve, reject) => {
|
||||
Claim
|
||||
.findAll({
|
||||
where: { name: claimName, certificateId: channelId },
|
||||
order: [['id', 'ASC']],
|
||||
})
|
||||
.then(result => {
|
||||
switch (result.length) {
|
||||
case 0:
|
||||
return resolve(NO_CLAIM);
|
||||
case 1:
|
||||
return resolve(result[0].claimId);
|
||||
default:
|
||||
logger.error(`${result.length} records found for ${claimName} from channel ${claimName}`);
|
||||
return resolve(result[0].claimId);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return Claim;
|
||||
};
|
||||
|
|
|
@ -152,24 +152,6 @@ db['getRecentClaims'] = () => {
|
|||
return db.sequelize.query(`SELECT * FROM File WHERE nsfw != 1 AND trendingEligible = 1 ORDER BY createdAt DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT });
|
||||
};
|
||||
|
||||
db['getAllFreeClaims'] = (name) => {
|
||||
return new Promise((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 })
|
||||
.then(result => {
|
||||
switch (result.length) {
|
||||
case 0:
|
||||
return resolve(null);
|
||||
default:
|
||||
return resolve(result);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
db['resolveClaim'] = (name, claimId) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
db
|
||||
|
@ -190,25 +172,6 @@ db['resolveClaim'] = (name, claimId) => {
|
|||
});
|
||||
};
|
||||
|
||||
db['getClaimIdByLongChannelId'] = (channelId, claimName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
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) {
|
||||
case 0:
|
||||
return resolve(NO_CLAIM);
|
||||
default:
|
||||
return resolve(result[0].claimId);
|
||||
}
|
||||
})
|
||||
.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
|
||||
|
|
Loading…
Reference in a new issue