2018-04-29 12:17:23 -07:00
|
|
|
const logger = require('winston');
|
|
|
|
|
2018-09-02 18:48:35 -05:00
|
|
|
const db = require('../../models');
|
2018-12-14 11:42:37 -06:00
|
|
|
const chainquery = require('chainquery').default;
|
2018-04-29 12:17:23 -07:00
|
|
|
|
2018-10-08 19:02:05 -05:00
|
|
|
const getClaimIdByChannel = async (channelName, channelClaimId, claimName) => {
|
2018-08-08 11:39:35 -07:00
|
|
|
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${claimName})`);
|
2018-10-08 19:02:05 -05:00
|
|
|
|
2018-10-30 16:07:36 -05:00
|
|
|
let channelId = await chainquery.claim.queries.getLongClaimId(channelName, channelClaimId);
|
2018-10-08 19:02:05 -05:00
|
|
|
|
2018-11-10 19:11:12 -05:00
|
|
|
if (channelId === null) {
|
2018-10-08 19:02:05 -05:00
|
|
|
channelId = await db.Certificate.getLongChannelId(channelName, channelClaimId);
|
|
|
|
}
|
|
|
|
|
2018-10-09 13:10:06 -05:00
|
|
|
let claimId = await chainquery.claim.queries.getClaimIdByLongChannelId(channelId, claimName);
|
2018-10-08 19:02:05 -05:00
|
|
|
|
2018-11-10 19:11:12 -05:00
|
|
|
if (claimId === null) {
|
2018-10-17 12:10:30 -04:00
|
|
|
claimId = db.Claim.getClaimIdByLongChannelId(channelId, claimName);
|
2018-10-08 19:02:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return claimId;
|
2018-04-29 12:17:23 -07:00
|
|
|
};
|
|
|
|
|
2018-10-08 19:02:05 -05:00
|
|
|
const getClaimId = async (channelName, channelClaimId, name, claimId) => {
|
2018-08-08 11:39:35 -07:00
|
|
|
logger.debug(`getClaimId: ${channelName}, ${channelClaimId}, ${name}, ${claimId})`);
|
2018-04-29 12:17:23 -07:00
|
|
|
if (channelName) {
|
2018-11-10 19:32:43 -05:00
|
|
|
return getClaimIdByChannel(channelName, channelClaimId, name);
|
2018-04-29 12:17:23 -07:00
|
|
|
} else {
|
2018-10-08 19:02:05 -05:00
|
|
|
let claimIdResult = await chainquery.claim.queries.getLongClaimId(name, claimId);
|
|
|
|
|
2018-11-10 19:11:12 -05:00
|
|
|
if (!claimIdResult) {
|
2018-10-08 19:02:05 -05:00
|
|
|
claimIdResult = await db.Claim.getLongClaimId(name, claimId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return claimIdResult;
|
2018-04-29 12:17:23 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = getClaimId;
|