insight-ui-zcash/app/models/Transaction.js

81 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-01-07 11:49:42 -08:00
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
async = require('async');
2014-01-07 11:49:42 -08:00
/**
*/
var TransactionSchema = new Schema({
// For now we keep this as short as possible
// More fields will be propably added as we move
// forward with the UX
txid: {
2014-01-07 11:49:42 -08:00
type: String,
index: true,
unique: true,
},
});
/**
* Statics
*/
TransactionSchema.statics.load = function(id, cb) {
this.findOne({
_id: id
}).exec(cb);
};
TransactionSchema.statics.fromID = function(txid, cb) {
2014-01-07 11:49:42 -08:00
this.findOne({
txid: txid,
2014-01-07 11:49:42 -08:00
}).exec(cb);
};
TransactionSchema.statics.createFromArray = function(txs, next) {
var that = this;
if (!txs) return next();
// console.log('exploding ', txs);
async.forEach( txs,
function(tx, callback) {
// console.log('procesing TX %s', tx);
that.create({ txid: tx }, function(err) {
if (err && ! err.toString().match(/E11000/)) {
return callback();
}
if (err) {
return callback(err);
}
return callback();
});
},
function(err) {
if (err) return next(err);
return next();
}
);
};
/*
* virtual
*/
// ugly? new object every call?
TransactionSchema.virtual('info').get(function () {
});
2014-01-07 11:49:42 -08:00
module.exports = mongoose.model('Transaction', TransactionSchema);