spee.ch/server/controllers/api/claim/availability/checkClaimAvailability.js
2018-12-16 01:27:08 -06:00

28 lines
763 B
JavaScript

const chainquery = require('chainquery').default;
const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('@config/siteConfig');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const claimAvailability = async (name) => {
const claimAddresses = additionalClaimAddresses || [];
claimAddresses.push(primaryClaimAddress);
// find any records where the name is used
return chainquery.claim
.findAll({
attributes: ['claim_address'],
where : {
name,
claim_address: {
[Op.or]: claimAddresses,
},
},
})
.then(result => {
return (result.length <= 0);
})
.catch(error => {
throw error;
});
};
module.exports = claimAvailability;