diff --git a/server/controllers/api/claim/availability/checkClaimAvailability.js b/server/controllers/api/claim/availability/checkClaimAvailability.js index c4f4501a..9440fa86 100644 --- a/server/controllers/api/claim/availability/checkClaimAvailability.js +++ b/server/controllers/api/claim/availability/checkClaimAvailability.js @@ -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; diff --git a/server/controllers/api/claim/availability/index.js b/server/controllers/api/claim/availability/index.js index 1583cb26..210e6033 100644 --- a/server/controllers/api/claim/availability/index.js +++ b/server/controllers/api/claim/availability/index.js @@ -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 => { diff --git a/server/controllers/api/claim/data/index.js b/server/controllers/api/claim/data/index.js index 49361d71..250e9849 100644 --- a/server/controllers/api/claim/data/index.js +++ b/server/controllers/api/claim/data/index.js @@ -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);