fixed name availability querty to use "or"

This commit is contained in:
bill bittner 2018-03-12 12:03:20 -07:00
parent 6414142f73
commit c247a9c79e
3 changed files with 16 additions and 15 deletions

View file

@ -3,6 +3,8 @@ const db = require('../models');
const lbryApi = require('../helpers/lbryApi.js');
const publishHelpers = require('../helpers/publishHelpers.js');
const { publish : { primaryClaimAddress, additionalClaimAddresses } } = require('../config/speechConfig.js');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
module.exports = {
publish (publishParams, fileName, fileType) {
@ -87,24 +89,22 @@ module.exports = {
});
},
claimNameIsAvailable (name) {
const claimAddresses = additionalClaimAddresses || [];
claimAddresses.push(primaryClaimAddress);
// find any records where the name is used
return db.Claim
.findAll({
attributes: ['address'],
where : { name },
where : {
name,
address: {
[Op.or]: claimAddresses,
},
},
})
.then(result => {
if (result.length >= 1) {
const claimAddresses = additionalClaimAddresses || [];
claimAddresses.push(primaryClaimAddress);
// filter out any that were not published from this address
const filteredResult = result.filter(({ address }) => {
return (claimAddresses.includes(address));
});
if (filteredResult.length >= 1) {
throw new Error('That claim is already in use');
};
return name;
throw new Error('That claim is already in use');
};
return name;
})

View file

@ -1,7 +1,4 @@
// const fs = require('fs');
// const path = require('path');
const Sequelize = require('sequelize');
// const basename = path.basename(module.filename);
const logger = require('winston');
const config = require('../config/speechConfig.js');
const { database, username, password } = config.sql;

View file

@ -91,7 +91,11 @@ class ChannelCreateForm extends React.Component {
this.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
})
.catch((error) => {
if (error.message) this.setState({'error': error.message, status: null});
if (error.message) {
this.setState({'error': error.message, status: null});
} else {
this.setState({'error': error, status: null});
};
});
}
render () {