added blocked model

This commit is contained in:
bill bittner 2018-04-29 10:31:26 -07:00
parent b5c486c4ac
commit c89fdd390e
3 changed files with 30 additions and 3 deletions

View file

@ -7,7 +7,7 @@ const NO_FILE = 'NO_FILE';
const NO_CHANNEL = 'NO_CHANNEL'; const NO_CHANNEL = 'NO_CHANNEL';
const NO_CLAIM = 'NO_CLAIM'; const NO_CLAIM = 'NO_CLAIM';
function serveAssetToClient (claimId, name, res) { const serveAssetToClient = (claimId, name, res) => {
return getLocalFileRecord(claimId, name) return getLocalFileRecord(claimId, name)
.then(fileRecord => { .then(fileRecord => {
// check that a local record was found // check that a local record was found

View file

@ -1,5 +1,7 @@
const logger = require('winston');
module.exports = (sequelize, { STRING }) => { module.exports = (sequelize, { STRING }) => {
return sequelize.define( const Blocked = sequelize.define(
'Blocked', 'Blocked',
{ {
outpoint: { outpoint: {
@ -11,4 +13,26 @@ module.exports = (sequelize, { STRING }) => {
freezeTableName: true, freezeTableName: true,
} }
); );
Blocked.isBlocked = function (outpoint) {
logger.debug(`checking to see if ${outpoint} is blocked`);
return new Promise((resolve, reject) => {
this.findOne({
where: {
outpoint,
},
})
.then(result => {
if (!result) {
return resolve(false);
}
resolve(true);
})
.catch(error => {
reject(error);
});
});
};
return Blocked;
}; };

View file

@ -315,7 +315,10 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
Claim.validateLongClaimId = function (name, claimId) { Claim.validateLongClaimId = function (name, claimId) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.findOne({ this.findOne({
where: {name, claimId}, where: {
name,
claimId,
},
}) })
.then(result => { .then(result => {
if (!result) { if (!result) {