@dhyasama/totem-models 11.76.0 → 11.78.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/LimitedPartner.js +2 -71
- package/lib/Note.js +12 -5
- package/lib/Organization.js +2 -80
- package/lib/Person.js +2 -49
- package/package.json +1 -1
package/lib/LimitedPartner.js
CHANGED
|
@@ -5,7 +5,6 @@ module.exports = function(mongoose, config) {
|
|
|
5
5
|
let
|
|
6
6
|
|
|
7
7
|
Schema = mongoose.Schema,
|
|
8
|
-
Flag = mongoose.model('Flag'),
|
|
9
8
|
Note = mongoose.model('Note'),
|
|
10
9
|
Organization = mongoose.model('Organization'),
|
|
11
10
|
_ = require('underscore'),
|
|
@@ -328,45 +327,8 @@ module.exports = function(mongoose, config) {
|
|
|
328
327
|
|
|
329
328
|
////////////////////////
|
|
330
329
|
|
|
331
|
-
LimitedPartner.statics.
|
|
332
|
-
|
|
333
|
-
Flag.createForModel({
|
|
334
|
-
createdBy: creatorPersonId,
|
|
335
|
-
text: text,
|
|
336
|
-
customer: customerId
|
|
337
|
-
}, this, lpid, cb);
|
|
338
|
-
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
LimitedPartner.statics.addNote = function(lpid, creatorPersonId, text, customerId, cb) {
|
|
342
|
-
|
|
343
|
-
Note.createForModel({
|
|
344
|
-
createdBy: creatorPersonId,
|
|
345
|
-
text: text,
|
|
346
|
-
customer: customerId
|
|
347
|
-
}, this, lpid, cb);
|
|
348
|
-
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
LimitedPartner.statics.deleteFlag = function(flagId, cb) {
|
|
352
|
-
|
|
353
|
-
// Delete the flag itself along with any references
|
|
354
|
-
|
|
355
|
-
const self = this;
|
|
356
|
-
|
|
357
|
-
let removeReferences = function removeReferences(callback) {
|
|
358
|
-
self.updateOne({}, {
|
|
359
|
-
$pull: { 'flags' : [flagId] }
|
|
360
|
-
}, callback);
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
async.series([
|
|
364
|
-
Flag.delete.bind(Flag, flagId),
|
|
365
|
-
removeReferences
|
|
366
|
-
], function(err, results) {
|
|
367
|
-
return cb(err, null);
|
|
368
|
-
});
|
|
369
|
-
|
|
330
|
+
LimitedPartner.statics.addNote = function(lpid, note, cb) {
|
|
331
|
+
Note.createForModel(this, lpId, note, cb);
|
|
370
332
|
};
|
|
371
333
|
|
|
372
334
|
LimitedPartner.statics.deleteNote = function(noteId, customerId, cb) {
|
|
@@ -553,37 +515,6 @@ module.exports = function(mongoose, config) {
|
|
|
553
515
|
|
|
554
516
|
};
|
|
555
517
|
|
|
556
|
-
LimitedPartner.statics.getFlags = function getFlags(lpid, options, cb) {
|
|
557
|
-
|
|
558
|
-
const self = this;
|
|
559
|
-
|
|
560
|
-
if (!cb) { throw new Error('cb is required'); }
|
|
561
|
-
if (!lpid) { return cb(new Error('lpid is required'), null); }
|
|
562
|
-
if (!mongoose.Types.ObjectId.isValid(lpid)) { return cb(new Error('lpid is not a valid ObjectId'), null); }
|
|
563
|
-
if (!options) { return cb(new Error('options is required'), null); }
|
|
564
|
-
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
565
|
-
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
566
|
-
|
|
567
|
-
let query = self.findOne({ '_id': lpid, customer: options.CUSTOMER_ID });
|
|
568
|
-
|
|
569
|
-
query.select('flags');
|
|
570
|
-
query.populate({
|
|
571
|
-
path: 'flags',
|
|
572
|
-
match: { customer: options.CUSTOMER_ID },
|
|
573
|
-
options: { sort: { createdOn: -1 } }
|
|
574
|
-
});
|
|
575
|
-
query.deepPopulate([
|
|
576
|
-
'flags.createdBy',
|
|
577
|
-
], {
|
|
578
|
-
populate: {
|
|
579
|
-
'flags.createdBy': { select: 'name avatarUrl title' }
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
query.exec(cb);
|
|
584
|
-
|
|
585
|
-
};
|
|
586
|
-
|
|
587
518
|
LimitedPartner.statics.getNotes = function getNotes(lpid, options, cb) {
|
|
588
519
|
|
|
589
520
|
const self = this;
|
package/lib/Note.js
CHANGED
|
@@ -15,7 +15,16 @@ module.exports = function(mongoose, config) {
|
|
|
15
15
|
|
|
16
16
|
createdBy: { type: Schema.ObjectId, ref: 'Person', index: false, required: true },
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
title: { type: String, index: false, required: false, trim: true },
|
|
19
|
+
|
|
20
|
+
text: { type: String, index: false, required: true, trim: true },
|
|
21
|
+
|
|
22
|
+
analysis: {
|
|
23
|
+
insights: [{
|
|
24
|
+
text: { type: String },
|
|
25
|
+
category: { type: String, enum: ['highlight', 'lowlight', 'goal', 'ask'] }
|
|
26
|
+
}]
|
|
27
|
+
}
|
|
19
28
|
|
|
20
29
|
});
|
|
21
30
|
|
|
@@ -47,13 +56,13 @@ module.exports = function(mongoose, config) {
|
|
|
47
56
|
|
|
48
57
|
};
|
|
49
58
|
|
|
50
|
-
Note.statics.createForModel = function(
|
|
59
|
+
Note.statics.createForModel = function(Model, modelId, note, cb) {
|
|
51
60
|
|
|
52
61
|
if (!cb) { throw new Error('cb is required'); }
|
|
53
|
-
if (!note) { return cb(new Error('note is required'), null); }
|
|
54
62
|
if (!Model) { return cb(new Error('Model is required'), null); }
|
|
55
63
|
if (!modelId) { return cb(new Error('modelId is required'), null); }
|
|
56
64
|
if (!mongoose.Types.ObjectId.isValid(modelId)) { return cb(new Error('modelId is not a valid ObjectId'), null); }
|
|
65
|
+
if (!note) { return cb(new Error('note is required'), null); }
|
|
57
66
|
|
|
58
67
|
const self = this;
|
|
59
68
|
|
|
@@ -67,8 +76,6 @@ module.exports = function(mongoose, config) {
|
|
|
67
76
|
});
|
|
68
77
|
};
|
|
69
78
|
|
|
70
|
-
note.createdOn = new Date();
|
|
71
|
-
|
|
72
79
|
self.create(note, addToModel);
|
|
73
80
|
|
|
74
81
|
};
|
package/lib/Organization.js
CHANGED
|
@@ -9,7 +9,6 @@ module.exports = function(mongoose, config) {
|
|
|
9
9
|
utilities = require('@dhyasama/totem-utilities'),
|
|
10
10
|
helpers = require('../helpers'),
|
|
11
11
|
Schema = mongoose.Schema,
|
|
12
|
-
Flag = mongoose.model('Flag'),
|
|
13
12
|
Note = mongoose.model('Note'),
|
|
14
13
|
|
|
15
14
|
Organization = new Schema({
|
|
@@ -1039,45 +1038,8 @@ module.exports = function(mongoose, config) {
|
|
|
1039
1038
|
// Statics query the entire collection
|
|
1040
1039
|
//////////////////////////////////////////////////////
|
|
1041
1040
|
|
|
1042
|
-
Organization.statics.
|
|
1043
|
-
|
|
1044
|
-
Flag.createForModel({
|
|
1045
|
-
createdBy: creatorPersonId,
|
|
1046
|
-
text: text,
|
|
1047
|
-
customer: customerId
|
|
1048
|
-
}, this, orgId, cb);
|
|
1049
|
-
|
|
1050
|
-
};
|
|
1051
|
-
|
|
1052
|
-
Organization.statics.addNote = function(organizationId, creatorPersonId, text, customerId, cb) {
|
|
1053
|
-
|
|
1054
|
-
Note.createForModel({
|
|
1055
|
-
createdBy: creatorPersonId,
|
|
1056
|
-
text: text,
|
|
1057
|
-
customer: customerId
|
|
1058
|
-
}, this, organizationId, cb);
|
|
1059
|
-
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
Organization.statics.deleteFlag = function(flagId, cb) {
|
|
1063
|
-
|
|
1064
|
-
// Delete the flag itself along with reference
|
|
1065
|
-
|
|
1066
|
-
const self = this;
|
|
1067
|
-
|
|
1068
|
-
let removeReferences = function removeReferences(callback) {
|
|
1069
|
-
self.updateMany({}, {
|
|
1070
|
-
$pull: { 'flags' : [flagId] }
|
|
1071
|
-
}, callback);
|
|
1072
|
-
};
|
|
1073
|
-
|
|
1074
|
-
async.series([
|
|
1075
|
-
Flag.delete.bind(Flag, flagId),
|
|
1076
|
-
removeReferences
|
|
1077
|
-
], function(err, results) {
|
|
1078
|
-
return cb(err, null);
|
|
1079
|
-
});
|
|
1080
|
-
|
|
1041
|
+
Organization.statics.addNote = function(organizationId, note, cb) {
|
|
1042
|
+
Note.createForModel(this, organizationId, note, cb);
|
|
1081
1043
|
};
|
|
1082
1044
|
|
|
1083
1045
|
Organization.statics.deleteNote = function(noteId, customerId, cb) {
|
|
@@ -1759,46 +1721,6 @@ module.exports = function(mongoose, config) {
|
|
|
1759
1721
|
|
|
1760
1722
|
};
|
|
1761
1723
|
|
|
1762
|
-
Organization.statics.getFlags = function getFlags(orgid, options, cb) {
|
|
1763
|
-
|
|
1764
|
-
const self = this;
|
|
1765
|
-
|
|
1766
|
-
if (!cb) { throw new Error('cb is required'); }
|
|
1767
|
-
if (!orgid) { return cb(new Error('orgid is required'), null); }
|
|
1768
|
-
if (!mongoose.Types.ObjectId.isValid(orgid)) { return cb(new Error('orgid is not a valid ObjectId'), null); }
|
|
1769
|
-
if (!options) { return cb(new Error('options is required'), null); }
|
|
1770
|
-
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
1771
|
-
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
1772
|
-
|
|
1773
|
-
let query = self.findById(orgid);
|
|
1774
|
-
|
|
1775
|
-
query.select('flags');
|
|
1776
|
-
query.populate({
|
|
1777
|
-
path: 'flags',
|
|
1778
|
-
match: { customer: options.CUSTOMER_ID }
|
|
1779
|
-
});
|
|
1780
|
-
query.deepPopulate([
|
|
1781
|
-
'flags.createdBy'
|
|
1782
|
-
], {
|
|
1783
|
-
populate: {
|
|
1784
|
-
'flags.createdBy': { select: 'name avatarUrl title' }
|
|
1785
|
-
}
|
|
1786
|
-
});
|
|
1787
|
-
query.sort({'createdOn':-1});
|
|
1788
|
-
|
|
1789
|
-
query.exec(function(err, org) {
|
|
1790
|
-
|
|
1791
|
-
if (err) { return cb(err, null); }
|
|
1792
|
-
else if (!org) { return cb(null, []); }
|
|
1793
|
-
|
|
1794
|
-
org = helpers.cleanOrg(org, options.CUSTOMER_ID);
|
|
1795
|
-
|
|
1796
|
-
return cb(null, org);
|
|
1797
|
-
|
|
1798
|
-
});
|
|
1799
|
-
|
|
1800
|
-
};
|
|
1801
|
-
|
|
1802
1724
|
Organization.statics.getList = function getList(cb) {
|
|
1803
1725
|
|
|
1804
1726
|
const self = this;
|
package/lib/Person.js
CHANGED
|
@@ -7,7 +7,6 @@ module.exports = function(mongoose, config) {
|
|
|
7
7
|
Schema = mongoose.Schema,
|
|
8
8
|
Organization = mongoose.model('Organization'),
|
|
9
9
|
Note = mongoose.model('Note'),
|
|
10
|
-
Flag = mongoose.model('Flag'),
|
|
11
10
|
helpers = require('../helpers'),
|
|
12
11
|
utilities = require('@dhyasama/totem-utilities'),
|
|
13
12
|
async = require('async'),
|
|
@@ -295,24 +294,8 @@ module.exports = function(mongoose, config) {
|
|
|
295
294
|
|
|
296
295
|
////////////
|
|
297
296
|
|
|
298
|
-
Person.statics.
|
|
299
|
-
|
|
300
|
-
Flag.createForModel({
|
|
301
|
-
createdBy: creatorPersonId,
|
|
302
|
-
text: text,
|
|
303
|
-
customer: customerId
|
|
304
|
-
}, this, personId, cb);
|
|
305
|
-
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
Person.statics.addNote = function(personId, creatorPersonId, text, customerId, cb) {
|
|
309
|
-
|
|
310
|
-
Note.createForModel({
|
|
311
|
-
createdBy: creatorPersonId,
|
|
312
|
-
text: text,
|
|
313
|
-
customer: customerId
|
|
314
|
-
}, this, personId, cb);
|
|
315
|
-
|
|
297
|
+
Person.statics.addNote = function(personId, note, cb) {
|
|
298
|
+
Note.createForModel(this, personId, note, cb);
|
|
316
299
|
};
|
|
317
300
|
|
|
318
301
|
Person.statics.deleteNote = function(noteId, customerId, cb) {
|
|
@@ -509,36 +492,6 @@ module.exports = function(mongoose, config) {
|
|
|
509
492
|
});
|
|
510
493
|
};
|
|
511
494
|
|
|
512
|
-
Person.statics.getFlags = function getFlags(personId, options, cb) {
|
|
513
|
-
|
|
514
|
-
if (!cb) { throw new Error('cb is required'); }
|
|
515
|
-
if (!personId) { return cb(new Error('personId is required'), null); }
|
|
516
|
-
if (!mongoose.Types.ObjectId.isValid(personId)) { return cb(new Error('personId is not a valid ObjectId'), null); }
|
|
517
|
-
if (!options) { return cb(new Error('options is required'), null); }
|
|
518
|
-
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
519
|
-
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
520
|
-
|
|
521
|
-
const self = this;
|
|
522
|
-
let query = self.findById(personId);
|
|
523
|
-
|
|
524
|
-
query.select('flags');
|
|
525
|
-
query.populate({
|
|
526
|
-
path: 'flags',
|
|
527
|
-
match: { customer: options.CUSTOMER_ID }
|
|
528
|
-
});
|
|
529
|
-
query.deepPopulate([
|
|
530
|
-
'flags.createdBy'
|
|
531
|
-
], {
|
|
532
|
-
populate: {
|
|
533
|
-
'flags.createdBy': { select: 'name avatarUrl title' }
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
query.sort({'createdOn':-1});
|
|
537
|
-
|
|
538
|
-
query.exec(cb);
|
|
539
|
-
|
|
540
|
-
};
|
|
541
|
-
|
|
542
495
|
Person.statics.getList = function getList(cb) {
|
|
543
496
|
|
|
544
497
|
var self = this;
|