@dhyasama/totem-models 12.12.0 → 12.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.
@@ -60,13 +60,15 @@ module.exports = function(mongoose, config) {
60
60
  DiffbotArticle.statics.upsert = function (doc, cb) {
61
61
 
62
62
  const run = async () => {
63
- doc.updatedOn = new Date();
64
- if (typeof doc.save === 'function') {
65
- doc.markModified('entity');
66
- return await doc.save();
67
- }
68
- const { _id, ...update } = doc;
69
- return await this.findByIdAndUpdate(_id, update, { new: true });
63
+ const update = doc.toObject ? doc.toObject() : doc;
64
+ delete update._id;
65
+ delete update.__v;
66
+ update.updatedOn = new Date();
67
+ return await this.findOneAndUpdate(
68
+ { entityId: update.entityId },
69
+ update,
70
+ { upsert: true, new: true }
71
+ );
70
72
  };
71
73
 
72
74
  if (typeof cb === 'function') { run().then(result => cb(null, result), err => cb(err)); return; }
@@ -59,13 +59,15 @@ module.exports = function(mongoose, config) {
59
59
  DiffbotOrganization.statics.upsert = function (doc, cb) {
60
60
 
61
61
  const run = async () => {
62
- doc.updatedOn = new Date();
63
- if (typeof doc.save === 'function') {
64
- doc.markModified('entity');
65
- return await doc.save();
66
- }
67
- const { _id, ...update } = doc;
68
- return await this.findByIdAndUpdate(_id, update, { new: true });
62
+ const update = doc.toObject ? doc.toObject() : doc;
63
+ delete update._id;
64
+ delete update.__v;
65
+ update.updatedOn = new Date();
66
+ return await this.findOneAndUpdate(
67
+ { org: update.org },
68
+ update,
69
+ { upsert: true, new: true }
70
+ );
69
71
  };
70
72
 
71
73
  if (typeof cb === 'function') { run().then(result => cb(null, result), err => cb(err)); return; }
package/lib/News.js CHANGED
@@ -115,11 +115,14 @@ module.exports = function(mongoose, config) {
115
115
  News.statics.upsert = function (news, cb) {
116
116
 
117
117
  const run = async () => {
118
- if (typeof news.save === 'function') {
119
- return await news.save();
120
- }
121
- const { _id, ...update } = news;
122
- return await this.findByIdAndUpdate(_id, update, { new: true });
118
+ const update = news.toObject ? news.toObject() : news;
119
+ delete update._id;
120
+ delete update.__v;
121
+ return await this.findOneAndUpdate(
122
+ { diffbotUri: update.diffbotUri },
123
+ update,
124
+ { upsert: true, new: true }
125
+ );
123
126
  };
124
127
 
125
128
  if (typeof cb === 'function') { run().then(result => cb(null, result), err => cb(err)); return; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "12.12.0",
3
+ "version": "12.14.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",