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

33 lines
777 B
JavaScript
Raw Normal View History

2018-04-27 18:54:36 +02:00
const { handleErrorResponse } = require('../../../utils/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',
});
2018-03-29 20:24:52 +02:00
}
res.status(200).json({
success: true,
data : claimInfo,
});
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;