updated channel availability route

This commit is contained in:
bill bittner 2018-05-03 15:47:58 -07:00
parent 3935fb1af0
commit 8b808b2c10
4 changed files with 18 additions and 10 deletions

View file

@ -3,13 +3,12 @@ const db = require('../../../../models');
const checkChannelAvailability = (name) => { const checkChannelAvailability = (name) => {
return db.Channel return db.Channel
.findAll({ .findAll({
where: { channelName: name }, where: {
channelName: name,
},
}) })
.then(result => { .then(result => {
if (result.length >= 1) { return (result.length <= 0);
throw new Error('That channel has already been claimed');
}
return name;
}) })
.catch(error => { .catch(error => {
throw error; throw error;

View file

@ -11,9 +11,18 @@ const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const channelAvailability = ({ ip, originalUrl, params: { name } }, res) => { const channelAvailability = ({ ip, originalUrl, params: { name } }, res) => {
const gaStartTime = Date.now(); const gaStartTime = Date.now();
checkChannelAvailability(name) checkChannelAvailability(name)
.then(availableName => { .then(isAvailable => {
res.status(200).json(availableName); let responseObject = {
sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now()); 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 => { .catch(error => {
handleErrorResponse(originalUrl, ip, error, res); handleErrorResponse(originalUrl, ip, error, res);

View file

@ -1,4 +1,4 @@
const db = require('../../../../models/index'); const db = require('../../../../models');
const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('../../../../../config/siteConfig.js'); const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('../../../../../config/siteConfig.js');
const Sequelize = require('sequelize'); const Sequelize = require('sequelize');
const Op = Sequelize.Op; const Op = Sequelize.Op;

View file

@ -19,7 +19,7 @@ const claimAvailability = ({ ip, originalUrl, params: { name } }, res) => {
if (isAvailable) { if (isAvailable) {
responseObject['message'] = `That claim name is available` responseObject['message'] = `That claim name is available`
} else { } else {
responseObject['message'] = `That name is already in use` responseObject['message'] = `That url is already in use`
} }
res.status(200).json(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());