spee.ch/server/controllers/api/claim/data/index.js

41 lines
1 KiB
JavaScript
Raw Normal View History

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
*/
const claimData = async ({ ip, originalUrl, body, params }, res) => {
2018-03-29 20:24:52 +02:00
const claimName = params.claimName;
let claimId = params.claimId;
if (claimId === 'none') claimId = null;
try {
let resolvedClaim = await chainquery.claim.queries.resolveClaim(claimName, claimId).catch(() => {});
if(!resolvedClaim) {
resolvedClaim = await db.Claim.resolveClaim(claimName, claimId);
}
if (!resolvedClaim) {
return res.status(404).json({
success: false,
message: 'No claim could be found',
});
}
res.status(200).json({
success: true,
data : await getClaimData(resolvedClaim),
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;