@dhyasama/totem-models 10.26.0 → 10.27.1
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/Deal.js +52 -39
- package/lib/Organization.js +4 -4
- package/package.json +1 -1
package/lib/Deal.js
CHANGED
|
@@ -340,44 +340,6 @@ module.exports = function(mongoose, config) {
|
|
|
340
340
|
|
|
341
341
|
};
|
|
342
342
|
|
|
343
|
-
Deal.statics.modifyCustomField = function modifyCustomField(id, key, value, customerId, options, cb) {
|
|
344
|
-
|
|
345
|
-
const self = this;
|
|
346
|
-
|
|
347
|
-
if (!cb) { throw new Error('cb is required'); }
|
|
348
|
-
if (!id) { return cb(new Error('id is required'), null); }
|
|
349
|
-
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
350
|
-
if (!key) { return cb(new Error('key is required'), null); }
|
|
351
|
-
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
352
|
-
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
353
|
-
|
|
354
|
-
// Dynamic custom field name requires building object this way, rather than { 'customField.' + key: value }
|
|
355
|
-
let keyValue = {};
|
|
356
|
-
keyValue['customFields.' + key] = value;
|
|
357
|
-
|
|
358
|
-
const historyItem = {
|
|
359
|
-
timestamp: new Date(),
|
|
360
|
-
account: options.account,
|
|
361
|
-
stage: null,
|
|
362
|
-
description: 'The deal details were updated'
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
const update = {
|
|
366
|
-
$set: keyValue,
|
|
367
|
-
$push: { history: historyItem }
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
const match = {
|
|
371
|
-
_id: id,
|
|
372
|
-
customer: customerId
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
const query = self.updateOne(match, update, { upsert: false, new: true });
|
|
376
|
-
|
|
377
|
-
query.exec(cb);
|
|
378
|
-
|
|
379
|
-
};
|
|
380
|
-
|
|
381
343
|
Deal.statics.modifyPoll = function modifyPoll(id, key, voterid, vote, customerId, options, cb) {
|
|
382
344
|
|
|
383
345
|
// Poll is the custom field type, but the actual field name/key can be anything
|
|
@@ -419,6 +381,17 @@ module.exports = function(mongoose, config) {
|
|
|
419
381
|
votedOn: new Date()
|
|
420
382
|
};
|
|
421
383
|
|
|
384
|
+
let addFields = {};
|
|
385
|
+
addFields[path] = {
|
|
386
|
+
"$cond": {
|
|
387
|
+
"if": {
|
|
388
|
+
"$ne": [ { "$type": "$" + path }, "array" ]
|
|
389
|
+
},
|
|
390
|
+
"then": [],
|
|
391
|
+
"else": "$" + path
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
422
395
|
// Dynamic custom field name requires building object this way, rather than { 'customField.' + key: value }
|
|
423
396
|
let set = {};
|
|
424
397
|
set[path] = {
|
|
@@ -457,7 +430,10 @@ module.exports = function(mongoose, config) {
|
|
|
457
430
|
'_id': id,
|
|
458
431
|
customer: customerId
|
|
459
432
|
},
|
|
460
|
-
[
|
|
433
|
+
[
|
|
434
|
+
{ $addFields: addFields },
|
|
435
|
+
{ $set: set }
|
|
436
|
+
], // must be part of aggregation pipeline for conditions to work
|
|
461
437
|
{ upsert: false, new: true }
|
|
462
438
|
);
|
|
463
439
|
|
|
@@ -518,6 +494,43 @@ module.exports = function(mongoose, config) {
|
|
|
518
494
|
|
|
519
495
|
};
|
|
520
496
|
|
|
497
|
+
Deal.statics.modifyProperty = function modifyProperty(id, key, value, customerId, options, cb) {
|
|
498
|
+
|
|
499
|
+
const self = this;
|
|
500
|
+
|
|
501
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
502
|
+
if (!id) { return cb(new Error('id is required'), null); }
|
|
503
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
504
|
+
if (!key) { return cb(new Error('key is required'), null); }
|
|
505
|
+
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
506
|
+
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
507
|
+
|
|
508
|
+
let keyValue = {};
|
|
509
|
+
keyValue[key] = value;
|
|
510
|
+
|
|
511
|
+
const historyItem = {
|
|
512
|
+
timestamp: new Date(),
|
|
513
|
+
account: options.account,
|
|
514
|
+
stage: null,
|
|
515
|
+
description: 'The deal details were updated'
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
const update = {
|
|
519
|
+
$set: keyValue,
|
|
520
|
+
$push: { history: historyItem }
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
const match = {
|
|
524
|
+
_id: id,
|
|
525
|
+
customer: customerId
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
const query = self.updateOne(match, update, { upsert: false, new: true });
|
|
529
|
+
|
|
530
|
+
query.exec(cb);
|
|
531
|
+
|
|
532
|
+
};
|
|
533
|
+
|
|
521
534
|
Deal.statics.upsert = function upsert(deal, options, cb) {
|
|
522
535
|
|
|
523
536
|
// Deal is dumb and doesn't validate customer stages or duplicate deals. That responsibility is with the org.
|
package/lib/Organization.js
CHANGED
|
@@ -241,7 +241,7 @@ module.exports = function(mongoose, config) {
|
|
|
241
241
|
type: { type: String, enum: ['Text', 'Number', 'Checkbox', 'Single Select', 'Multiple Select', 'Timestamp', 'Tags', 'Person', 'Org', 'Poll'] },
|
|
242
242
|
|
|
243
243
|
// These are the number formats
|
|
244
|
-
format: { type: String, enum: [null, 'number', 'abbreviated', 'decimal', 'financials', 'currency', 'ownership', 'multiple', 'variance', 'M/d/yy'] },
|
|
244
|
+
format: { type: String, enum: [null, 'number', 'abbreviated', 'decimal', 'financials', 'currency', 'ownership', 'multiple', 'variance', 'M/d/yy', 'long'] },
|
|
245
245
|
|
|
246
246
|
// These will be the choices in polls, single-selects and multi-selects
|
|
247
247
|
options: [{
|
|
@@ -411,7 +411,7 @@ module.exports = function(mongoose, config) {
|
|
|
411
411
|
type: { type: String, enum: ['Text', 'Number', 'Checkbox', 'Single Select', 'Multiple Select', 'Timestamp', 'Tags', 'Person', 'Org', 'Poll'] },
|
|
412
412
|
|
|
413
413
|
// These are the number formats
|
|
414
|
-
format: { type: String, enum: [null, 'number', 'abbreviated', 'decimal', 'financials', 'currency', 'ownership', 'multiple', 'variance', 'M/d/yy'] },
|
|
414
|
+
format: { type: String, enum: [null, 'number', 'abbreviated', 'decimal', 'financials', 'currency', 'ownership', 'multiple', 'variance', 'M/d/yy', 'long'] },
|
|
415
415
|
|
|
416
416
|
// These will be the choices in polls, single-selects and multi-selects
|
|
417
417
|
options: [{
|
|
@@ -474,7 +474,7 @@ module.exports = function(mongoose, config) {
|
|
|
474
474
|
type: { type: String, enum: ['Text', 'Number', 'Checkbox', 'Single Select', 'Multiple Select', 'Timestamp', 'Tags', 'Person', 'Org', 'Poll'] },
|
|
475
475
|
|
|
476
476
|
// These are the number formats
|
|
477
|
-
format: { type: String, enum: [null, 'number', 'abbreviated', 'decimal', 'financials', 'currency', 'ownership', 'multiple', 'variance', 'M/d/yy'] },
|
|
477
|
+
format: { type: String, enum: [null, 'number', 'abbreviated', 'decimal', 'financials', 'currency', 'ownership', 'multiple', 'variance', 'M/d/yy', 'long'] },
|
|
478
478
|
|
|
479
479
|
// These will be the choices in polls, single-selects and multi-selects
|
|
480
480
|
options: [{
|
|
@@ -539,7 +539,7 @@ module.exports = function(mongoose, config) {
|
|
|
539
539
|
type: { type: String, enum: ['Text', 'Number', 'Checkbox', 'Single Select', 'Multiple Select', 'Timestamp', 'Tags', 'Person', 'Org', 'Poll'] },
|
|
540
540
|
|
|
541
541
|
// These are the number formats
|
|
542
|
-
format: { type: String, enum: [null, 'number', 'abbreviated', 'decimal', 'financials', 'currency', 'ownership', 'multiple', 'variance', 'M/d/yy'] },
|
|
542
|
+
format: { type: String, enum: [null, 'number', 'abbreviated', 'decimal', 'financials', 'currency', 'ownership', 'multiple', 'variance', 'M/d/yy', 'long'] },
|
|
543
543
|
|
|
544
544
|
// These will be the choices in polls, single-selects and multi-selects
|
|
545
545
|
options: [{
|