2018-04-27 18:54:36 +02:00
|
|
|
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
|
2018-09-26 03:20:59 +02:00
|
|
|
const getClaimData = require('server/utils/getClaimData');
|
|
|
|
const chainquery = require('chainquery');
|
2018-04-27 18:54:36 +02:00
|
|
|
const db = require('../../../../models');
|
2018-03-29 02:35:41 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
route to return data for a claim
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-03-29 20:24:52 +02:00
|
|
|
const claimData = ({ ip, originalUrl, body, params }, res) => {
|
|
|
|
const claimName = params.claimName;
|
|
|
|
let claimId = params.claimId;
|
|
|
|
if (claimId === 'none') claimId = null;
|
2018-10-09 02:02:05 +02:00
|
|
|
chainquery.claim.queries.resolveClaim(claimName, claimId).catch(() => {})
|
2018-09-26 03:20:59 +02:00
|
|
|
.then(claimInfo => {
|
|
|
|
if (!claimInfo) {
|
|
|
|
// Not found remote, try local
|
|
|
|
return db.Claim.resolveClaim(claimName, claimId)
|
|
|
|
}
|
|
|
|
return claimInfo
|
|
|
|
})
|
2018-03-29 20:24:52 +02:00
|
|
|
.then(claimInfo => {
|
|
|
|
if (!claimInfo) {
|
2018-05-04 00:22:29 +02:00
|
|
|
return res.status(404).json({
|
|
|
|
success: false,
|
2018-08-01 01:43:08 +02:00
|
|
|
message: 'No claim could be found',
|
2018-05-04 00:22:29 +02:00
|
|
|
});
|
2018-03-29 20:24:52 +02:00
|
|
|
}
|
2018-10-09 02:02:05 +02:00
|
|
|
|
2018-05-04 00:22:29 +02:00
|
|
|
res.status(200).json({
|
|
|
|
success: true,
|
2018-09-26 03:20:59 +02:00
|
|
|
data : getClaimData(claimInfo),
|
2018-05-04 00:22:29 +02:00
|
|
|
});
|
2018-03-29 20:24:52 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
handleErrorResponse(originalUrl, ip, error, res);
|
|
|
|
});
|
2018-03-29 02:35:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = claimData;
|