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-12-14 18:42:37 +01:00
|
|
|
const chainquery = require('chainquery').default;
|
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
|
|
|
|
2018-10-30 22:07:36 +01:00
|
|
|
let channelId = await chainquery.claim.queries.getLongClaimId(channelName, channelClaimId);
|
2018-10-09 02:02:05 +02:00
|
|
|
|
2018-11-11 01:11:12 +01:00
|
|
|
if (channelId === null) {
|
2018-10-09 02:02:05 +02:00
|
|
|
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
|
|
|
|
2018-11-11 01:11:12 +01:00
|
|
|
if (claimId === null) {
|
2018-10-17 18:10:30 +02:00
|
|
|
claimId = db.Claim.getClaimIdByLongChannelId(channelId, claimName);
|
2018-10-09 02:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-11-11 01:32:43 +01:00
|
|
|
return 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-11-11 01:11:12 +01: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;
|