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