@dhyasama/totem-models 2.3.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Financials.js +1 -26
- package/lib/Organization.js +3 -3
- package/package-lock.json +1 -1
- package/package.json +1 -1
- package/test/Financials.js +151 -0
package/lib/Financials.js
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
module.exports = function(mongoose, config) {
|
|
11
11
|
|
|
12
12
|
var Schema = mongoose.Schema;
|
|
13
|
-
var Round = mongoose.model('Round');
|
|
14
13
|
var async = require('async');
|
|
15
14
|
var _ = require('underscore');
|
|
16
15
|
|
|
@@ -93,31 +92,7 @@ module.exports = function(mongoose, config) {
|
|
|
93
92
|
'customer': config.CUSTOMER_ID
|
|
94
93
|
});
|
|
95
94
|
|
|
96
|
-
query.exec(
|
|
97
|
-
|
|
98
|
-
if (err) return cb(err, null);
|
|
99
|
-
if (!rounds || rounds.length == 0) return cb(null, []);
|
|
100
|
-
|
|
101
|
-
var error = checkForUnpopulatedData(rounds, 'Round.getByOrg');
|
|
102
|
-
if (error) return cb(error, null);
|
|
103
|
-
|
|
104
|
-
// reverse chronological
|
|
105
|
-
rounds = _.sortBy(rounds, function(r) {
|
|
106
|
-
|
|
107
|
-
var date = r.closingDate;
|
|
108
|
-
|
|
109
|
-
// use investment date in absence of closing date
|
|
110
|
-
if (!date && r.vehicles.length && r.vehicles[0].investments.length) {
|
|
111
|
-
date = r.vehicles[0].investments[0].investmentDate;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return date;
|
|
115
|
-
|
|
116
|
-
}).reverse();
|
|
117
|
-
|
|
118
|
-
return cb(null, rounds);
|
|
119
|
-
|
|
120
|
-
});
|
|
95
|
+
query.exec(cb);
|
|
121
96
|
|
|
122
97
|
};
|
|
123
98
|
|
package/lib/Organization.js
CHANGED
|
@@ -1209,15 +1209,15 @@ module.exports = function(mongoose, config) {
|
|
|
1209
1209
|
|
|
1210
1210
|
};
|
|
1211
1211
|
|
|
1212
|
-
Organization.statics.modify = function(
|
|
1212
|
+
Organization.statics.modify = function(filter, update, cb) {
|
|
1213
1213
|
|
|
1214
1214
|
if (!cb) throw new Error('cb is required');
|
|
1215
|
-
if (!
|
|
1215
|
+
if (!filter) { return cb(new Error('filter is required'), null); }
|
|
1216
1216
|
if (!update) { return cb(new Error('update is required'), null); }
|
|
1217
1217
|
|
|
1218
1218
|
var self = this;
|
|
1219
1219
|
|
|
1220
|
-
self.findOneAndUpdate(
|
|
1220
|
+
self.findOneAndUpdate(filter, update, { upsert: false, new: true }, cb);
|
|
1221
1221
|
|
|
1222
1222
|
};
|
|
1223
1223
|
|
package/package-lock.json
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var
|
|
4
|
+
|
|
5
|
+
should = require("should"),
|
|
6
|
+
_ = require('underscore'),
|
|
7
|
+
config = require('./config')['test'],
|
|
8
|
+
mongoose = require('mongoose'),
|
|
9
|
+
clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
|
|
10
|
+
Financials = mongoose.model('Financials');
|
|
11
|
+
|
|
12
|
+
var customerA = new mongoose.Types.ObjectId();
|
|
13
|
+
var customerB = new mongoose.Types.ObjectId();
|
|
14
|
+
var orgA = new mongoose.Types.ObjectId();
|
|
15
|
+
var orgB = new mongoose.Types.ObjectId();
|
|
16
|
+
|
|
17
|
+
describe('Financials', function() {
|
|
18
|
+
|
|
19
|
+
before(function(done) {
|
|
20
|
+
if (mongoose.connection.db) return done();
|
|
21
|
+
mongoose.connect(config.db.uri, done);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
before(function(done) {
|
|
25
|
+
clearDB(done);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('creates a financial document', function(done) {
|
|
29
|
+
|
|
30
|
+
var f = new Financials({
|
|
31
|
+
organization: orgA,
|
|
32
|
+
customer: customerA,
|
|
33
|
+
asOfDate: new Date(),
|
|
34
|
+
runway: 1
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
Financials.upsert(f, function(err, result) {
|
|
38
|
+
should.not.exist(err);
|
|
39
|
+
should.exist(result);
|
|
40
|
+
done();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('creates more financial documents', function(done) {
|
|
46
|
+
|
|
47
|
+
var f = new Financials({
|
|
48
|
+
organization: orgB,
|
|
49
|
+
customer: customerA,
|
|
50
|
+
asOfDate: new Date(),
|
|
51
|
+
runway: 2
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
Financials.upsert(f, function(err, result) {
|
|
55
|
+
|
|
56
|
+
should.not.exist(err);
|
|
57
|
+
should.exist(result);
|
|
58
|
+
|
|
59
|
+
var f = new Financials({
|
|
60
|
+
organization: orgB,
|
|
61
|
+
customer: customerB,
|
|
62
|
+
asOfDate: new Date(),
|
|
63
|
+
runway: 3
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
Financials.upsert(f, function(err, result) {
|
|
67
|
+
|
|
68
|
+
should.not.exist(err);
|
|
69
|
+
should.exist(result);
|
|
70
|
+
|
|
71
|
+
var f = new Financials({
|
|
72
|
+
organization: orgA,
|
|
73
|
+
customer: customerB,
|
|
74
|
+
asOfDate: new Date(),
|
|
75
|
+
runway: 4
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
Financials.upsert(f, function(err, result) {
|
|
79
|
+
should.not.exist(err);
|
|
80
|
+
should.exist(result);
|
|
81
|
+
done();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('gets financials for an org', function(done) {
|
|
91
|
+
|
|
92
|
+
config.CUSTOMER_ID = customerA;
|
|
93
|
+
|
|
94
|
+
Financials.getByOrg(orgA, function(err, result) {
|
|
95
|
+
should.not.exist(err);
|
|
96
|
+
should.exist(result);
|
|
97
|
+
result.length.should.equal(1);
|
|
98
|
+
result[0].runway.should.equal(1);
|
|
99
|
+
done();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('gets financials for the same org but different customer', function(done) {
|
|
105
|
+
|
|
106
|
+
config.CUSTOMER_ID = customerB;
|
|
107
|
+
|
|
108
|
+
Financials.getByOrg(orgA, function(err, result) {
|
|
109
|
+
should.not.exist(err);
|
|
110
|
+
should.exist(result);
|
|
111
|
+
result.length.should.equal(1);
|
|
112
|
+
result[0].runway.should.equal(4);
|
|
113
|
+
done();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('removes financials for a customer', function(done) {
|
|
119
|
+
|
|
120
|
+
config.CUSTOMER_ID = customerA;
|
|
121
|
+
|
|
122
|
+
Financials.find({}, function(err, result) {
|
|
123
|
+
|
|
124
|
+
should.not.exist(err);
|
|
125
|
+
should.exist(result);
|
|
126
|
+
result.length.should.equal(4);
|
|
127
|
+
|
|
128
|
+
Financials.removeCustomerFinancials(config.CUSTOMER_ID, function(err, result) {
|
|
129
|
+
|
|
130
|
+
should.not.exist(err);
|
|
131
|
+
should.exist(result);
|
|
132
|
+
|
|
133
|
+
Financials.find({}, function(err, result) {
|
|
134
|
+
|
|
135
|
+
should.not.exist(err);
|
|
136
|
+
should.exist(result);
|
|
137
|
+
result.length.should.equal(2);
|
|
138
|
+
result[0].runway.should.equal(3);
|
|
139
|
+
result[1].runway.should.equal(4);
|
|
140
|
+
|
|
141
|
+
done();
|
|
142
|
+
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
});
|