fixed name availability querty to use "or"
This commit is contained in:
parent
6414142f73
commit
c247a9c79e
3 changed files with 16 additions and 15 deletions
|
@ -3,6 +3,8 @@ const db = require('../models');
|
||||||
const lbryApi = require('../helpers/lbryApi.js');
|
const lbryApi = require('../helpers/lbryApi.js');
|
||||||
const publishHelpers = require('../helpers/publishHelpers.js');
|
const publishHelpers = require('../helpers/publishHelpers.js');
|
||||||
const { publish : { primaryClaimAddress, additionalClaimAddresses } } = require('../config/speechConfig.js');
|
const { publish : { primaryClaimAddress, additionalClaimAddresses } } = require('../config/speechConfig.js');
|
||||||
|
const Sequelize = require('sequelize');
|
||||||
|
const Op = Sequelize.Op;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publish (publishParams, fileName, fileType) {
|
publish (publishParams, fileName, fileType) {
|
||||||
|
@ -87,26 +89,24 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
claimNameIsAvailable (name) {
|
claimNameIsAvailable (name) {
|
||||||
|
const claimAddresses = additionalClaimAddresses || [];
|
||||||
|
claimAddresses.push(primaryClaimAddress);
|
||||||
// find any records where the name is used
|
// find any records where the name is used
|
||||||
return db.Claim
|
return db.Claim
|
||||||
.findAll({
|
.findAll({
|
||||||
attributes: ['address'],
|
attributes: ['address'],
|
||||||
where : { name },
|
where : {
|
||||||
|
name,
|
||||||
|
address: {
|
||||||
|
[Op.or]: claimAddresses,
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.length >= 1) {
|
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');
|
throw new Error('That claim is already in use');
|
||||||
};
|
};
|
||||||
return name;
|
return name;
|
||||||
};
|
|
||||||
return name;
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
// const fs = require('fs');
|
|
||||||
// const path = require('path');
|
|
||||||
const Sequelize = require('sequelize');
|
const Sequelize = require('sequelize');
|
||||||
// const basename = path.basename(module.filename);
|
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const config = require('../config/speechConfig.js');
|
const config = require('../config/speechConfig.js');
|
||||||
const { database, username, password } = config.sql;
|
const { database, username, password } = config.sql;
|
||||||
|
|
|
@ -91,7 +91,11 @@ class ChannelCreateForm extends React.Component {
|
||||||
this.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
this.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.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 () {
|
render () {
|
||||||
|
|
Loading…
Reference in a new issue