spee.ch/server/routes/api/claimData.js
2018-03-29 11:24:52 -07:00

26 lines
699 B
JavaScript

const { handleErrorResponse } = require('helpers/errorHandlers.js');
const db = require('models');
/*
route to return data for a claim
*/
const claimData = ({ ip, originalUrl, body, params }, res) => {
const claimName = params.claimName;
let claimId = params.claimId;
if (claimId === 'none') claimId = null;
db.Claim.resolveClaim(claimName, claimId)
.then(claimInfo => {
if (!claimInfo) {
return res.status(404).json({success: false, message: 'No claim could be found'});
}
res.status(200).json({success: true, data: claimInfo});
})
.catch(error => {
handleErrorResponse(originalUrl, ip, error, res);
});
};
module.exports = claimData;