spee.ch/server/routes/api/claimData.js
2018-03-28 17:35:41 -07:00

27 lines
719 B
JavaScript

const { handleErrorResponse } = require('helpers/errorHandlers.js');
/*
route to return data for a claim
*/
const claimData = (db) => {
return ({ 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;