@dhyasama/totem-models 11.1.0 → 11.3.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/DiffbotOrganization.js +6 -6
- package/lib/Interaction.js +43 -0
- package/lib/Message.js +15 -2
- package/lib/News.js +19 -8
- package/lib/Person.js +3 -1
- package/package.json +1 -1
|
@@ -12,13 +12,13 @@ module.exports = function(mongoose, config) {
|
|
|
12
12
|
org: {
|
|
13
13
|
type: Schema.ObjectId,
|
|
14
14
|
ref: 'Organization',
|
|
15
|
-
required:
|
|
16
|
-
|
|
15
|
+
required: true,
|
|
16
|
+
unique: true
|
|
17
17
|
},
|
|
18
18
|
|
|
19
|
-
updatedOn: { type: Date, required:
|
|
19
|
+
updatedOn: { type: Date, required: true, default: new Date() },
|
|
20
20
|
|
|
21
|
-
entity: { type: Schema.Types.Mixed, required:
|
|
21
|
+
entity: { type: Schema.Types.Mixed, required: true },
|
|
22
22
|
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -33,7 +33,7 @@ module.exports = function(mongoose, config) {
|
|
|
33
33
|
options = helpers.getDefaultOptions(options);
|
|
34
34
|
|
|
35
35
|
self
|
|
36
|
-
.
|
|
36
|
+
.findOne({ org: id })
|
|
37
37
|
.populate('org')
|
|
38
38
|
.exec(cb);
|
|
39
39
|
|
|
@@ -50,7 +50,7 @@ module.exports = function(mongoose, config) {
|
|
|
50
50
|
options = helpers.getDefaultOptions(options);
|
|
51
51
|
|
|
52
52
|
self
|
|
53
|
-
.
|
|
53
|
+
.findOne({ org: id })
|
|
54
54
|
.exec(cb);
|
|
55
55
|
|
|
56
56
|
};
|
package/lib/Interaction.js
CHANGED
|
@@ -189,6 +189,49 @@ module.exports = function(mongoose, config) {
|
|
|
189
189
|
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
+
Interaction.statics.getForTimeline = function getForTimeline(customerId, options, cb) {
|
|
193
|
+
|
|
194
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
195
|
+
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
196
|
+
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
197
|
+
|
|
198
|
+
const self = this;
|
|
199
|
+
const startDate = options.startDate || moment().subtract(20, 'years').startOf('day').toISOString();
|
|
200
|
+
const endDate = options.endDate || moment().toISOString();
|
|
201
|
+
|
|
202
|
+
self.aggregate([
|
|
203
|
+
{
|
|
204
|
+
$match: {
|
|
205
|
+
totemCustomerId: customerId,
|
|
206
|
+
startTime: {
|
|
207
|
+
$gte: startDate,
|
|
208
|
+
$lte: endDate
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
$sort: {
|
|
214
|
+
startTime: -1
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
$group: {
|
|
219
|
+
_id: "$providerEventId", // Group by providerEventId to deduplicate
|
|
220
|
+
doc: { $first: "$$ROOT" } // Take the first (latest) document encountered for each providerEventId after sorting
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
$replaceRoot: { newRoot: "$doc" } // Replace the root to output the original document structure
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
$sort: {
|
|
228
|
+
startTime: -1 // Final sort by startTime in descending order to order the output
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
]).exec(cb);
|
|
232
|
+
|
|
233
|
+
};
|
|
234
|
+
|
|
192
235
|
Interaction.statics.getMostRecent = function getMostRecent(customerId, personIds, cb) {
|
|
193
236
|
|
|
194
237
|
// Gets the most recent interaction with a customer across a list of people
|
package/lib/Message.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const moment = require("moment/moment");
|
|
3
4
|
module.exports = function(mongoose, config) {
|
|
4
5
|
|
|
5
6
|
let
|
|
@@ -7,6 +8,7 @@ module.exports = function(mongoose, config) {
|
|
|
7
8
|
Schema = mongoose.Schema,
|
|
8
9
|
async = require('async'),
|
|
9
10
|
_ = require('underscore'),
|
|
11
|
+
moment = require('moment'),
|
|
10
12
|
helpers = require('../helpers'),
|
|
11
13
|
Document = mongoose.model('Document'),
|
|
12
14
|
Note = mongoose.model('Note');
|
|
@@ -246,9 +248,20 @@ module.exports = function(mongoose, config) {
|
|
|
246
248
|
|
|
247
249
|
const self = this;
|
|
248
250
|
|
|
249
|
-
let query = self.find({ customer: options.CUSTOMER_ID
|
|
251
|
+
let query = self.find({ customer: options.CUSTOMER_ID });
|
|
252
|
+
query.find({ organization: { $in : orgIds }});
|
|
253
|
+
|
|
254
|
+
if (options.startDate) {
|
|
255
|
+
const startDate = options.startDate || moment().subtract(20, 'years').startOf('day').toISOString();
|
|
256
|
+
query.where('messageDate').gte(startDate)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (options.endDate) {
|
|
260
|
+
const endDate = options.endDate || moment().toISOString();
|
|
261
|
+
query.where('messageDate').lte(endDate)
|
|
262
|
+
}
|
|
263
|
+
|
|
250
264
|
query.populate('documents');
|
|
251
|
-
|
|
252
265
|
query.exec(cb);
|
|
253
266
|
|
|
254
267
|
};
|
package/lib/News.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const moment = require("moment/moment");
|
|
3
4
|
module.exports = function(mongoose, config) {
|
|
4
5
|
|
|
5
6
|
let
|
|
6
7
|
|
|
7
8
|
Schema = mongoose.Schema,
|
|
8
9
|
helpers = require('../helpers'),
|
|
10
|
+
moment = require('moment'),
|
|
9
11
|
|
|
10
12
|
News = new Schema({
|
|
11
13
|
|
|
@@ -25,7 +27,7 @@ module.exports = function(mongoose, config) {
|
|
|
25
27
|
|
|
26
28
|
sentiment: { type: Number, required: false, default: null },
|
|
27
29
|
|
|
28
|
-
diffbotUri: { type: String, required:
|
|
30
|
+
diffbotUri: { type: String, required: true, unique: true },
|
|
29
31
|
|
|
30
32
|
org: {
|
|
31
33
|
type: Schema.ObjectId,
|
|
@@ -60,18 +62,28 @@ module.exports = function(mongoose, config) {
|
|
|
60
62
|
|
|
61
63
|
News.statics.getByIds = function getByIds(ids, options, cb) {
|
|
62
64
|
|
|
63
|
-
const self = this;
|
|
64
|
-
|
|
65
65
|
if (!cb) { throw new Error('cb is required'); }
|
|
66
66
|
if (!ids) { return cb(new Error('ids is required'), null); }
|
|
67
67
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
68
68
|
|
|
69
69
|
options = helpers.getDefaultOptions(options);
|
|
70
70
|
|
|
71
|
-
self
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
const self = this;
|
|
72
|
+
|
|
73
|
+
let query = self.find({ org: { $in : ids } })
|
|
74
|
+
|
|
75
|
+
if (options.startDate) {
|
|
76
|
+
const startDate = options.startDate || moment().subtract(20, 'years').startOf('day').toISOString();
|
|
77
|
+
query.where('publishedOn').gte(startDate)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (options.endDate) {
|
|
81
|
+
const endDate = options.endDate || moment().toISOString();
|
|
82
|
+
query.where('publishedOn').lte(endDate)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
query.sort('-createdOn')
|
|
86
|
+
query.exec(cb);
|
|
75
87
|
|
|
76
88
|
};
|
|
77
89
|
|
|
@@ -95,7 +107,6 @@ module.exports = function(mongoose, config) {
|
|
|
95
107
|
};
|
|
96
108
|
|
|
97
109
|
News.statics.upsert = function (news, cb) {
|
|
98
|
-
news.markModified('extracted');
|
|
99
110
|
news.save(cb);
|
|
100
111
|
};
|
|
101
112
|
|
package/lib/Person.js
CHANGED
|
@@ -1217,7 +1217,9 @@ module.exports = function(mongoose, config) {
|
|
|
1217
1217
|
cleanContactInfo(doc);
|
|
1218
1218
|
|
|
1219
1219
|
// set full name for ease of searching
|
|
1220
|
-
|
|
1220
|
+
doc.fullName = '';
|
|
1221
|
+
if(doc.name.first) doc.fullName += doc.name.first;
|
|
1222
|
+
if(doc.name.last) doc.fullName += ' ' + doc.name.last;
|
|
1221
1223
|
|
|
1222
1224
|
if (doc.sources) {
|
|
1223
1225
|
|