@dhyasama/totem-models 11.102.0 → 11.103.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/CalendarEvent.js +2 -2
- package/lib/Interaction.js +1 -3
- package/lib/Meeting.js +117 -29
- package/package.json +1 -1
package/lib/CalendarEvent.js
CHANGED
|
@@ -49,7 +49,7 @@ module.exports = function(mongoose, config) {
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
CalendarEvent.virtual('original').get(function () {
|
|
52
|
-
return JSON.parse(this.raw);
|
|
52
|
+
try { return JSON.parse(this.raw); } catch (e) { return null; }
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
CalendarEvent.statics.delete = function(calendarEventId, cb) {
|
|
@@ -70,7 +70,7 @@ module.exports = function(mongoose, config) {
|
|
|
70
70
|
|
|
71
71
|
CalendarEvent.statics.findByCreatedRange = function (since, until, cb) {
|
|
72
72
|
this
|
|
73
|
-
.find({ createdOn: { $gt: since, $lt:
|
|
73
|
+
.find({ createdOn: { $gt: since, $lt: until } })
|
|
74
74
|
.exec(cb);
|
|
75
75
|
};
|
|
76
76
|
|
package/lib/Interaction.js
CHANGED
|
@@ -54,8 +54,7 @@ module.exports = function(mongoose, config) {
|
|
|
54
54
|
Interaction.statics.delete = function(providerEventId, totemCustomerId, cb) {
|
|
55
55
|
|
|
56
56
|
if (!cb) { throw new Error('cb is required'); }
|
|
57
|
-
if (!providerEventId) { return cb(new Error('
|
|
58
|
-
if (!mongoose.Types.ObjectId.isValid(providerEventId)) { return cb(new Error('providerEventId is not a valid ObjectId'), null); }
|
|
57
|
+
if (!providerEventId) { return cb(new Error('providerEventId is required'), null); }
|
|
59
58
|
if (!totemCustomerId) { return cb(new Error('totemCustomerId is required'), null); }
|
|
60
59
|
if (!mongoose.Types.ObjectId.isValid(totemCustomerId)) { return cb(new Error('totemCustomerId is not a valid ObjectId'), null); }
|
|
61
60
|
|
|
@@ -408,7 +407,6 @@ module.exports = function(mongoose, config) {
|
|
|
408
407
|
|
|
409
408
|
Interaction.set('usePushEach', true);
|
|
410
409
|
Interaction.set('autoIndex', false);
|
|
411
|
-
Interaction.set('usePushEach', true);
|
|
412
410
|
Interaction.on('index', function(err) { console.log('error building interaction indexes: ' + err); });
|
|
413
411
|
|
|
414
412
|
var deepPopulate = require('mongoose-deep-populate')(mongoose);
|
package/lib/Meeting.js
CHANGED
|
@@ -51,49 +51,137 @@ module.exports = function(mongoose, config) {
|
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
Meeting.virtual('original').get(function () {
|
|
54
|
-
return JSON.parse(this.raw);
|
|
54
|
+
try { return JSON.parse(this.raw); } catch (e) { return null; }
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
Meeting.statics.getById = function (id, cb) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
Meeting.statics.getById = function (id, options, cb) {
|
|
58
|
+
|
|
59
|
+
const self = this;
|
|
60
|
+
|
|
61
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
62
|
+
if (!id) { return cb(new Error('id is required'), null); }
|
|
63
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
64
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
65
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
66
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
67
|
+
|
|
68
|
+
let query = self.findOne({ '_id': id, customer: options.CUSTOMER_ID });
|
|
69
|
+
query.exec(cb);
|
|
70
|
+
|
|
61
71
|
};
|
|
62
72
|
|
|
63
|
-
Meeting.statics.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
Meeting.statics.getByEventId = function (eventId, options, cb) {
|
|
74
|
+
|
|
75
|
+
const self = this;
|
|
76
|
+
|
|
77
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
78
|
+
if (!eventId) { return cb(new Error('eventId is required'), null); }
|
|
79
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
80
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
81
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
82
|
+
|
|
83
|
+
let query = self.findOne({ 'eventId': eventId, customer: options.CUSTOMER_ID });
|
|
84
|
+
query.exec(cb);
|
|
85
|
+
|
|
67
86
|
};
|
|
68
87
|
|
|
69
|
-
Meeting.statics.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
Meeting.statics.getByUniqueId = function (uniqueId, options, cb) {
|
|
89
|
+
|
|
90
|
+
const self = this;
|
|
91
|
+
|
|
92
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
93
|
+
if (!uniqueId) { return cb(new Error('uniqueId is required'), null); }
|
|
94
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
95
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
96
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
97
|
+
|
|
98
|
+
let query = self.findOne({ 'uniqueId': uniqueId, customer: options.CUSTOMER_ID });
|
|
99
|
+
query.exec(cb);
|
|
100
|
+
|
|
73
101
|
};
|
|
74
102
|
|
|
75
|
-
Meeting.statics.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
103
|
+
Meeting.statics.getByDate = function (since, until, options, cb) {
|
|
104
|
+
|
|
105
|
+
const self = this;
|
|
106
|
+
|
|
107
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
108
|
+
if (!since) { return cb(new Error('since is required'), null); }
|
|
109
|
+
if (!until) { return cb(new Error('until is required'), null); }
|
|
110
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
111
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
112
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
113
|
+
|
|
114
|
+
let query = self.find({ customer: options.CUSTOMER_ID, startOn: { $gte: since, $lte: until } });
|
|
115
|
+
query.exec(cb);
|
|
116
|
+
|
|
79
117
|
};
|
|
80
118
|
|
|
81
|
-
Meeting.statics.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
119
|
+
Meeting.statics.getByPeople = function (personIds, options, cb) {
|
|
120
|
+
|
|
121
|
+
const self = this;
|
|
122
|
+
|
|
123
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
124
|
+
if (!personIds) { return cb(new Error('personIds is required'), null); }
|
|
125
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
126
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
127
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
128
|
+
|
|
129
|
+
let query = self.find({ customer: options.CUSTOMER_ID });
|
|
130
|
+
query.where({ 'people': { $in : personIds } });
|
|
131
|
+
query.exec(cb);
|
|
132
|
+
|
|
85
133
|
};
|
|
134
|
+
|
|
135
|
+
Meeting.statics.getMostRecent = function getMostRecent(customerId, personIds, timestamp, cb) {
|
|
136
|
+
|
|
137
|
+
// Gets the most recent meeting with a customer across a list of people
|
|
138
|
+
// Typically used to get the last meeting the firm had with an org
|
|
139
|
+
// So you'd pass in the id of the customer and a list of the people at an org and get back the most recent interaction
|
|
140
|
+
|
|
141
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
142
|
+
if (!personIds) { return cb(new Error('personIds is required'), null); }
|
|
143
|
+
if (personIds.length === 0) { return cb(new Error('personIds has no person ids'), null); }
|
|
144
|
+
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
145
|
+
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
146
|
+
|
|
147
|
+
const self = this;
|
|
148
|
+
|
|
149
|
+
// only for this customer
|
|
150
|
+
let query = self.findOne({ customer: customerId });
|
|
151
|
+
|
|
152
|
+
// with these people on the meeting
|
|
153
|
+
query.where({ 'people': { $in : personIds } });
|
|
154
|
+
|
|
155
|
+
// only meetings that have already started
|
|
156
|
+
query.where('startOn').lte(new Date());
|
|
157
|
+
|
|
158
|
+
// Optionally limit to meetings newer than timestamp (useful for seeing if anything since a previous event)
|
|
159
|
+
if (timestamp) query.where('startOn').gt(timestamp);
|
|
160
|
+
|
|
161
|
+
query.sort({ 'startOn': -1 });
|
|
162
|
+
query.limit(1);
|
|
163
|
+
|
|
164
|
+
query.exec(cb);
|
|
86
165
|
|
|
87
|
-
Meeting.statics.findByPerson = function (person, cb) {
|
|
88
|
-
this
|
|
89
|
-
.find({ 'people': person })
|
|
90
|
-
.exec(cb);
|
|
91
166
|
};
|
|
92
167
|
|
|
93
|
-
Meeting.statics.delete = function(meetingId, cb) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
168
|
+
Meeting.statics.delete = function(meetingId, options, cb) {
|
|
169
|
+
|
|
170
|
+
const self = this;
|
|
171
|
+
|
|
172
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
173
|
+
if (!meetingId) { return cb(new Error('meetingId is required'), null); }
|
|
174
|
+
if (!mongoose.Types.ObjectId.isValid(meetingId)) { return cb(new Error('meetingId is not a valid ObjectId'), null); }
|
|
175
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
176
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
177
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
178
|
+
|
|
179
|
+
let query = self.findOne({ _id: meetingId, customer: options.CUSTOMER_ID });
|
|
180
|
+
query.exec(function(err, meeting) {
|
|
181
|
+
if (err) { return cb(err, null); }
|
|
182
|
+
else if (!meeting) { return cb(null, null); }
|
|
183
|
+
meeting.remove(cb);
|
|
184
|
+
});
|
|
97
185
|
};
|
|
98
186
|
|
|
99
187
|
Meeting.statics.upsert = function(meeting, cb) {
|