@dhyasama/totem-models 1.19.1 → 1.20.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/index.js +6 -0
- package/lib/Flag.js +79 -0
- package/lib/LimitedPartner.js +46 -10
- package/lib/Organization.js +61 -3
- package/lib/Person.js +67 -3
- package/package.json +1 -1
- package/test/Flag.js +247 -0
- package/test/Organization.js +31 -0
package/index.js
CHANGED
|
@@ -19,6 +19,12 @@ var bootstrap = function(mongoose, config) {
|
|
|
19
19
|
|
|
20
20
|
// todo - find a solution to load without worrying about order
|
|
21
21
|
|
|
22
|
+
// flag must be loaded before fund
|
|
23
|
+
// flag must be loaded before limited partner
|
|
24
|
+
// flag must be loaded before organization
|
|
25
|
+
// flag must be loaded before person
|
|
26
|
+
require('./lib/Flag.js')(mongoose, config);
|
|
27
|
+
|
|
22
28
|
// note must be loaded before limited partner
|
|
23
29
|
// note must be loaded before organization
|
|
24
30
|
// note must be loaded before person
|
package/lib/Flag.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function(mongoose, config) {
|
|
4
|
+
|
|
5
|
+
var
|
|
6
|
+
|
|
7
|
+
Schema = mongoose.Schema,
|
|
8
|
+
querystring = require('querystring');
|
|
9
|
+
|
|
10
|
+
var Flag = new Schema({
|
|
11
|
+
|
|
12
|
+
customer: { type: Schema.ObjectId, ref: 'Organization', index: true, required: true },
|
|
13
|
+
|
|
14
|
+
createdOn: { type: Date, index: false, required: true },
|
|
15
|
+
|
|
16
|
+
createdBy: { type: Schema.ObjectId, ref: 'Person', index: false, required: true },
|
|
17
|
+
|
|
18
|
+
text: { type: String, index: false, required: true, trim: true },
|
|
19
|
+
|
|
20
|
+
status: { type: String, enum: ['open', 'closed'], default: 'open' }
|
|
21
|
+
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
Flag.statics.createForModel = function(flag, Model, modelId, cb) {
|
|
25
|
+
|
|
26
|
+
var addToModel = function(err, createdFlag) {
|
|
27
|
+
if (err) return cb(err, null);
|
|
28
|
+
Model.findByIdAndUpdate(modelId, { $push: { flags: createdFlag }}, { new: true, upsert: false }, function(err, addedTo) {
|
|
29
|
+
return cb(err, {
|
|
30
|
+
flag: createdFlag,
|
|
31
|
+
addedTo: addedTo
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
flag.createdOn = new Date();
|
|
37
|
+
flag.customer = config.CUSTOMER_ID;
|
|
38
|
+
|
|
39
|
+
this.create(flag, addToModel);
|
|
40
|
+
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
Flag.statics.delete = function(flagId, cb) {
|
|
44
|
+
|
|
45
|
+
var self = this;
|
|
46
|
+
|
|
47
|
+
// Not strictly necessary but provides verification that the flag being deleted belongs to the customer doing the deleting
|
|
48
|
+
self.findOne({
|
|
49
|
+
'_id': flagId,
|
|
50
|
+
'customer': config.CUSTOMER_ID
|
|
51
|
+
}, function(err, flag) {
|
|
52
|
+
|
|
53
|
+
if (err) return cb(err, null);
|
|
54
|
+
else if (!flag) return cb(null, null);
|
|
55
|
+
|
|
56
|
+
flag.remove(cb);
|
|
57
|
+
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
Flag.statics.getById = function(id, cb) {
|
|
63
|
+
this.findOne({
|
|
64
|
+
'_id': id,
|
|
65
|
+
'customer': config.CUSTOMER_ID
|
|
66
|
+
}).exec(cb);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
Flag.post('init', function() {
|
|
70
|
+
var self = this;
|
|
71
|
+
self.text = querystring.unescape(self.text);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
Flag.set('autoIndex', false);
|
|
75
|
+
Flag.on('index', function(err) { console.log('error building Flag indexes: ' + err); });
|
|
76
|
+
|
|
77
|
+
mongoose.model('Flag', Flag);
|
|
78
|
+
|
|
79
|
+
};
|
package/lib/LimitedPartner.js
CHANGED
|
@@ -7,6 +7,7 @@ module.exports = function(mongoose, config) {
|
|
|
7
7
|
CUSTOMER_ID = config.CUSTOMER_ID,
|
|
8
8
|
LPS_ENABLED = config.LPS_ENABLED,
|
|
9
9
|
Schema = mongoose.Schema,
|
|
10
|
+
Flag = mongoose.model('Flag'),
|
|
10
11
|
Fund = mongoose.model('Fund'),
|
|
11
12
|
Note = mongoose.model('Note'),
|
|
12
13
|
Organization = mongoose.model('Organization'),
|
|
@@ -165,6 +166,8 @@ module.exports = function(mongoose, config) {
|
|
|
165
166
|
resolved: { type: Boolean, default: false }
|
|
166
167
|
},
|
|
167
168
|
|
|
169
|
+
flags: [ { type: Schema.ObjectId, ref: 'Flag' } ],
|
|
170
|
+
|
|
168
171
|
notes: [ { type: Schema.ObjectId, ref: 'Note' } ]
|
|
169
172
|
|
|
170
173
|
});
|
|
@@ -446,16 +449,19 @@ module.exports = function(mongoose, config) {
|
|
|
446
449
|
var self = this;
|
|
447
450
|
var query = self.findById(lpid)
|
|
448
451
|
|
|
449
|
-
query.select('notes')
|
|
452
|
+
query.select('notes people')
|
|
453
|
+
query.populate('people', 'name avatarUrl title calendarEventSummaries')
|
|
450
454
|
query.populate({
|
|
451
455
|
path: 'notes',
|
|
452
456
|
match: { customer: config.CUSTOMER_ID }
|
|
453
457
|
})
|
|
454
458
|
query.deepPopulate([
|
|
455
|
-
'notes.createdBy'
|
|
459
|
+
'notes.createdBy',
|
|
460
|
+
'people.calendarEventSummaries.notes.createdBy'
|
|
456
461
|
], {
|
|
457
462
|
populate: {
|
|
458
|
-
'notes.createdBy': { select: 'name avatarUrl title' }
|
|
463
|
+
'notes.createdBy': { select: 'name avatarUrl title' },
|
|
464
|
+
'people.calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title' }
|
|
459
465
|
}
|
|
460
466
|
})
|
|
461
467
|
query.sort({'createdOn':-1})
|
|
@@ -638,6 +644,15 @@ module.exports = function(mongoose, config) {
|
|
|
638
644
|
|
|
639
645
|
};
|
|
640
646
|
|
|
647
|
+
LimitedPartner.statics.addFlag = function(lpid, creatorPersonId, text, cb) {
|
|
648
|
+
|
|
649
|
+
Flag.createForModel({
|
|
650
|
+
createdBy: creatorPersonId,
|
|
651
|
+
text: text
|
|
652
|
+
}, this, lpid, cb);
|
|
653
|
+
|
|
654
|
+
};
|
|
655
|
+
|
|
641
656
|
LimitedPartner.statics.addNote = function(lpid, creatorPersonId, text, cb) {
|
|
642
657
|
|
|
643
658
|
Note.createForModel({
|
|
@@ -647,6 +662,27 @@ module.exports = function(mongoose, config) {
|
|
|
647
662
|
|
|
648
663
|
};
|
|
649
664
|
|
|
665
|
+
LimitedPartner.statics.deleteFlag = function(flagId, cb) {
|
|
666
|
+
|
|
667
|
+
// Delete the flag itself along with any references
|
|
668
|
+
|
|
669
|
+
var self = this;
|
|
670
|
+
|
|
671
|
+
var removeReferences = function removeReferences(callback) {
|
|
672
|
+
self.update({}, {
|
|
673
|
+
$pull: { 'flags' : [flagId] }
|
|
674
|
+
}, callback);
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
async.series([
|
|
678
|
+
Flag.delete.bind(Flag, flagId),
|
|
679
|
+
removeReferences
|
|
680
|
+
], function(err, results) {
|
|
681
|
+
return cb(err, null);
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
};
|
|
685
|
+
|
|
650
686
|
LimitedPartner.statics.deleteNote = function(noteId, cb) {
|
|
651
687
|
|
|
652
688
|
// Delete the note itself along with any references
|
|
@@ -747,15 +783,15 @@ module.exports = function(mongoose, config) {
|
|
|
747
783
|
|
|
748
784
|
LimitedPartner.plugin(filter, {
|
|
749
785
|
readFilter: {
|
|
750
|
-
'admin': ['name', 'shortName', 'start', 'people', 'documentSlugs', 'fundsInvested', 'contact', 'distributions', 'k1', 'entered', 'status', 'flagged', 'notes'],
|
|
751
|
-
'lp-full': ['name', 'shortName', 'start', 'people', 'documentSlugs', 'fundsInvested', 'contact', 'distributions', 'k1', 'entered', 'status', 'flagged', 'notes'],
|
|
752
|
-
'lp-names': ['name', 'shortName', 'flagged'],
|
|
786
|
+
'admin': ['name', 'shortName', 'start', 'people', 'documentSlugs', 'fundsInvested', 'contact', 'distributions', 'k1', 'entered', 'status', 'flagged', 'flags', 'notes'],
|
|
787
|
+
'lp-full': ['name', 'shortName', 'start', 'people', 'documentSlugs', 'fundsInvested', 'contact', 'distributions', 'k1', 'entered', 'status', 'flagged', 'flags', 'notes'],
|
|
788
|
+
'lp-names': ['name', 'shortName', 'flagged', 'flags'],
|
|
753
789
|
'none': []
|
|
754
790
|
},
|
|
755
791
|
writeFilter: {
|
|
756
|
-
'admin': ['name', 'shortName', 'start', 'people', 'documentSlugs', 'fundsInvested', 'contact', 'distributions', 'k1', 'entered', 'status', 'flagged', 'notes'],
|
|
757
|
-
'lp-full': ['name', 'shortName', 'start', 'people', 'documentSlugs', 'fundsInvested', 'contact', 'distributions', 'k1', 'entered', 'status', 'flagged', 'notes'],
|
|
758
|
-
'lp-names': ['flagged'],
|
|
792
|
+
'admin': ['name', 'shortName', 'start', 'people', 'documentSlugs', 'fundsInvested', 'contact', 'distributions', 'k1', 'entered', 'status', 'flagged', 'flags', 'notes'],
|
|
793
|
+
'lp-full': ['name', 'shortName', 'start', 'people', 'documentSlugs', 'fundsInvested', 'contact', 'distributions', 'k1', 'entered', 'status', 'flagged', 'flags', 'notes'],
|
|
794
|
+
'lp-names': ['flagged', 'flags'],
|
|
759
795
|
'none': []
|
|
760
796
|
},
|
|
761
797
|
defaultFilterRole: 'none', // default to no read or write
|
|
@@ -765,7 +801,7 @@ module.exports = function(mongoose, config) {
|
|
|
765
801
|
|
|
766
802
|
//////////////////////////////
|
|
767
803
|
|
|
768
|
-
LimitedPartner.set('autoIndex',
|
|
804
|
+
LimitedPartner.set('autoIndex', false);
|
|
769
805
|
LimitedPartner.on('index', function(err) { console.log('error building limited partner indexes: ' + err); });
|
|
770
806
|
|
|
771
807
|
LimitedPartner.set('toJSON', { virtuals: true });
|
package/lib/Organization.js
CHANGED
|
@@ -8,6 +8,7 @@ module.exports = function(mongoose, config) {
|
|
|
8
8
|
async = require('async'),
|
|
9
9
|
utils = require('@dhyasama/ffvc-utilities'),
|
|
10
10
|
Schema = mongoose.Schema,
|
|
11
|
+
Flag = mongoose.model('Flag'),
|
|
11
12
|
Note = mongoose.model('Note'),
|
|
12
13
|
|
|
13
14
|
customerFunds = [],
|
|
@@ -83,6 +84,8 @@ module.exports = function(mongoose, config) {
|
|
|
83
84
|
resolved: { type: Boolean, default: false }
|
|
84
85
|
},
|
|
85
86
|
|
|
87
|
+
flags: [ { type: Schema.ObjectId, ref: 'Flag' } ],
|
|
88
|
+
|
|
86
89
|
merged: [{ type: Schema.ObjectId, ref: 'Organization' }],
|
|
87
90
|
|
|
88
91
|
deleted: { type: Boolean, default: false },
|
|
@@ -547,6 +550,15 @@ module.exports = function(mongoose, config) {
|
|
|
547
550
|
// Statics query the entire collection
|
|
548
551
|
//////////////////////////////////////////////////////
|
|
549
552
|
|
|
553
|
+
Organization.statics.addFlag = function(organizationId, creatorPersonId, text, cb) {
|
|
554
|
+
|
|
555
|
+
Flag.createForModel({
|
|
556
|
+
createdBy: creatorPersonId,
|
|
557
|
+
text: text
|
|
558
|
+
}, this, organizationId, cb);
|
|
559
|
+
|
|
560
|
+
};
|
|
561
|
+
|
|
550
562
|
Organization.statics.addNote = function(organizationId, creatorPersonId, text, cb) {
|
|
551
563
|
|
|
552
564
|
Note.createForModel({
|
|
@@ -556,6 +568,27 @@ module.exports = function(mongoose, config) {
|
|
|
556
568
|
|
|
557
569
|
};
|
|
558
570
|
|
|
571
|
+
Organization.statics.deleteFlag = function(flagId, cb) {
|
|
572
|
+
|
|
573
|
+
// Delete the flag itself along with reference
|
|
574
|
+
|
|
575
|
+
var self = this;
|
|
576
|
+
|
|
577
|
+
var removeReferences = function removeReferences(callback) {
|
|
578
|
+
self.update({}, {
|
|
579
|
+
$pull: { 'flags' : [flagId] }
|
|
580
|
+
}, callback);
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
async.series([
|
|
584
|
+
Flag.delete.bind(Flag, flagId),
|
|
585
|
+
removeReferences
|
|
586
|
+
], function(err, results) {
|
|
587
|
+
return cb(err, null);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
};
|
|
591
|
+
|
|
559
592
|
Organization.statics.deleteNote = function(noteId, cb) {
|
|
560
593
|
|
|
561
594
|
// Delete the note itself along with any references
|
|
@@ -786,21 +819,46 @@ module.exports = function(mongoose, config) {
|
|
|
786
819
|
|
|
787
820
|
};
|
|
788
821
|
|
|
822
|
+
Organization.statics.getFlags = function getFlags(orgid, cb) {
|
|
823
|
+
|
|
824
|
+
var self = this;
|
|
825
|
+
var query = self.findById(orgid)
|
|
826
|
+
|
|
827
|
+
query.select('flags')
|
|
828
|
+
query.populate({
|
|
829
|
+
path: 'flags',
|
|
830
|
+
match: { customer: config.CUSTOMER_ID }
|
|
831
|
+
})
|
|
832
|
+
query.deepPopulate([
|
|
833
|
+
'flags.createdBy'
|
|
834
|
+
], {
|
|
835
|
+
populate: {
|
|
836
|
+
'flags.createdBy': { select: 'name avatarUrl title' }
|
|
837
|
+
}
|
|
838
|
+
})
|
|
839
|
+
query.sort({'createdOn':-1})
|
|
840
|
+
query.exec(cb);
|
|
841
|
+
|
|
842
|
+
};
|
|
843
|
+
|
|
789
844
|
Organization.statics.getNotes = function getNotes(orgid, cb) {
|
|
790
845
|
|
|
791
846
|
var self = this;
|
|
792
847
|
var query = self.findById(orgid)
|
|
793
848
|
|
|
794
|
-
query.select('notes')
|
|
849
|
+
query.select('notes people.person')
|
|
850
|
+
query.populate('people.person', 'name avatarUrl title calendarEventSummaries')
|
|
795
851
|
query.populate({
|
|
796
852
|
path: 'notes',
|
|
797
853
|
match: { customer: config.CUSTOMER_ID }
|
|
798
854
|
})
|
|
799
855
|
query.deepPopulate([
|
|
800
|
-
'notes.createdBy'
|
|
856
|
+
'notes.createdBy',
|
|
857
|
+
'people.person.calendarEventSummaries.notes.createdBy'
|
|
801
858
|
], {
|
|
802
859
|
populate: {
|
|
803
|
-
'notes.createdBy': { select: 'name avatarUrl title' }
|
|
860
|
+
'notes.createdBy': { select: 'name avatarUrl title' },
|
|
861
|
+
'people.person.calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title' }
|
|
804
862
|
}
|
|
805
863
|
})
|
|
806
864
|
query.sort({'createdOn':-1})
|
package/lib/Person.js
CHANGED
|
@@ -8,6 +8,7 @@ module.exports = function(mongoose, config) {
|
|
|
8
8
|
|
|
9
9
|
Schema = mongoose.Schema,
|
|
10
10
|
LimitedPartner = mongoose.model('LimitedPartner'),
|
|
11
|
+
Flag = mongoose.model('Flag'),
|
|
11
12
|
Note = mongoose.model('Note'),
|
|
12
13
|
Crypto = require('@dhyasama/ffvc-crypto'),
|
|
13
14
|
crypto = new Crypto({'key': config.crypto.key}),
|
|
@@ -114,6 +115,8 @@ module.exports = function(mongoose, config) {
|
|
|
114
115
|
resolved: { type: Boolean, default: false }
|
|
115
116
|
},
|
|
116
117
|
|
|
118
|
+
flags: [ { type: Schema.ObjectId, ref: 'Flag' } ],
|
|
119
|
+
|
|
117
120
|
merged: [{ type: Schema.ObjectId, ref: 'Person' }],
|
|
118
121
|
|
|
119
122
|
deleted: { type: Boolean, default: false },
|
|
@@ -747,21 +750,45 @@ module.exports = function(mongoose, config) {
|
|
|
747
750
|
.exec(cb);
|
|
748
751
|
};
|
|
749
752
|
|
|
753
|
+
Person.statics.getFlags = function getFlags(personId, cb) {
|
|
754
|
+
|
|
755
|
+
var self = this;
|
|
756
|
+
var query = self.findById(personId)
|
|
757
|
+
|
|
758
|
+
query.select('flags')
|
|
759
|
+
query.populate({
|
|
760
|
+
path: 'flags',
|
|
761
|
+
match: { customer: config.CUSTOMER_ID }
|
|
762
|
+
})
|
|
763
|
+
query.deepPopulate([
|
|
764
|
+
'flags.createdBy'
|
|
765
|
+
], {
|
|
766
|
+
populate: {
|
|
767
|
+
'flags.createdBy': { select: 'name avatarUrl title' }
|
|
768
|
+
}
|
|
769
|
+
})
|
|
770
|
+
query.sort({'createdOn':-1})
|
|
771
|
+
query.exec(cb);
|
|
772
|
+
|
|
773
|
+
};
|
|
774
|
+
|
|
750
775
|
Person.statics.getNotes = function getNotes(personId, cb) {
|
|
751
776
|
|
|
752
777
|
var self = this;
|
|
753
778
|
var query = self.findById(personId)
|
|
754
779
|
|
|
755
|
-
query.select('notes')
|
|
780
|
+
query.select('notes calendarEventSummaries')
|
|
756
781
|
query.populate({
|
|
757
782
|
path: 'notes',
|
|
758
783
|
match: { customer: config.CUSTOMER_ID }
|
|
759
784
|
})
|
|
760
785
|
query.deepPopulate([
|
|
761
|
-
'notes.createdBy'
|
|
786
|
+
'notes.createdBy',
|
|
787
|
+
'calendarEventSummaries.notes.createdBy'
|
|
762
788
|
], {
|
|
763
789
|
populate: {
|
|
764
|
-
'notes.createdBy': { select: 'name avatarUrl title' }
|
|
790
|
+
'notes.createdBy': { select: 'name avatarUrl title' },
|
|
791
|
+
'calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title' }
|
|
765
792
|
}
|
|
766
793
|
})
|
|
767
794
|
query.sort({'createdOn':-1})
|
|
@@ -991,6 +1018,15 @@ module.exports = function(mongoose, config) {
|
|
|
991
1018
|
|
|
992
1019
|
};
|
|
993
1020
|
|
|
1021
|
+
Person.statics.addFlag = function(personId, creatorPersonId, text, cb) {
|
|
1022
|
+
|
|
1023
|
+
Flag.createForModel({
|
|
1024
|
+
createdBy: creatorPersonId,
|
|
1025
|
+
text: text
|
|
1026
|
+
}, this, personId, cb);
|
|
1027
|
+
|
|
1028
|
+
};
|
|
1029
|
+
|
|
994
1030
|
Person.statics.addNote = function(personId, creatorPersonId, text, cb) {
|
|
995
1031
|
|
|
996
1032
|
Note.createForModel({
|
|
@@ -1000,6 +1036,27 @@ module.exports = function(mongoose, config) {
|
|
|
1000
1036
|
|
|
1001
1037
|
};
|
|
1002
1038
|
|
|
1039
|
+
Person.statics.deleteFlag = function(flagId, cb) {
|
|
1040
|
+
|
|
1041
|
+
// Delete the flag itself along with reference on person
|
|
1042
|
+
|
|
1043
|
+
var self = this;
|
|
1044
|
+
|
|
1045
|
+
var removeReference = function removeReference(callback) {
|
|
1046
|
+
self.update({}, {
|
|
1047
|
+
$pull: { 'flags' : [flagId] }
|
|
1048
|
+
}, callback);
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
async.series([
|
|
1052
|
+
Flag.delete.bind(Flag, flagId),
|
|
1053
|
+
removeReference
|
|
1054
|
+
], function(err, results) {
|
|
1055
|
+
return cb(err, null);
|
|
1056
|
+
});
|
|
1057
|
+
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1003
1060
|
Person.statics.deleteNote = function(noteId, cb) {
|
|
1004
1061
|
|
|
1005
1062
|
// Delete the note itself along with any references on people
|
|
@@ -1104,6 +1161,13 @@ module.exports = function(mongoose, config) {
|
|
|
1104
1161
|
var self = this;
|
|
1105
1162
|
var CUSTOMER_ID = config.CUSTOMER_ID;
|
|
1106
1163
|
|
|
1164
|
+
// if (self._id.toString() == '5637a9cc281347cc0bc17518') {
|
|
1165
|
+
// console.log(self);
|
|
1166
|
+
// console.log(JSON.stringify(_.find(self.calendarEventSummaries, function(item) {
|
|
1167
|
+
// return item.calendarEventId == '5a81bf645359aef7ff13bfcd';
|
|
1168
|
+
// }), null, 2));
|
|
1169
|
+
// }
|
|
1170
|
+
|
|
1107
1171
|
var protectCalendarEventData = function protectCalendarEventData(person) {
|
|
1108
1172
|
|
|
1109
1173
|
if (CUSTOMER_ID == 'GLOBAL_PROCESS') return;
|
package/package.json
CHANGED
package/test/Flag.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var
|
|
4
|
+
|
|
5
|
+
should = require("should"),
|
|
6
|
+
config = require('./config')['test'],
|
|
7
|
+
_ = require('underscore'),
|
|
8
|
+
mongoose = require('mongoose'),
|
|
9
|
+
clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
|
|
10
|
+
LimitedPartner = mongoose.model('LimitedPartner'),
|
|
11
|
+
Flag = mongoose.model('Flag'),
|
|
12
|
+
Organization = mongoose.model('Organization'),
|
|
13
|
+
Person = mongoose.model('Person');
|
|
14
|
+
|
|
15
|
+
var lp, org, person, person2, person3, person4, flagCreator;
|
|
16
|
+
var accountId = new mongoose.Types.ObjectId();
|
|
17
|
+
var flagId;
|
|
18
|
+
|
|
19
|
+
describe('Flag', function() {
|
|
20
|
+
|
|
21
|
+
before(function(done) {
|
|
22
|
+
if (mongoose.connection.db) return done();
|
|
23
|
+
mongoose.connect(config.db.uri, done);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
before(function(done) {
|
|
27
|
+
clearDB(done);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
before(function(done) {
|
|
31
|
+
|
|
32
|
+
lp = new LimitedPartner();
|
|
33
|
+
lp.name = 'Big LP';
|
|
34
|
+
lp.slug = 'big-lp';
|
|
35
|
+
|
|
36
|
+
LimitedPartner.upsert(lp, 'test', 'lp-full', function(err, result) {
|
|
37
|
+
|
|
38
|
+
should.not.exist(err);
|
|
39
|
+
should.exist(result);
|
|
40
|
+
lp = result;
|
|
41
|
+
|
|
42
|
+
return done();
|
|
43
|
+
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
before(function(done) {
|
|
49
|
+
|
|
50
|
+
org = new Organization();
|
|
51
|
+
org.name = 'Big Org';
|
|
52
|
+
org.slug = 'big-org';
|
|
53
|
+
|
|
54
|
+
Organization.upsert(org, 'test', function(err, result) {
|
|
55
|
+
|
|
56
|
+
should.not.exist(err);
|
|
57
|
+
should.exist(result);
|
|
58
|
+
org = result;
|
|
59
|
+
|
|
60
|
+
return done();
|
|
61
|
+
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
before(function(done) {
|
|
67
|
+
|
|
68
|
+
person = new Person();
|
|
69
|
+
person.name = {
|
|
70
|
+
'first': 'Big',
|
|
71
|
+
'last': 'Person'
|
|
72
|
+
};
|
|
73
|
+
person.slug = 'big-person';
|
|
74
|
+
|
|
75
|
+
Person.upsert(person, 'test', function(err, result) {
|
|
76
|
+
|
|
77
|
+
should.not.exist(err);
|
|
78
|
+
should.exist(result);
|
|
79
|
+
person = result;
|
|
80
|
+
|
|
81
|
+
return done();
|
|
82
|
+
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
before(function(done) {
|
|
88
|
+
|
|
89
|
+
person2 = new Person();
|
|
90
|
+
person2.name = {
|
|
91
|
+
'first': 'Another',
|
|
92
|
+
'last': 'Girl'
|
|
93
|
+
};
|
|
94
|
+
person2.slug = 'another-girl';
|
|
95
|
+
|
|
96
|
+
Person.upsert(person2, 'test', function(err, result) {
|
|
97
|
+
|
|
98
|
+
should.not.exist(err);
|
|
99
|
+
should.exist(result);
|
|
100
|
+
person2 = result;
|
|
101
|
+
|
|
102
|
+
return done();
|
|
103
|
+
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
before(function(done) {
|
|
109
|
+
|
|
110
|
+
person3 = new Person();
|
|
111
|
+
person3.name = {
|
|
112
|
+
'first': 'Different',
|
|
113
|
+
'last': 'Guy'
|
|
114
|
+
};
|
|
115
|
+
person3.slug = 'different-guy';
|
|
116
|
+
|
|
117
|
+
Person.upsert(person3, 'test', function(err, result) {
|
|
118
|
+
|
|
119
|
+
should.not.exist(err);
|
|
120
|
+
should.exist(result);
|
|
121
|
+
person3 = result;
|
|
122
|
+
|
|
123
|
+
return done();
|
|
124
|
+
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
before(function(done) {
|
|
130
|
+
|
|
131
|
+
person4 = new Person();
|
|
132
|
+
person4.name = {
|
|
133
|
+
'first': 'Lady',
|
|
134
|
+
'last': 'Marmaduke'
|
|
135
|
+
};
|
|
136
|
+
person4.slug = 'lady-marmaduke';
|
|
137
|
+
|
|
138
|
+
Person.upsert(person4, 'test', function(err, result) {
|
|
139
|
+
|
|
140
|
+
should.not.exist(err);
|
|
141
|
+
should.exist(result);
|
|
142
|
+
person4 = result;
|
|
143
|
+
|
|
144
|
+
return done();
|
|
145
|
+
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
before(function(done) {
|
|
151
|
+
|
|
152
|
+
flagCreator = new Person();
|
|
153
|
+
flagCreator.name = {
|
|
154
|
+
'first': 'George',
|
|
155
|
+
'last': 'Michael'
|
|
156
|
+
};
|
|
157
|
+
flagCreator.slug = 'george-michael';
|
|
158
|
+
|
|
159
|
+
Person.upsert(flagCreator, 'test', function(err, result) {
|
|
160
|
+
|
|
161
|
+
should.not.exist(err);
|
|
162
|
+
should.exist(result);
|
|
163
|
+
flagCreator = result;
|
|
164
|
+
|
|
165
|
+
return done();
|
|
166
|
+
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('creates a flag for an organization', function(done) {
|
|
172
|
+
|
|
173
|
+
Flag.createForModel({
|
|
174
|
+
createdBy: flagCreator,
|
|
175
|
+
text: 'Best flag ever!'
|
|
176
|
+
}, Organization, org._id, function(err, result) {
|
|
177
|
+
|
|
178
|
+
should.not.exist(err);
|
|
179
|
+
should.exist(result);
|
|
180
|
+
should.exist(result.flag);
|
|
181
|
+
should.exist(result.addedTo);
|
|
182
|
+
result.addedTo.flags.length.should.equal(1);
|
|
183
|
+
|
|
184
|
+
flagId = result.addedTo.flags[0];
|
|
185
|
+
|
|
186
|
+
return done();
|
|
187
|
+
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('creates a flag for a limited partner', function(done) {
|
|
193
|
+
|
|
194
|
+
Flag.createForModel({
|
|
195
|
+
createdBy: flagCreator,
|
|
196
|
+
text: 'Best flag ever!'
|
|
197
|
+
}, LimitedPartner, lp._id, function(err, result) {
|
|
198
|
+
|
|
199
|
+
should.not.exist(err);
|
|
200
|
+
should.exist(result);
|
|
201
|
+
should.exist(result.flag);
|
|
202
|
+
should.exist(result.addedTo);
|
|
203
|
+
result.addedTo.flags.length.should.equal(1);
|
|
204
|
+
|
|
205
|
+
return done();
|
|
206
|
+
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('creates a flag for a person', function(done) {
|
|
212
|
+
|
|
213
|
+
Flag.createForModel({
|
|
214
|
+
createdBy: flagCreator,
|
|
215
|
+
text: 'Best flag ever!'
|
|
216
|
+
}, Person, person._id, function(err, result) {
|
|
217
|
+
|
|
218
|
+
should.not.exist(err);
|
|
219
|
+
should.exist(result);
|
|
220
|
+
should.exist(result.flag);
|
|
221
|
+
should.exist(result.addedTo);
|
|
222
|
+
result.addedTo.flags.length.should.equal(1);
|
|
223
|
+
|
|
224
|
+
return done();
|
|
225
|
+
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('gets a flag by id', function(done) {
|
|
231
|
+
Flag.getById(flagId, function(err, result) {
|
|
232
|
+
should.not.exist(err);
|
|
233
|
+
should.exist(result);
|
|
234
|
+
result.text.should.equal('Best flag ever!');
|
|
235
|
+
return done();
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('deletes a flag', function(done) {
|
|
240
|
+
Flag.delete(flagId, function(err, result) {
|
|
241
|
+
should.not.exist(err);
|
|
242
|
+
should.exist(result);
|
|
243
|
+
return done();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
});
|
package/test/Organization.js
CHANGED
|
@@ -13,6 +13,7 @@ var
|
|
|
13
13
|
var person, person1, person2;
|
|
14
14
|
var noteId;
|
|
15
15
|
var eventNote;
|
|
16
|
+
var flagId;
|
|
16
17
|
|
|
17
18
|
describe('Organization', function() {
|
|
18
19
|
|
|
@@ -699,6 +700,36 @@ describe('Organization', function() {
|
|
|
699
700
|
});
|
|
700
701
|
});
|
|
701
702
|
|
|
703
|
+
it('adds a flag', function(done) {
|
|
704
|
+
|
|
705
|
+
Organization.addFlag(org4.id, person._id, 'Sweet flag bro!', function(err, result) {
|
|
706
|
+
|
|
707
|
+
should.not.exist(err);
|
|
708
|
+
should.exist(result);
|
|
709
|
+
should.exist(result.flag);
|
|
710
|
+
should.exist(result.addedTo);
|
|
711
|
+
result.addedTo.flags.length.should.equal(1);
|
|
712
|
+
|
|
713
|
+
flagId = result.addedTo.flags[0];
|
|
714
|
+
|
|
715
|
+
return done();
|
|
716
|
+
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
it('deletes a flag', function(done) {
|
|
722
|
+
|
|
723
|
+
Organization.deleteFlag(flagId, function(err, result) {
|
|
724
|
+
|
|
725
|
+
should.not.exist(err);
|
|
726
|
+
|
|
727
|
+
return done();
|
|
728
|
+
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
});
|
|
732
|
+
|
|
702
733
|
it('adds a note', function(done) {
|
|
703
734
|
|
|
704
735
|
Organization.addNote(org4.id, person._id, 'Sweet note bro!', function(err, result) {
|