-
Notifications
You must be signed in to change notification settings - Fork 0
/
paymentsDataProvider.js
61 lines (51 loc) · 1.67 KB
/
paymentsDataProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var Db = require('mongodb').Db;
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
var BSON = require('mongodb').BSON;
var ObjectID = require('mongodb').ObjectID;
PaymentProvider = function(host, port) {
this.db= new Db('magnolia', new Server(host, port, {auto_reconnect: true}, {}));
this.db.open(function(){});
};
PaymentProvider.prototype.getCollection= function(callback) {
this.db.collection('paymentData', function(error, payment_collection) {
if( error ) callback(error);
else callback(null, payment_collection);
});
};
PaymentProvider.prototype.findAll = function(callback) {
this.getCollection(function(error, payment_collection) {
if( error ) callback(error)
else {
payment_collection.find().toArray(function(error, results) {
if( error ) callback(error)
else callback(null, results)
});
}
});
};
PaymentProvider.prototype.add = function(payment, callback) {
this.getCollection(function(error, payment_collection) {
if( error ) callback(error)
else {
payment_collection.insert(payment, function() {
callback(null, payment); });
}
});
};
PaymentProvider.prototype.delete = function(id, callback) {
this.getCollection(function(error, payment_collection) {
if( error ) callback(error)
else {
payment_collection.remove({"_id": payment_collection.db.bson_serializer.ObjectID.createFromHexString(id)}, function(error, result) {
if( error ) {
console.log(error);
}
else {
callback(null,result)
}
});
}
});
};
exports.PaymentProvider = PaymentProvider;