spee.ch/server/controllers/api/claim/availability/checkClaimAvailability.js

29 lines
755 B
JavaScript
Raw Normal View History

2018-09-26 03:20:59 +02:00
const chainquery = require('chainquery');
2018-06-06 04:34:24 +02:00
const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('@config/siteConfig');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
2018-09-26 03:20:59 +02:00
const claimAvailability = async (name) => {
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
.findAll({
2018-09-26 03:20:59 +02:00
attributes: ['claim_address'],
where : {
name,
2018-09-26 03:20:59 +02:00
claim_address: {
[Op.or]: claimAddresses,
},
},
})
.then(result => {
return (result.length <= 0);
})
.catch(error => {
throw error;
});
};
module.exports = claimAvailability;