updated back end to send availability and message
This commit is contained in:
parent
c439e3d971
commit
fac77b2524
3 changed files with 21 additions and 8 deletions
|
@ -18,10 +18,7 @@ const claimAvailability = (name) => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.length >= 1) {
|
return (result.length <= 0);
|
||||||
throw new Error('That claim is already in use');
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -11,8 +11,18 @@ const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
|
||||||
const claimAvailability = ({ ip, originalUrl, params: { name } }, res) => {
|
const claimAvailability = ({ ip, originalUrl, params: { name } }, res) => {
|
||||||
const gaStartTime = Date.now();
|
const gaStartTime = Date.now();
|
||||||
checkClaimAvailability(name)
|
checkClaimAvailability(name)
|
||||||
.then(result => {
|
.then(isAvailable => {
|
||||||
res.status(200).json(result);
|
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());
|
sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now());
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -14,9 +14,15 @@ const claimData = ({ ip, originalUrl, body, params }, res) => {
|
||||||
db.Claim.resolveClaim(claimName, claimId)
|
db.Claim.resolveClaim(claimName, claimId)
|
||||||
.then(claimInfo => {
|
.then(claimInfo => {
|
||||||
if (!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 => {
|
.catch(error => {
|
||||||
handleErrorResponse(originalUrl, ip, error, res);
|
handleErrorResponse(originalUrl, ip, error, res);
|
||||||
|
|
Loading…
Reference in a new issue