@dhyasama/totem-models 10.56.1 → 10.57.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.
Files changed (2) hide show
  1. package/lib/Financials.js +28 -0
  2. package/package.json +1 -1
package/lib/Financials.js CHANGED
@@ -349,6 +349,34 @@ module.exports = function(mongoose, config) {
349
349
 
350
350
  };
351
351
 
352
+ Financials.statics.getDocument = function getDocument(documentId, cb) {
353
+
354
+ if (!cb) { throw new Error('cb is required'); }
355
+ if (!documentId) { return cb(new Error('documentId is required'), null); }
356
+ if (!mongoose.Types.ObjectId.isValid(documentId)) { return cb(new Error('documentId is not a valid ObjectId'), null); }
357
+
358
+ const self = this;
359
+
360
+ self.aggregate([
361
+ { $unwind: '$snapshots' },
362
+ { $unwind: '$snapshots.documents' },
363
+ { $match: { 'snapshots.documents.document': documentId } },
364
+ {
365
+ $project: {
366
+ uuid: '$snapshots.uuid',
367
+ document: '$snapshots.documents'
368
+ }
369
+ }
370
+ ]).exec(function(err, result) {
371
+
372
+ if (err) return cb(err);
373
+ else if (result.length > 0) { return cb(null, { uuid: result[0].uuid, document: result[0].document }); }
374
+ else { return cb(null, null); }
375
+
376
+ });
377
+
378
+ };
379
+
352
380
  Financials.statics.getRecurringToSend = function getRecurringToSend(options, cb) {
353
381
 
354
382
  const self = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "10.56.1",
3
+ "version": "10.57.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",