@dhyasama/totem-models 1.9.0 → 1.11.0
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/Account.js +1 -1
- package/lib/Organization.js +97 -18
- package/package.json +1 -1
- package/test/Organization.js +153 -0
package/lib/Account.js
CHANGED
|
@@ -41,7 +41,7 @@ module.exports = function(mongoose, config) {
|
|
|
41
41
|
admin: { type: Boolean },
|
|
42
42
|
active: { type: Boolean },
|
|
43
43
|
subscriber: { type: Boolean },
|
|
44
|
-
role: { type: String, enum: ['admin', 'lp-full', 'lp-names', 'none'] },
|
|
44
|
+
role: { type: String, enum: ['admin', 'lp-full', 'lp-names', 'welcome', 'none'] },
|
|
45
45
|
|
|
46
46
|
// Enable this and iLevel links will show on portfolio pages
|
|
47
47
|
iLevelUser: { type: Boolean },
|
package/lib/Organization.js
CHANGED
|
@@ -89,19 +89,37 @@ module.exports = function(mongoose, config) {
|
|
|
89
89
|
aliases: [ { type: String, trim: true } ],
|
|
90
90
|
|
|
91
91
|
foundedOn: { type: Date, default: null },
|
|
92
|
-
closedOn: { type: Date, default: null },
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
ipo: {
|
|
94
|
+
ticker: {type: String, default: null, trim: true},
|
|
95
|
+
offeredOn: {type: Date, default: null}
|
|
96
|
+
},
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
operating: {
|
|
99
|
+
|
|
100
|
+
closed: {
|
|
101
|
+
public: {
|
|
102
|
+
closedOn: { type: Date, default: null }
|
|
103
|
+
},
|
|
104
|
+
private: [{
|
|
105
|
+
customer: { type: Schema.ObjectId, ref: 'Organization' },
|
|
106
|
+
closedOn: { type: Date, default: null },
|
|
107
|
+
hasZeroUnrealizedValue: { type: Boolean, default: false }
|
|
108
|
+
}]
|
|
100
109
|
},
|
|
101
110
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
acquired: {
|
|
112
|
+
public: {
|
|
113
|
+
by: { type: Schema.ObjectId, ref: 'Organization' },
|
|
114
|
+
acquiredOn: { type: Date, default: null },
|
|
115
|
+
amount: { type: Number, default: 0 }
|
|
116
|
+
},
|
|
117
|
+
private: [{
|
|
118
|
+
customer: { type: Schema.ObjectId, ref: 'Organization' },
|
|
119
|
+
by: { type: Schema.ObjectId, ref: 'Organization' },
|
|
120
|
+
acquiredOn: { type: Date, default: null },
|
|
121
|
+
amount: { type: Number, default: 0 }
|
|
122
|
+
}]
|
|
105
123
|
}
|
|
106
124
|
|
|
107
125
|
},
|
|
@@ -211,6 +229,51 @@ module.exports = function(mongoose, config) {
|
|
|
211
229
|
// Properties that are not persisted to the database
|
|
212
230
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
213
231
|
|
|
232
|
+
Organization.virtual('acquired.amount').get(function () {
|
|
233
|
+
|
|
234
|
+
var self = this;
|
|
235
|
+
var publicData = self.operating.acquired.public || {};
|
|
236
|
+
var privateData = self.operating.acquired.private || [];
|
|
237
|
+
|
|
238
|
+
if (publicData.amount) return publicData.amount;
|
|
239
|
+
else if (privateData.length == 1) {
|
|
240
|
+
if (privateData[0].amount) return privateData[0].amount;
|
|
241
|
+
else return 0;
|
|
242
|
+
}
|
|
243
|
+
else return 0;
|
|
244
|
+
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
Organization.virtual('acquired.by').get(function () {
|
|
248
|
+
|
|
249
|
+
var self = this;
|
|
250
|
+
var publicData = self.operating.acquired.public || {};
|
|
251
|
+
var privateData = self.operating.acquired.private || [];
|
|
252
|
+
|
|
253
|
+
if (publicData.by) return publicData.by;
|
|
254
|
+
else if (privateData.length == 1) {
|
|
255
|
+
if (privateData[0].by) return privateData[0].by;
|
|
256
|
+
else return null;
|
|
257
|
+
}
|
|
258
|
+
else return null;
|
|
259
|
+
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
Organization.virtual('acquired.on').get(function () {
|
|
263
|
+
|
|
264
|
+
var self = this;
|
|
265
|
+
var publicData = self.operating.acquired.public || {};
|
|
266
|
+
var privateData = self.operating.acquired.private || [];
|
|
267
|
+
|
|
268
|
+
if (publicData.acquiredOn) return publicData.acquiredOn;
|
|
269
|
+
else if (privateData.length == 1) {
|
|
270
|
+
if (privateData[0].acquiredOn) return privateData[0].acquiredOn;
|
|
271
|
+
else return null;
|
|
272
|
+
}
|
|
273
|
+
else return null;
|
|
274
|
+
|
|
275
|
+
});
|
|
276
|
+
|
|
214
277
|
Organization.virtual('address.primary').get(function () {
|
|
215
278
|
var primary = _.find(this.contact.address, function(address) {
|
|
216
279
|
return address.primary;
|
|
@@ -275,6 +338,22 @@ module.exports = function(mongoose, config) {
|
|
|
275
338
|
|
|
276
339
|
});
|
|
277
340
|
|
|
341
|
+
Organization.virtual('closed').get(function () {
|
|
342
|
+
|
|
343
|
+
var self = this;
|
|
344
|
+
var publicData = self.operating.closed.public || {};
|
|
345
|
+
var privateData = self.operating.closed.private || [];
|
|
346
|
+
|
|
347
|
+
if (publicData.closedOn) return true;
|
|
348
|
+
else if (privateData.length == 1) {
|
|
349
|
+
if (privateData[0].closedOn) return true;
|
|
350
|
+
if (privateData[0].hasZeroUnrealizedValue) return true;
|
|
351
|
+
else return false;
|
|
352
|
+
}
|
|
353
|
+
else return false;
|
|
354
|
+
|
|
355
|
+
});
|
|
356
|
+
|
|
278
357
|
Organization.virtual('employees.all').get(function () {
|
|
279
358
|
|
|
280
359
|
var self = this;
|
|
@@ -387,11 +466,9 @@ module.exports = function(mongoose, config) {
|
|
|
387
466
|
|
|
388
467
|
var self = this;
|
|
389
468
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (self.
|
|
393
|
-
else if (self.ipo && self.ipo.year) return 'IPO';
|
|
394
|
-
else if (self.acquisition && self.acquisition.year) return 'Acquired';
|
|
469
|
+
if (self.closed) return 'Dead';
|
|
470
|
+
else if (self.ipo.ticker) return 'IPO';
|
|
471
|
+
else if (self.acquired.by) return 'Acquired';
|
|
395
472
|
else return 'Active';
|
|
396
473
|
|
|
397
474
|
});
|
|
@@ -988,10 +1065,12 @@ module.exports = function(mongoose, config) {
|
|
|
988
1065
|
// remove customer details if not viewing self
|
|
989
1066
|
if (doc._id.toString() != CUSTOMER_ID) doc.customer = {};
|
|
990
1067
|
|
|
991
|
-
doc.filters = _.reject(doc.filters, function(item) { return item.customer != CUSTOMER_ID; });
|
|
992
|
-
doc.docs = _.reject(doc.docs, function(item) { return item.customer != CUSTOMER_ID; });
|
|
993
|
-
doc.iLevel = _.reject(doc.iLevel, function(item) { return item.customer != CUSTOMER_ID; });
|
|
994
|
-
doc.chairs = _.reject(doc.chairs, function(item) { return item.customer != CUSTOMER_ID; });
|
|
1068
|
+
doc.filters = _.reject(doc.filters, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1069
|
+
doc.docs = _.reject(doc.docs, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1070
|
+
doc.iLevel = _.reject(doc.iLevel, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1071
|
+
doc.chairs = _.reject(doc.chairs, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1072
|
+
doc.operating.acquired.private = _.find(doc.operating.acquired.private, function(item) { return !item.customer || item.customer.toString() == CUSTOMER_ID; });
|
|
1073
|
+
doc.operating.closed.private = _.find(doc.operating.closed.private, function(item) { return !item.customer || item.customer.toString() == CUSTOMER_ID; });
|
|
995
1074
|
|
|
996
1075
|
// people
|
|
997
1076
|
_.each(doc.people, function(person) {
|
package/package.json
CHANGED
package/test/Organization.js
CHANGED
|
@@ -37,6 +37,15 @@ describe('Organization', function() {
|
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
+
before(function (done) {
|
|
41
|
+
Person.collection.dropIndexes(function (err, result) {
|
|
42
|
+
should.not.exist(err);
|
|
43
|
+
should.exist(result);
|
|
44
|
+
result.should.equal(true);
|
|
45
|
+
return done();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
40
49
|
before(function (done) {
|
|
41
50
|
|
|
42
51
|
org2 = new Organization();
|
|
@@ -780,6 +789,150 @@ describe('Organization', function() {
|
|
|
780
789
|
|
|
781
790
|
});
|
|
782
791
|
|
|
792
|
+
describe('State', function() {
|
|
793
|
+
|
|
794
|
+
it('gets ipo info', function(done) {
|
|
795
|
+
|
|
796
|
+
var org = new Organization();
|
|
797
|
+
org.name = 'Homerun';
|
|
798
|
+
org.slug = 'homerun';
|
|
799
|
+
org.ipo.ticker = 'HOME';
|
|
800
|
+
|
|
801
|
+
Organization.upsert(org, 'test-user', function(err, result) {
|
|
802
|
+
should.not.exist(err);
|
|
803
|
+
should.exist(result);
|
|
804
|
+
result.status.should.equal('IPO');
|
|
805
|
+
result.ipo.ticker.should.equal('HOME');
|
|
806
|
+
return done();
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
it('gets public acquisition info', function(done) {
|
|
812
|
+
|
|
813
|
+
var org = new Organization();
|
|
814
|
+
org.name = 'Publicks';
|
|
815
|
+
org.slug = 'publicks';
|
|
816
|
+
org.operating.acquired.public.by = new mongoose.Types.ObjectId();
|
|
817
|
+
org.operating.acquired.public.acquiredOn = new Date();
|
|
818
|
+
org.operating.acquired.public.amount = 1;
|
|
819
|
+
org.operating.acquired.private.push({
|
|
820
|
+
customer: new mongoose.Types.ObjectId(),
|
|
821
|
+
by: new mongoose.Types.ObjectId(),
|
|
822
|
+
acquiredOn: new Date(),
|
|
823
|
+
amount: 2
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
Organization.upsert(org, 'test-user', function(err, result) {
|
|
827
|
+
should.not.exist(err);
|
|
828
|
+
should.exist(result);
|
|
829
|
+
result.status.should.equal('Acquired');
|
|
830
|
+
result.acquired.amount.should.equal(1);
|
|
831
|
+
return done();
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
it('gets private acquisition info', function(done) {
|
|
837
|
+
|
|
838
|
+
var org = new Organization();
|
|
839
|
+
org.name = 'Stanky';
|
|
840
|
+
org.slug = 'stanky';
|
|
841
|
+
org.operating.acquired.public.by = null;
|
|
842
|
+
org.operating.acquired.public.acquiredOn = null;
|
|
843
|
+
org.operating.acquired.public.amount = 0;
|
|
844
|
+
|
|
845
|
+
org.operating.acquired.private.push({
|
|
846
|
+
customer: new mongoose.Types.ObjectId(),
|
|
847
|
+
by: new mongoose.Types.ObjectId(),
|
|
848
|
+
acquiredOn: new Date(),
|
|
849
|
+
amount: 2
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
org.operating.acquired.private.push({
|
|
853
|
+
customer: config.CUSTOMER_ID,
|
|
854
|
+
by: new mongoose.Types.ObjectId(),
|
|
855
|
+
acquiredOn: new Date(),
|
|
856
|
+
amount: 4
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
Organization.upsert(org, 'test-user', function(err, result) {
|
|
860
|
+
|
|
861
|
+
should.not.exist(err);
|
|
862
|
+
should.exist(result);
|
|
863
|
+
|
|
864
|
+
Organization.findById(result._id, function(err, org) {
|
|
865
|
+
|
|
866
|
+
should.not.exist(err);
|
|
867
|
+
should.exist(org);
|
|
868
|
+
|
|
869
|
+
org.status.should.equal('Acquired');
|
|
870
|
+
org.acquired.amount.should.equal(4);
|
|
871
|
+
return done();
|
|
872
|
+
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
it('gets public closed info', function(done) {
|
|
880
|
+
|
|
881
|
+
var org = new Organization();
|
|
882
|
+
org.name = 'The Copper Beaver';
|
|
883
|
+
org.slug = 'the-copper-beaver';
|
|
884
|
+
org.operating.closed.public.closedOn = new Date();
|
|
885
|
+
org.operating.closed.private.push({
|
|
886
|
+
customer: new mongoose.Types.ObjectId(),
|
|
887
|
+
hasZeroUnrealizedValue: false,
|
|
888
|
+
closedOn: null
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
Organization.upsert(org, 'test-user', function(err, result) {
|
|
892
|
+
should.not.exist(err);
|
|
893
|
+
should.exist(result);
|
|
894
|
+
result.status.should.equal('Dead');
|
|
895
|
+
return done();
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
});
|
|
899
|
+
|
|
900
|
+
it('gets private closed info', function(done) {
|
|
901
|
+
|
|
902
|
+
var org = new Organization();
|
|
903
|
+
org.name = 'Dam Hydraulics';
|
|
904
|
+
org.slug = 'dam-hydraulics';
|
|
905
|
+
org.operating.closed.public.closedOn = new Date();
|
|
906
|
+
|
|
907
|
+
org.operating.closed.private.push({
|
|
908
|
+
customer: new mongoose.Types.ObjectId(),
|
|
909
|
+
hasZeroUnrealizedValue: false,
|
|
910
|
+
closedOn: null
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
org.operating.closed.private.push({
|
|
914
|
+
customer: config.CUSTOMER_ID,
|
|
915
|
+
hasZeroUnrealizedValue: true,
|
|
916
|
+
closedOn: null
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
Organization.upsert(org, 'test-user', function(err, result) {
|
|
920
|
+
|
|
921
|
+
should.not.exist(err);
|
|
922
|
+
should.exist(result);
|
|
923
|
+
|
|
924
|
+
Organization.findById(result._id, function(err, org) {
|
|
925
|
+
should.not.exist(err);
|
|
926
|
+
should.exist(org);
|
|
927
|
+
org.status.should.equal('Dead');
|
|
928
|
+
return done();
|
|
929
|
+
});
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
});
|
|
935
|
+
|
|
783
936
|
// not yet tested:
|
|
784
937
|
// listAllFlagged
|
|
785
938
|
// listPage
|