fixed the bug in returnShortId for missing claim Ids
This commit is contained in:
parent
7d518cf6b5
commit
cf7ffeb783
2 changed files with 5 additions and 6 deletions
|
@ -1,23 +1,23 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
returnShortId: function (result, longId) {
|
returnShortId: function (claimsArray, longId) {
|
||||||
let claimIndex;
|
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;
|
let shortIdLength = 0;
|
||||||
// find the index of this claim id
|
// find the index of this claim id
|
||||||
claimIndex = result.findIndex(element => {
|
claimIndex = claimsArray.findIndex(element => {
|
||||||
return element.claimId === longId;
|
return element.claimId === longId;
|
||||||
});
|
});
|
||||||
if (claimIndex < 0) {
|
if (claimIndex < 0) {
|
||||||
throw new Error('claim id not found in claims list');
|
throw new Error('claim id not found in claims list');
|
||||||
}
|
}
|
||||||
// get an array of all claims with lower height
|
// 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.
|
// remove certificates with the same prefixes until none are left.
|
||||||
while (possibleMatches.length > 0) {
|
while (possibleMatches.length > 0) {
|
||||||
shortIdLength += 1;
|
shortIdLength += 1;
|
||||||
shortId = longId.substring(0, shortIdLength);
|
shortId = longId.substring(0, shortIdLength);
|
||||||
possibleMatches = possibleMatches.filter(element => {
|
possibleMatches = possibleMatches.filter(element => {
|
||||||
return (element.claimId.substring(0, shortIdLength) === shortId);
|
return (element.claimId && (element.claimId.substring(0, shortIdLength) === shortId));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return shortId;
|
return shortId;
|
||||||
|
|
|
@ -280,7 +280,6 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
||||||
where: {name, claimId},
|
where: {name, claimId},
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
// logger.debug('validateLongClaimId result:', result.dataValues);
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return resolve(NO_CLAIM);
|
return resolve(NO_CLAIM);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue