spee.ch/server/controllers/utils/getClaimId.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

const logger = require('winston');
const db = require('../../models');
2018-12-14 11:42:37 -06:00
const chainquery = require('chainquery').default;
const getClaimIdByChannel = async (channelName, channelClaimId, claimName) => {
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${claimName})`);
let channelId = await chainquery.claim.queries.getLongClaimId(channelName, channelClaimId);
2018-11-10 19:11:12 -05:00
if (channelId === null) {
channelId = await db.Certificate.getLongChannelId(channelName, channelClaimId);
}
let claimId = await chainquery.claim.queries.getClaimIdByLongChannelId(channelId, claimName);
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);
}
return claimId;
};
const getClaimId = async (channelName, channelClaimId, name, claimId) => {
logger.debug(`getClaimId: ${channelName}, ${channelClaimId}, ${name}, ${claimId})`);
if (channelName) {
2018-11-10 19:32:43 -05:00
return getClaimIdByChannel(channelName, channelClaimId, name);
} else {
let claimIdResult = await chainquery.claim.queries.getLongClaimId(name, claimId);
2018-11-10 19:11:12 -05:00
if (!claimIdResult) {
claimIdResult = await db.Claim.getLongClaimId(name, claimId);
}
return claimIdResult;
}
};
module.exports = getClaimId;