spee.ch/server/utils/fetchClaimData.js

26 lines
719 B
JavaScript
Raw Normal View History

2018-12-14 11:42:37 -06:00
const chainquery = require('chainquery').default;
const db = require('server/models');
2019-01-29 01:05:16 -05:00
const fetchClaimData = async params => {
2018-10-28 18:51:51 -04:00
let { claimId, claimName: name } = params;
if (claimId === 'none') claimId = null;
const [cq, local] = await Promise.all([
2019-01-29 01:05:16 -05:00
chainquery.claim.queries.resolveClaim(name, claimId).catch(() => {}),
db.Claim.resolveClaim(name, claimId).catch(() => {}),
]);
2019-01-29 01:05:16 -05:00
// Todo: don't use localdb to get post publish content
2018-11-09 09:49:03 -05: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;