@dhyasama/totem-models 12.3.0 → 12.4.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/Snapshot.js CHANGED
@@ -13,19 +13,24 @@ module.exports = function(mongoose, config) {
13
13
 
14
14
  });
15
15
 
16
- Snapshot.statics.getByDocId = function getByDocId(docId, cb) {
16
+ Snapshot.statics.getByDocId = async function getByDocId(docId, cb) {
17
17
 
18
- const self = this;
19
-
20
- self
21
- .find({ 'doc._id': docId })
22
- .sort({ changedOn: -1 })
23
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
18
+ try {
19
+ const result = await this.find({ 'doc._id': docId }).sort({ changedOn: -1 });
20
+ return cb(null, result);
21
+ } catch(err) {
22
+ return cb(err);
23
+ }
24
24
 
25
25
  };
26
26
 
27
- Snapshot.statics.upsert = function(snapshot, cb) {
28
- snapshot.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
27
+ Snapshot.statics.upsert = async function(snapshot, cb) {
28
+ try {
29
+ const result = await snapshot.save();
30
+ return cb(null, result);
31
+ } catch(err) {
32
+ return cb(err);
33
+ }
29
34
  };
30
35
  mongoose.model('Snapshot', Snapshot, '_Snapshots');
31
36
 
package/lib/Sync.js CHANGED
@@ -13,7 +13,7 @@ module.exports = function(mongoose, config) {
13
13
  syncedOn: { type: Date, required: true },
14
14
  completedOn: { type: Date },
15
15
  syncedBy: { type: String, trim: true },
16
- steps: [{
16
+ steps: [{
17
17
  _id: false,
18
18
  name: { type: String, trim: true },
19
19
  tasks: [{
@@ -24,23 +24,31 @@ module.exports = function(mongoose, config) {
24
24
  }]
25
25
  });
26
26
 
27
- Sync.statics.getById = function (id, customerId, cb) {
27
+ Sync.statics.getById = async function (id, customerId, cb) {
28
28
 
29
- var self = this;
30
-
31
- self.findOne({
32
- '_id': id,
33
- 'customer': customerId
34
- }).exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
29
+ try {
30
+ const result = await this.findOne({
31
+ '_id': id,
32
+ 'customer': customerId
33
+ });
34
+ return cb(null, result);
35
+ } catch(err) {
36
+ return cb(err);
37
+ }
35
38
 
36
39
  };
37
40
 
38
- Sync.statics.upsert = function(sync, cb) {
41
+ Sync.statics.upsert = async function(sync, cb) {
39
42
  sync.syncedOn = new Date();
40
- sync.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
43
+ try {
44
+ const result = await sync.save();
45
+ return cb(null, result);
46
+ } catch(err) {
47
+ return cb(err);
48
+ }
41
49
  };
42
50
  Sync.set('autoIndex', false);
43
51
 
44
52
  mongoose.model('Sync', Sync, 'syncs');
45
53
 
46
- };
54
+ };
package/lib/Webhook.js CHANGED
@@ -16,12 +16,17 @@ module.exports = function(mongoose, config) {
16
16
 
17
17
  });
18
18
 
19
- Webhook.statics.upsert = function(webhook, cb) {
19
+ Webhook.statics.upsert = async function(webhook, cb) {
20
20
  webhook.createdOn = new Date();
21
- webhook.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
21
+ try {
22
+ const result = await webhook.save();
23
+ return cb(null, result);
24
+ } catch(err) {
25
+ return cb(err);
26
+ }
22
27
  };
23
28
  Webhook.set('autoIndex', false);
24
29
 
25
30
  mongoose.model('Webhook', Webhook);
26
31
 
27
- };
32
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "12.3.0",
3
+ "version": "12.4.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",