2018-05-04 00:47:58 +02:00
|
|
|
const db = require('../../../../models');
|
2018-06-06 03:55:44 +02:00
|
|
|
const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('@config/siteConfig.js');
|
2018-04-27 08:42:22 +02:00
|
|
|
const Sequelize = require('sequelize');
|
|
|
|
const Op = Sequelize.Op;
|
|
|
|
|
|
|
|
const claimAvailability = (name) => {
|
|
|
|
const claimAddresses = additionalClaimAddresses || [];
|
|
|
|
claimAddresses.push(primaryClaimAddress);
|
|
|
|
// find any records where the name is used
|
|
|
|
return db.Claim
|
|
|
|
.findAll({
|
|
|
|
attributes: ['address'],
|
|
|
|
where : {
|
|
|
|
name,
|
|
|
|
address: {
|
|
|
|
[Op.or]: claimAddresses,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(result => {
|
2018-05-04 00:22:29 +02:00
|
|
|
return (result.length <= 0);
|
2018-04-27 08:42:22 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = claimAvailability;
|