2018-04-29 21:17:23 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
|
2018-09-03 01:48:35 +02:00
|
|
|
const db = require('../../models');
|
2018-10-09 02:02:05 +02:00
|
|
|
const chainquery = require('chainquery');
|
2018-04-29 21:17:23 +02:00
|
|
|
|
2018-10-09 02:02:05 +02:00
|
|
|
const getClaimIdByChannel = async (channelName, channelClaimId, claimName) => {
|
2018-08-08 20:39:35 +02:00
|
|
|
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${claimName})`);
|
2018-10-09 02:02:05 +02:00
|
|
|
|
|
|
|
let channelId = await chainquery.claim.queries.getLongClaimIdFromShortClaimId(channelName, channelClaimId);
|
|
|
|
|
|
|
|
if(channelId === null) {
|
|
|
|
channelId = await db.Certificate.getLongChannelId(channelName, channelClaimId);
|
|
|
|
}
|
|
|
|
|
2018-10-09 20:10:06 +02:00
|
|
|
let claimId = await chainquery.claim.queries.getClaimIdByLongChannelId(channelId, claimName);
|
2018-10-09 02:02:05 +02:00
|
|
|
|
|
|
|
if(claimId === null) {
|
|
|
|
claimId = db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return claimId;
|
2018-04-29 21:17:23 +02:00
|
|
|
};
|
|
|
|
|
2018-10-09 02:02:05 +02:00
|
|
|
const getClaimId = async (channelName, channelClaimId, name, claimId) => {
|
2018-08-08 20:39:35 +02:00
|
|
|
logger.debug(`getClaimId: ${channelName}, ${channelClaimId}, ${name}, ${claimId})`);
|
2018-04-29 21:17:23 +02:00
|
|
|
if (channelName) {
|
2018-10-09 02:02:05 +02:00
|
|
|
return await getClaimIdByChannel(channelName, channelClaimId, name);
|
2018-04-29 21:17:23 +02:00
|
|
|
} else {
|
2018-10-09 02:02:05 +02:00
|
|
|
let claimIdResult = await chainquery.claim.queries.getLongClaimId(name, claimId);
|
|
|
|
|
2018-10-10 19:19:51 +02:00
|
|
|
if(!claimIdResult) {
|
2018-10-09 02:02:05 +02:00
|
|
|
claimIdResult = await db.Claim.getLongClaimId(name, claimId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return claimIdResult;
|
2018-04-29 21:17:23 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = getClaimId;
|