2018-12-14 18:42:37 +01:00
|
|
|
const chainquery = require('chainquery').default;
|
2018-06-06 04:34:24 +02:00
|
|
|
const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('@config/siteConfig');
|
2018-04-27 08:42:22 +02:00
|
|
|
const Sequelize = require('sequelize');
|
|
|
|
const Op = Sequelize.Op;
|
|
|
|
|
2018-09-26 03:20:59 +02:00
|
|
|
const claimAvailability = async (name) => {
|
2018-04-27 08:42:22 +02:00
|
|
|
const claimAddresses = additionalClaimAddresses || [];
|
|
|
|
claimAddresses.push(primaryClaimAddress);
|
|
|
|
// find any records where the name is used
|
2018-11-11 01:32:43 +01:00
|
|
|
return chainquery.claim
|
2018-04-27 08:42:22 +02:00
|
|
|
.findAll({
|
2018-09-26 03:20:59 +02:00
|
|
|
attributes: ['claim_address'],
|
2018-04-27 08:42:22 +02:00
|
|
|
where : {
|
|
|
|
name,
|
2018-09-26 03:20:59 +02:00
|
|
|
claim_address: {
|
2018-04-27 08:42:22 +02:00
|
|
|
[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;
|