spee.ch/server/utils/fetchClaimData.js

26 lines
685 B
JavaScript
Raw Normal View History

const chainquery = require('chainquery');
const db = require('server/models');
const fetchClaimData = async (params) => {
2018-10-28 23:51:51 +01:00
let { claimId, claimName: name } = params;
if (claimId === 'none') claimId = null;
const [cq, local] = await Promise.all([
chainquery.claim.queries.resolveClaim(name, claimId).then(res => res.dataValues).catch(() => {}),
db.Claim.resolveClaim(name, claimId).catch(() => {}),
]);
2018-11-09 15:49:03 +01:00
if (!cq && !local) {
return null;
}
if (cq && cq.name === name && !local) {
return cq;
}
if (local && local.name === name && !cq) {
return local;
}
return local.updatedAt > cq.modified_at ? local : cq;
};
module.exports = fetchClaimData;