2018-04-29 19:31:26 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
|
2018-04-29 21:17:23 +02:00
|
|
|
const BLOCKED_CLAIM = 'BLOCKED_CLAIM';
|
|
|
|
|
2018-04-28 00:17:09 +02:00
|
|
|
module.exports = (sequelize, { STRING }) => {
|
2018-04-29 19:31:26 +02:00
|
|
|
const Blocked = sequelize.define(
|
2018-04-28 00:17:09 +02:00
|
|
|
'Blocked',
|
|
|
|
{
|
2018-04-29 21:17:23 +02:00
|
|
|
claimId: {
|
|
|
|
type : STRING,
|
|
|
|
allowNull: false,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type : STRING,
|
|
|
|
allowNull: false,
|
|
|
|
},
|
2018-04-28 00:17:09 +02:00
|
|
|
outpoint: {
|
|
|
|
type : STRING,
|
|
|
|
allowNull: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
freezeTableName: true,
|
|
|
|
}
|
|
|
|
);
|
2018-04-29 19:31:26 +02:00
|
|
|
|
2018-04-29 21:17:23 +02:00
|
|
|
Blocked.isNotBlocked = function (claimId, name) {
|
|
|
|
logger.debug(`checking to see if ${name}#${claimId} is not blocked`);
|
2018-04-29 19:31:26 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this.findOne({
|
|
|
|
where: {
|
2018-04-29 21:17:23 +02:00
|
|
|
claimId,
|
|
|
|
name,
|
2018-04-29 19:31:26 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(result => {
|
2018-04-29 21:17:23 +02:00
|
|
|
if (result) {
|
|
|
|
return reject(BLOCKED_CLAIM);
|
2018-04-29 19:31:26 +02:00
|
|
|
}
|
|
|
|
resolve(true);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2018-04-29 21:17:23 +02:00
|
|
|
logger.error(error);
|
|
|
|
reject(BLOCKED_CLAIM);
|
2018-04-29 19:31:26 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return Blocked;
|
2018-04-28 00:17:09 +02:00
|
|
|
};
|