updated back end to send availability and message

This commit is contained in:
bill bittner 2018-05-03 15:22:29 -07:00
parent c439e3d971
commit fac77b2524
3 changed files with 21 additions and 8 deletions

View file

@ -18,10 +18,7 @@ const claimAvailability = (name) => {
},
})
.then(result => {
if (result.length >= 1) {
throw new Error('That claim is already in use');
}
return name;
return (result.length <= 0);
})
.catch(error => {
throw error;

View file

@ -11,8 +11,18 @@ const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const claimAvailability = ({ ip, originalUrl, params: { name } }, res) => {
const gaStartTime = Date.now();
checkClaimAvailability(name)
.then(result => {
res.status(200).json(result);
.then(isAvailable => {
let responseObject = {
success: true,
data: isAvailable,
};
if (isAvailable) {
responseObject['message'] = `That claim name is available`
} else {
responseObject['message'] = `That name is already in use`
}
console.log('response object', responseObject);
res.status(200).json(responseObject);
sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now());
})
.catch(error => {

View file

@ -14,9 +14,15 @@ const claimData = ({ ip, originalUrl, body, params }, res) => {
db.Claim.resolveClaim(claimName, claimId)
.then(claimInfo => {
if (!claimInfo) {
return res.status(404).json({success: false, message: 'No claim could be found'});
return res.status(404).json({
success: false,
message: 'No claim could be found'
});
}
res.status(200).json({success: true, data: claimInfo});
res.status(200).json({
success: true,
data: claimInfo
});
})
.catch(error => {
handleErrorResponse(originalUrl, ip, error, res);