fixed the bug in returnShortId for missing claim Ids

This commit is contained in:
bill bittner 2017-11-28 16:38:42 -08:00
parent 7d518cf6b5
commit cf7ffeb783
2 changed files with 5 additions and 6 deletions

View file

@ -1,23 +1,23 @@
module.exports = {
returnShortId: function (result, longId) {
returnShortId: function (claimsArray, longId) {
let claimIndex;
let shortId = longId.substring(0, 1); // default sort id is the first letter
let shortId = longId.substring(0, 1); // default short id is the first letter
let shortIdLength = 0;
// find the index of this claim id
claimIndex = result.findIndex(element => {
claimIndex = claimsArray.findIndex(element => {
return element.claimId === longId;
});
if (claimIndex < 0) {
throw new Error('claim id not found in claims list');
}
// get an array of all claims with lower height
let possibleMatches = result.slice(0, claimIndex);
let possibleMatches = claimsArray.slice(0, claimIndex);
// remove certificates with the same prefixes until none are left.
while (possibleMatches.length > 0) {
shortIdLength += 1;
shortId = longId.substring(0, shortIdLength);
possibleMatches = possibleMatches.filter(element => {
return (element.claimId.substring(0, shortIdLength) === shortId);
return (element.claimId && (element.claimId.substring(0, shortIdLength) === shortId));
});
}
return shortId;

View file

@ -280,7 +280,6 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
where: {name, claimId},
})
.then(result => {
// logger.debug('validateLongClaimId result:', result.dataValues);
if (!result) {
return resolve(NO_CLAIM);
};