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) => {
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;

View file

@ -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);

View file

@ -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;

View file

@ -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());