@dhyasama/totem-merge 6.12.0 → 6.14.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 +1 -4
- package/lib/organizations.js +1 -48
- package/lib/people.js +15 -121
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -13,17 +13,14 @@ var Merge = function(mongoose, config) {
|
|
|
13
13
|
this.Deal = mongoose.model('Deal');
|
|
14
14
|
this.Document = mongoose.model('Document');
|
|
15
15
|
this.Financials = mongoose.model('Financials');
|
|
16
|
-
this.Flag = mongoose.model('Flag');
|
|
17
|
-
this.Interaction = mongoose.model('Interaction');
|
|
18
16
|
this.LimitedPartner = mongoose.model('LimitedPartner');
|
|
19
|
-
this.List = mongoose.model('List');
|
|
20
17
|
this.Message = mongoose.model('Message');
|
|
18
|
+
this.Meeting = mongoose.model('Meeting');
|
|
21
19
|
this.News = mongoose.model('News');
|
|
22
20
|
this.Note = mongoose.model('Note');
|
|
23
21
|
this.Organization = mongoose.model('Organization');
|
|
24
22
|
this.Person = mongoose.model('Person');
|
|
25
23
|
this.Round = mongoose.model('Round');
|
|
26
|
-
this.Snapshot = mongoose.model('Snapshot');
|
|
27
24
|
|
|
28
25
|
// can choose to flag an entity as needing to be merged rather than actually merging it
|
|
29
26
|
// particularly useful for automated processes, e.g., a batch import that detects dupes
|
package/lib/organizations.js
CHANGED
|
@@ -109,7 +109,7 @@ var mergeSourceIntoTarget = function mergeEntities(target, source, cb) {
|
|
|
109
109
|
'__v'
|
|
110
110
|
];
|
|
111
111
|
|
|
112
|
-
helpers.mergeObjects(target, source, doNotMergeKeys);
|
|
112
|
+
helpers.mergeObjects(target.toObject(), source.toObject(), doNotMergeKeys);
|
|
113
113
|
|
|
114
114
|
// keep a list of copied orgs
|
|
115
115
|
target.merge(source.id);
|
|
@@ -175,7 +175,6 @@ var updateReferences = function updateReferences(context, target, source, merged
|
|
|
175
175
|
updateCapTables.bind(context, newOrgId, oldOrgId),
|
|
176
176
|
updateDeals.bind(context, newOrgId, oldOrgId, customerId),
|
|
177
177
|
updateFinancials.bind(context, newOrgId, oldOrgId),
|
|
178
|
-
updateLists.bind(context, newOrgId, oldOrgId),
|
|
179
178
|
updateMessages.bind(context, newOrgId, oldOrgId),
|
|
180
179
|
updateNews.bind(context, newOrgId, oldOrgId),
|
|
181
180
|
updateOrganizations.bind(context, newOrgId, oldOrgId),
|
|
@@ -307,52 +306,6 @@ var updateFinancials = function updateFinancials(newOrgId, oldOrgId, cb) {
|
|
|
307
306
|
|
|
308
307
|
};
|
|
309
308
|
|
|
310
|
-
var updateLists = function updateLists(newOrgId, oldOrgId, cb) {
|
|
311
|
-
|
|
312
|
-
logger.writeToInfoLog(' Updating lists...');
|
|
313
|
-
|
|
314
|
-
var self = this;
|
|
315
|
-
|
|
316
|
-
self.List.collection.find({ 'organizations': oldOrgId }).toArray(function(err, items) {
|
|
317
|
-
|
|
318
|
-
if (err) return cb(err, null);
|
|
319
|
-
else if (!items || items.length === 0) return cb(null, []);
|
|
320
|
-
|
|
321
|
-
var tasks = [];
|
|
322
|
-
var updated = [];
|
|
323
|
-
|
|
324
|
-
_.each(items, function(item) {
|
|
325
|
-
|
|
326
|
-
var orgs = _.map(item.organizations, function(o) {
|
|
327
|
-
if (o.toString() === oldOrgId.toString()) { o = newOrgId; }
|
|
328
|
-
return o;
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
tasks.push({
|
|
332
|
-
id: item._id,
|
|
333
|
-
update: { $set: { organizations: orgs } }
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
logger.writeToInfoLog(' Found ' + tasks.length + ' list references to update');
|
|
339
|
-
|
|
340
|
-
var queue = async.queue(function(task, callback) {
|
|
341
|
-
self.List.modifyById(task.id, task.update, function(err, result) {
|
|
342
|
-
if (err) { return callback(err, null); }
|
|
343
|
-
else if (result) { updated.push(result); }
|
|
344
|
-
return callback(null, result);
|
|
345
|
-
});
|
|
346
|
-
}, 8);
|
|
347
|
-
|
|
348
|
-
queue.drain = function() { return cb(null, updated); };
|
|
349
|
-
|
|
350
|
-
queue.push(tasks);
|
|
351
|
-
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
};
|
|
355
|
-
|
|
356
309
|
var updateMessages = function updateMessages(newOrgId, oldOrgId, cb) {
|
|
357
310
|
|
|
358
311
|
logger.writeToInfoLog(' Updating messages...');
|
package/lib/people.js
CHANGED
|
@@ -118,7 +118,7 @@ var mergeSourceIntoTarget = function mergeEntities(target, source, cb) {
|
|
|
118
118
|
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
helpers.mergeObjects(target, source, doNotMergeKeys);
|
|
121
|
+
helpers.mergeObjects(target.toObject(), source.toObject(), doNotMergeKeys);
|
|
122
122
|
|
|
123
123
|
target.sources = mergeSources(target, source);
|
|
124
124
|
|
|
@@ -171,14 +171,10 @@ var updateReferences = function updateReferences(context, target, source, merged
|
|
|
171
171
|
|
|
172
172
|
updateDocuments.bind(context, newPersonId, oldPersonId, null),
|
|
173
173
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
updateInteractions.bind(context, newPersonId, oldPersonId, username),
|
|
174
|
+
updateMeetings.bind(context, newPersonId, oldPersonId, username),
|
|
177
175
|
|
|
178
176
|
updateLimitedPartners.bind(context, newPersonId, oldPersonId, mergedBy),
|
|
179
177
|
|
|
180
|
-
updateLists.bind(context, newPersonId, oldPersonId, null),
|
|
181
|
-
|
|
182
178
|
updateMessages.bind(context, newPersonId, oldPersonId, null),
|
|
183
179
|
|
|
184
180
|
updateNotes.bind(context, newPersonId, oldPersonId, username),
|
|
@@ -285,60 +281,18 @@ var updateDocuments = function updateDocuments(newPersonId, oldPersonId, user, c
|
|
|
285
281
|
|
|
286
282
|
};
|
|
287
283
|
|
|
288
|
-
var
|
|
284
|
+
var updateMeetings = function updateMeetings(newPersonId, oldPersonId, user, cb) {
|
|
289
285
|
|
|
290
|
-
console.log(' Updating
|
|
286
|
+
console.log(' Updating meetings...');
|
|
291
287
|
|
|
292
288
|
var self = this;
|
|
293
289
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (err) return cb(err, null);
|
|
298
|
-
else if (!items || items.length === 0) return cb(null, []);
|
|
299
|
-
|
|
300
|
-
var tasks = [];
|
|
301
|
-
var updated = [];
|
|
302
|
-
|
|
303
|
-
_.each(items, function(item) {
|
|
304
|
-
|
|
305
|
-
var setObj = {};
|
|
306
|
-
|
|
307
|
-
if (item.createdBy.toString() === oldPersonId.toString()) { setObj.createdBy = newPersonId; }
|
|
308
|
-
|
|
309
|
-
tasks.push({
|
|
310
|
-
id: item._id,
|
|
311
|
-
update: { $set: setObj }
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
console.log(' Found ' + tasks.length + ' flag references to update');
|
|
317
|
-
|
|
318
|
-
var queue = async.queue(function(task, callback) {
|
|
319
|
-
self.Flag.modifyById(task.id, task.update, function(err, result) {
|
|
320
|
-
if (err) { return callback(err, null); }
|
|
321
|
-
else if (result) { updated.push(result); }
|
|
322
|
-
return callback(null, result);
|
|
323
|
-
});
|
|
324
|
-
}, 8);
|
|
325
|
-
|
|
326
|
-
queue.drain = function() { return cb(null, updated); };
|
|
327
|
-
|
|
328
|
-
queue.push(tasks);
|
|
329
|
-
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
var updateInteractions = function updateInteractions(newPersonId, oldPersonId, user, cb) {
|
|
335
|
-
|
|
336
|
-
console.log(' Updating interactions...');
|
|
337
|
-
|
|
338
|
-
var self = this;
|
|
290
|
+
if (!self.Meeting || !self.Meeting.collection) {
|
|
291
|
+
return cb(null, []);
|
|
292
|
+
}
|
|
339
293
|
|
|
340
|
-
// Get all
|
|
341
|
-
self.
|
|
294
|
+
// Get all meetings containing the old person id in people array
|
|
295
|
+
self.Meeting.collection.find({ 'people': oldPersonId }).toArray(function(err, items) {
|
|
342
296
|
|
|
343
297
|
if (err) return cb(err, null);
|
|
344
298
|
else if (!items || items.length === 0) return cb(null, []);
|
|
@@ -348,31 +302,22 @@ var updateInteractions = function updateInteractions(newPersonId, oldPersonId, u
|
|
|
348
302
|
|
|
349
303
|
_.each(items, function(item) {
|
|
350
304
|
|
|
351
|
-
item.
|
|
352
|
-
if (
|
|
353
|
-
return
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
item.attendees.external = _.map(item.attendees.external, function(attendee) {
|
|
357
|
-
if (attendee.toString() === oldPersonId.toString()) { attendee = newPersonId; }
|
|
358
|
-
return attendee;
|
|
305
|
+
item.people = _.map(item.people, function(person) {
|
|
306
|
+
if (person.toString() === oldPersonId.toString()) { person = newPersonId; }
|
|
307
|
+
return person;
|
|
359
308
|
});
|
|
360
309
|
|
|
361
310
|
tasks.push({
|
|
362
311
|
id: item._id,
|
|
363
|
-
update: { $set: {
|
|
364
|
-
'attendees.internal': item.attendees.internal,
|
|
365
|
-
'attendees.external': item.attendees.external
|
|
366
|
-
}
|
|
367
|
-
}
|
|
312
|
+
update: { $set: { 'people': item.people } }
|
|
368
313
|
});
|
|
369
314
|
|
|
370
315
|
});
|
|
371
316
|
|
|
372
|
-
console.log(' Found ' + tasks.length + '
|
|
317
|
+
console.log(' Found ' + tasks.length + ' meeting references to update');
|
|
373
318
|
|
|
374
319
|
var queue = async.queue(function(task, callback) {
|
|
375
|
-
self.
|
|
320
|
+
self.Meeting.modifyById(task.id, task.update, function(err, result) {
|
|
376
321
|
if (err) { return callback(err, null); }
|
|
377
322
|
else if (result) { updated.push(result); }
|
|
378
323
|
return callback(null, result);
|
|
@@ -437,57 +382,6 @@ var updateLimitedPartners = function updateLimitedPartners(newPersonId, oldPerso
|
|
|
437
382
|
|
|
438
383
|
};
|
|
439
384
|
|
|
440
|
-
var updateLists = function updateLists(newPersonId, oldPersonId, user, cb) {
|
|
441
|
-
|
|
442
|
-
console.log(' Updating lists...');
|
|
443
|
-
|
|
444
|
-
var self = this;
|
|
445
|
-
|
|
446
|
-
// Get all lists for this person
|
|
447
|
-
self.List.collection.find({ $or: [{ 'people': oldPersonId }, { 'createdBy': oldPersonId }] }).toArray(function(err, items) {
|
|
448
|
-
|
|
449
|
-
if (err) return cb(err, null);
|
|
450
|
-
else if (!items || items.length === 0) return cb(null, []);
|
|
451
|
-
|
|
452
|
-
var tasks = [];
|
|
453
|
-
var updated = [];
|
|
454
|
-
|
|
455
|
-
_.each(items, function(item) {
|
|
456
|
-
|
|
457
|
-
var setObj = {};
|
|
458
|
-
|
|
459
|
-
if (item.createdBy.toString() === oldPersonId.toString()) { setObj.createdBy = newPersonId; }
|
|
460
|
-
|
|
461
|
-
setObj.people = _.map(item.people, function(person) {
|
|
462
|
-
if (person.toString() === oldPersonId.toString()) { person = newPersonId; }
|
|
463
|
-
return person;
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
tasks.push({
|
|
467
|
-
id: item._id,
|
|
468
|
-
update: { $set: setObj }
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
console.log(' Found ' + tasks.length + ' list references to update');
|
|
474
|
-
|
|
475
|
-
var queue = async.queue(function(task, callback) {
|
|
476
|
-
self.List.modifyById(task.id, task.update, function(err, result) {
|
|
477
|
-
if (err) { return callback(err, null); }
|
|
478
|
-
else if (result) { updated.push(result); }
|
|
479
|
-
return callback(null, result);
|
|
480
|
-
});
|
|
481
|
-
}, 8);
|
|
482
|
-
|
|
483
|
-
queue.drain = function() { return cb(null, updated); };
|
|
484
|
-
|
|
485
|
-
queue.push(tasks);
|
|
486
|
-
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
};
|
|
490
|
-
|
|
491
385
|
var updateMessages = function updateMessages(newPersonId, oldPersonId, user, cb) {
|
|
492
386
|
|
|
493
387
|
console.log(' Updating messages...');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhyasama/totem-merge",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.14.0",
|
|
4
4
|
"description": "Org and person merging package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"underscore": "^1.13.6"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@dhyasama/totem-models": "^
|
|
25
|
+
"@dhyasama/totem-models": "^11.110.0",
|
|
26
26
|
"mocha": "^5.2.0",
|
|
27
27
|
"mocha-mongoose": "^1.1.1",
|
|
28
28
|
"should": "^8.2.2"
|