@dhyasama/totem-models 2.1.5 → 2.2.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/Organization.js +12 -0
- package/lib/Person.js +12 -0
- package/package-lock.json +1 -1
- package/package.json +1 -1
- package/test/Organization.js +19 -0
- package/test/Person.js +19 -0
package/lib/Organization.js
CHANGED
|
@@ -1208,6 +1208,18 @@ module.exports = function(mongoose, config) {
|
|
|
1208
1208
|
|
|
1209
1209
|
};
|
|
1210
1210
|
|
|
1211
|
+
Organization.statics.modify = function(orgId, update, cb) {
|
|
1212
|
+
|
|
1213
|
+
if (!cb) throw new Error('cb is required');
|
|
1214
|
+
if (!orgId) { return cb(new Error('orgId is required'), null); }
|
|
1215
|
+
if (!update) { return cb(new Error('update is required'), null); }
|
|
1216
|
+
|
|
1217
|
+
var self = this;
|
|
1218
|
+
|
|
1219
|
+
self.findOneAndUpdate({ _id: orgId }, update, { upsert: false, new: true }, cb);
|
|
1220
|
+
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1211
1223
|
|
|
1212
1224
|
|
|
1213
1225
|
///////////////////////////////////////////////////////////////////////////////////////
|
package/lib/Person.js
CHANGED
|
@@ -991,6 +991,18 @@ module.exports = function(mongoose, config) {
|
|
|
991
991
|
|
|
992
992
|
};
|
|
993
993
|
|
|
994
|
+
Person.statics.modify = function(personId, update, cb) {
|
|
995
|
+
|
|
996
|
+
if (!cb) throw new Error('cb is required');
|
|
997
|
+
if (!personId) { return cb(new Error('personId is required'), null); }
|
|
998
|
+
if (!update) { return cb(new Error('update is required'), null); }
|
|
999
|
+
|
|
1000
|
+
var self = this;
|
|
1001
|
+
|
|
1002
|
+
self.findOneAndUpdate({ _id: personId }, update, { upsert: false, new: true }, cb);
|
|
1003
|
+
|
|
1004
|
+
};
|
|
1005
|
+
|
|
994
1006
|
Person.statics.addFlag = function(personId, creatorPersonId, text, cb) {
|
|
995
1007
|
|
|
996
1008
|
Flag.createForModel({
|
package/package-lock.json
CHANGED
package/package.json
CHANGED
package/test/Organization.js
CHANGED
|
@@ -511,6 +511,25 @@ describe('Organization', function() {
|
|
|
511
511
|
|
|
512
512
|
});
|
|
513
513
|
|
|
514
|
+
it('modifies a company', function(done) {
|
|
515
|
+
|
|
516
|
+
var update = {
|
|
517
|
+
$set: {
|
|
518
|
+
'name': 'I updated my name!',
|
|
519
|
+
'entered.by': 'Testy McTester',
|
|
520
|
+
'entered.on': new Date()
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
Organization.modify(org1._id, update, function(err, org) {
|
|
525
|
+
should.not.exist(err);
|
|
526
|
+
should.exist(org);
|
|
527
|
+
org.name.should.equal('I updated my name!');
|
|
528
|
+
done();
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
});
|
|
532
|
+
|
|
514
533
|
it('merges an org', function(done) {
|
|
515
534
|
|
|
516
535
|
var merged = org1.merge(mergeId);
|
package/test/Person.js
CHANGED
|
@@ -584,6 +584,25 @@ describe('Person', function() {
|
|
|
584
584
|
|
|
585
585
|
});
|
|
586
586
|
|
|
587
|
+
it('modifies a person', function(done) {
|
|
588
|
+
|
|
589
|
+
var update = {
|
|
590
|
+
$set: {
|
|
591
|
+
'title': 'Chief Testing Officer',
|
|
592
|
+
'entered.by': 'Testy McTester',
|
|
593
|
+
'entered.on': new Date()
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
Person.modify(person._id, update, function(err, org) {
|
|
598
|
+
should.not.exist(err);
|
|
599
|
+
should.exist(org);
|
|
600
|
+
org.title.should.equal('Chief Testing Officer');
|
|
601
|
+
done();
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
});
|
|
605
|
+
|
|
587
606
|
it('lists all people', function(done) {
|
|
588
607
|
|
|
589
608
|
Person.listAllPeople(function(err, people) {
|