spee.ch/server/models/blocked.js

51 lines
1,010 B
JavaScript
Raw Normal View History

2018-04-29 19:31:26 +02:00
const logger = require('winston');
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',
{
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
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: {
claimId,
name,
2018-04-29 19:31:26 +02:00
},
})
.then(result => {
if (result) {
return reject(BLOCKED_CLAIM);
2018-04-29 19:31:26 +02:00
}
resolve(true);
})
.catch(error => {
logger.error(error);
reject(BLOCKED_CLAIM);
2018-04-29 19:31:26 +02:00
});
});
};
return Blocked;
2018-04-28 00:17:09 +02:00
};