Claim availability check #434

Merged
bones7242 merged 7 commits from claim-availability-check into master 2018-05-06 20:22:38 +02:00
4 changed files with 18 additions and 10 deletions
Showing only changes of commit 8b808b2c10 - Show all commits

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