@dhyasama/totem-models 1.19.0 → 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 +65 -13
- package/lib/Person.js +67 -6
- package/package.json +1 -1
- package/test/Flag.js +247 -0
- package/test/Organization.js +25 -14
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
|
|
@@ -608,7 +641,6 @@ module.exports = function(mongoose, config) {
|
|
|
608
641
|
.find({ '_id': { $in : ids }})
|
|
609
642
|
.populate('people.person', 'name avatarUrl title calendarEventSummaries sources')
|
|
610
643
|
.populate('related', 'name logoUrl')
|
|
611
|
-
.populate('notes')
|
|
612
644
|
.populate('chairs.first', 'name avatarUrl title')
|
|
613
645
|
.populate('chairs.second', 'name avatarUrl title')
|
|
614
646
|
.populate('funds', 'name hexColorCode')
|
|
@@ -616,15 +648,13 @@ module.exports = function(mongoose, config) {
|
|
|
616
648
|
'people.person.sources.person',
|
|
617
649
|
'people.person.calendarEventSummaries.attendees.internal',
|
|
618
650
|
'people.person.calendarEventSummaries.attendees.external',
|
|
619
|
-
'people.person.calendarEventSummaries.notes.createdBy'
|
|
620
|
-
'notes.createdBy'
|
|
651
|
+
'people.person.calendarEventSummaries.notes.createdBy'
|
|
621
652
|
], {
|
|
622
653
|
populate: {
|
|
623
654
|
'people.person.sources.person': { select: 'name avatarUrl title' },
|
|
624
655
|
'people.person.calendarEventSummaries.attendees.internal': { select: 'name avatarUrl title' },
|
|
625
656
|
'people.person.calendarEventSummaries.attendees.external': { select: 'name avatarUrl title' },
|
|
626
|
-
'people.person.calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title' }
|
|
627
|
-
'notes.createdBy': { select: 'name avatarUrl title' }
|
|
657
|
+
'people.person.calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title' }
|
|
628
658
|
}
|
|
629
659
|
})
|
|
630
660
|
.exec(cb);
|
|
@@ -750,7 +780,6 @@ module.exports = function(mongoose, config) {
|
|
|
750
780
|
.findById(id)
|
|
751
781
|
.populate('people.person', 'name avatarUrl title calendarEventSummaries sources')
|
|
752
782
|
.populate('related', 'name logoUrl')
|
|
753
|
-
.populate('notes')
|
|
754
783
|
.populate('chairs.first', 'name avatarUrl title')
|
|
755
784
|
.populate('chairs.second', 'name avatarUrl title')
|
|
756
785
|
.populate('funds', 'name hexColorCode closeDate')
|
|
@@ -761,15 +790,13 @@ module.exports = function(mongoose, config) {
|
|
|
761
790
|
'people.person.sources.person',
|
|
762
791
|
'people.person.calendarEventSummaries.attendees.internal',
|
|
763
792
|
'people.person.calendarEventSummaries.attendees.external',
|
|
764
|
-
'people.person.calendarEventSummaries.notes.createdBy'
|
|
765
|
-
'notes.createdBy'
|
|
793
|
+
'people.person.calendarEventSummaries.notes.createdBy'
|
|
766
794
|
], {
|
|
767
795
|
populate: {
|
|
768
796
|
'people.person.sources.person': { select: 'name avatarUrl title' },
|
|
769
797
|
'people.person.calendarEventSummaries.attendees.internal': { select: 'name avatarUrl title' },
|
|
770
798
|
'people.person.calendarEventSummaries.attendees.external': { select: 'name avatarUrl title' },
|
|
771
|
-
'people.person.calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title' }
|
|
772
|
-
'notes.createdBy': { select: 'name avatarUrl title' }
|
|
799
|
+
'people.person.calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title' }
|
|
773
800
|
}
|
|
774
801
|
})
|
|
775
802
|
.exec(cb);
|
|
@@ -792,21 +819,46 @@ module.exports = function(mongoose, config) {
|
|
|
792
819
|
|
|
793
820
|
};
|
|
794
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
|
+
|
|
795
844
|
Organization.statics.getNotes = function getNotes(orgid, cb) {
|
|
796
845
|
|
|
797
846
|
var self = this;
|
|
798
847
|
var query = self.findById(orgid)
|
|
799
848
|
|
|
800
|
-
query.select('notes')
|
|
849
|
+
query.select('notes people.person')
|
|
850
|
+
query.populate('people.person', 'name avatarUrl title calendarEventSummaries')
|
|
801
851
|
query.populate({
|
|
802
852
|
path: 'notes',
|
|
803
853
|
match: { customer: config.CUSTOMER_ID }
|
|
804
854
|
})
|
|
805
855
|
query.deepPopulate([
|
|
806
|
-
'notes.createdBy'
|
|
856
|
+
'notes.createdBy',
|
|
857
|
+
'people.person.calendarEventSummaries.notes.createdBy'
|
|
807
858
|
], {
|
|
808
859
|
populate: {
|
|
809
|
-
'notes.createdBy': { select: 'name avatarUrl title' }
|
|
860
|
+
'notes.createdBy': { select: 'name avatarUrl title' },
|
|
861
|
+
'people.person.calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title' }
|
|
810
862
|
}
|
|
811
863
|
})
|
|
812
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 },
|
|
@@ -703,15 +706,12 @@ module.exports = function(mongoose, config) {
|
|
|
703
706
|
.populate('calendarEventSummaries.attendees.external', 'avatarUrl name title')
|
|
704
707
|
.populate('calendarEventSummaries.attendees.internal', 'avatarUrl name title')
|
|
705
708
|
.populate('calendarEventSummaries.notes')
|
|
706
|
-
.populate('notes')
|
|
707
709
|
.populate('related')
|
|
708
710
|
.populate('sources.person', 'avatarUrl name title')
|
|
709
711
|
.deepPopulate([
|
|
710
|
-
'notes.createdBy',
|
|
711
712
|
'calendarEventSummaries.notes.createdBy'
|
|
712
713
|
], {
|
|
713
714
|
populate: {
|
|
714
|
-
'notes.createdBy': {select: 'avatarUrl name'},
|
|
715
715
|
'calendarEventSummaries.notes.createdBy': { select: 'avatarUrl name' }
|
|
716
716
|
}
|
|
717
717
|
})
|
|
@@ -750,21 +750,45 @@ module.exports = function(mongoose, config) {
|
|
|
750
750
|
.exec(cb);
|
|
751
751
|
};
|
|
752
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
|
+
|
|
753
775
|
Person.statics.getNotes = function getNotes(personId, cb) {
|
|
754
776
|
|
|
755
777
|
var self = this;
|
|
756
778
|
var query = self.findById(personId)
|
|
757
779
|
|
|
758
|
-
query.select('notes')
|
|
780
|
+
query.select('notes calendarEventSummaries')
|
|
759
781
|
query.populate({
|
|
760
782
|
path: 'notes',
|
|
761
783
|
match: { customer: config.CUSTOMER_ID }
|
|
762
784
|
})
|
|
763
785
|
query.deepPopulate([
|
|
764
|
-
'notes.createdBy'
|
|
786
|
+
'notes.createdBy',
|
|
787
|
+
'calendarEventSummaries.notes.createdBy'
|
|
765
788
|
], {
|
|
766
789
|
populate: {
|
|
767
|
-
'notes.createdBy': { select: 'name avatarUrl title' }
|
|
790
|
+
'notes.createdBy': { select: 'name avatarUrl title' },
|
|
791
|
+
'calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title' }
|
|
768
792
|
}
|
|
769
793
|
})
|
|
770
794
|
query.sort({'createdOn':-1})
|
|
@@ -994,6 +1018,15 @@ module.exports = function(mongoose, config) {
|
|
|
994
1018
|
|
|
995
1019
|
};
|
|
996
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
|
+
|
|
997
1030
|
Person.statics.addNote = function(personId, creatorPersonId, text, cb) {
|
|
998
1031
|
|
|
999
1032
|
Note.createForModel({
|
|
@@ -1003,6 +1036,27 @@ module.exports = function(mongoose, config) {
|
|
|
1003
1036
|
|
|
1004
1037
|
};
|
|
1005
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
|
+
|
|
1006
1060
|
Person.statics.deleteNote = function(noteId, cb) {
|
|
1007
1061
|
|
|
1008
1062
|
// Delete the note itself along with any references on people
|
|
@@ -1107,6 +1161,13 @@ module.exports = function(mongoose, config) {
|
|
|
1107
1161
|
var self = this;
|
|
1108
1162
|
var CUSTOMER_ID = config.CUSTOMER_ID;
|
|
1109
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
|
+
|
|
1110
1171
|
var protectCalendarEventData = function protectCalendarEventData(person) {
|
|
1111
1172
|
|
|
1112
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,17 +700,29 @@ describe('Organization', function() {
|
|
|
699
700
|
});
|
|
700
701
|
});
|
|
701
702
|
|
|
702
|
-
it('adds a
|
|
703
|
+
it('adds a flag', function(done) {
|
|
703
704
|
|
|
704
|
-
Organization.
|
|
705
|
+
Organization.addFlag(org4.id, person._id, 'Sweet flag bro!', function(err, result) {
|
|
705
706
|
|
|
706
707
|
should.not.exist(err);
|
|
707
708
|
should.exist(result);
|
|
708
|
-
should.exist(result.
|
|
709
|
+
should.exist(result.flag);
|
|
709
710
|
should.exist(result.addedTo);
|
|
710
|
-
result.addedTo.
|
|
711
|
+
result.addedTo.flags.length.should.equal(1);
|
|
711
712
|
|
|
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);
|
|
713
726
|
|
|
714
727
|
return done();
|
|
715
728
|
|
|
@@ -717,19 +730,17 @@ describe('Organization', function() {
|
|
|
717
730
|
|
|
718
731
|
});
|
|
719
732
|
|
|
720
|
-
it('
|
|
733
|
+
it('adds a note', function(done) {
|
|
721
734
|
|
|
722
|
-
Organization.
|
|
735
|
+
Organization.addNote(org4.id, person._id, 'Sweet note bro!', function(err, result) {
|
|
723
736
|
|
|
724
737
|
should.not.exist(err);
|
|
725
738
|
should.exist(result);
|
|
726
|
-
|
|
727
|
-
should.exist(result.
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
should.exist(result.notes[0].createdBy.name.first);
|
|
732
|
-
result.notes[0].createdBy.name.first.length.should.be.above(0);
|
|
739
|
+
should.exist(result.note);
|
|
740
|
+
should.exist(result.addedTo);
|
|
741
|
+
result.addedTo.notes.length.should.equal(1);
|
|
742
|
+
|
|
743
|
+
noteId = result.addedTo.notes[0];
|
|
733
744
|
|
|
734
745
|
return done();
|
|
735
746
|
|