spee.ch/server/routes/api/claimData.js

27 lines
711 B
JavaScript
Raw Normal View History

const { handleErrorResponse } = require('../../helpers/errorHandlers.js');
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;
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);
});
2018-03-29 02:35:41 +02:00
};
module.exports = claimData;