From 8b808b2c109ec5d623b90b8578c4b3da1ebfdca8 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 3 May 2018 15:47:58 -0700 Subject: [PATCH] updated channel availability route --- .../availability/checkChannelAvailability.js | 9 ++++----- .../controllers/api/channel/availability/index.js | 15 ++++++++++++--- .../claim/availability/checkClaimAvailability.js | 2 +- .../controllers/api/claim/availability/index.js | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/server/controllers/api/channel/availability/checkChannelAvailability.js b/server/controllers/api/channel/availability/checkChannelAvailability.js index 3c5d78b5..3261c63f 100644 --- a/server/controllers/api/channel/availability/checkChannelAvailability.js +++ b/server/controllers/api/channel/availability/checkChannelAvailability.js @@ -3,13 +3,12 @@ const db = require('../../../../models'); const checkChannelAvailability = (name) => { return db.Channel .findAll({ - where: { channelName: name }, + where: { + channelName: name, + }, }) .then(result => { - if (result.length >= 1) { - throw new Error('That channel has already been claimed'); - } - return name; + return (result.length <= 0); }) .catch(error => { throw error; diff --git a/server/controllers/api/channel/availability/index.js b/server/controllers/api/channel/availability/index.js index ae2a3807..e3b29ccb 100644 --- a/server/controllers/api/channel/availability/index.js +++ b/server/controllers/api/channel/availability/index.js @@ -11,9 +11,18 @@ const { handleErrorResponse } = require('../../../utils/errorHandlers.js'); const channelAvailability = ({ ip, originalUrl, params: { name } }, res) => { const gaStartTime = Date.now(); checkChannelAvailability(name) - .then(availableName => { - res.status(200).json(availableName); - sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now()); + .then(isAvailable => { + let responseObject = { + success: true, + data: isAvailable, + }; + if (isAvailable) { + responseObject['message'] = `That channel name is available` + } else { + responseObject['message'] = `That channel is already in use` + } + res.status(200).json(responseObject); + sendGATimingEvent('end-to-end', 'channel name availability', name, gaStartTime, Date.now()); }) .catch(error => { handleErrorResponse(originalUrl, ip, error, res); diff --git a/server/controllers/api/claim/availability/checkClaimAvailability.js b/server/controllers/api/claim/availability/checkClaimAvailability.js index 9440fa86..68c31056 100644 --- a/server/controllers/api/claim/availability/checkClaimAvailability.js +++ b/server/controllers/api/claim/availability/checkClaimAvailability.js @@ -1,4 +1,4 @@ -const db = require('../../../../models/index'); +const db = require('../../../../models'); const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('../../../../../config/siteConfig.js'); const Sequelize = require('sequelize'); const Op = Sequelize.Op; diff --git a/server/controllers/api/claim/availability/index.js b/server/controllers/api/claim/availability/index.js index 6c14c00a..da982e8f 100644 --- a/server/controllers/api/claim/availability/index.js +++ b/server/controllers/api/claim/availability/index.js @@ -19,7 +19,7 @@ const claimAvailability = ({ ip, originalUrl, params: { name } }, res) => { if (isAvailable) { responseObject['message'] = `That claim name is available` } else { - responseObject['message'] = `That name is already in use` + responseObject['message'] = `That url is already in use` } res.status(200).json(responseObject); sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now());