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

40 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

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