@dhyasama/totem-models 11.29.0 → 11.30.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/index.js CHANGED
@@ -67,6 +67,7 @@ var bootstrap = function(mongoose, config) {
67
67
  require('./lib/Event.js')(mongoose, config);
68
68
  require('./lib/EventAttendee.js')(mongoose, config);
69
69
  require('./lib/Financials.js')(mongoose, config);
70
+ require('./lib/FinancialsAnalysis.js')(mongoose, config);
70
71
  require('./lib/Folder.js')(mongoose, config);
71
72
  require('./lib/Interaction.js')(mongoose, config);
72
73
  require('./lib/Investment.js')(mongoose, config);
@@ -0,0 +1,156 @@
1
+ 'use strict';
2
+
3
+ ///////////////////////////////////////////////////////////////////////////////////////
4
+ // NOTES
5
+ //
6
+ // This is private data
7
+ //
8
+ ///////////////////////////////////////////////////////////////////////////////////////
9
+
10
+ const _ = require("underscore");
11
+ module.exports = function(mongoose, config) {
12
+
13
+ const Schema = mongoose.Schema;
14
+ const _ = require('underscore');
15
+ const moment = require('moment');
16
+
17
+ const FinancialsAnalysis = new Schema({
18
+
19
+ organization: { type: Schema.ObjectId, ref: 'Organization', required: true, index: true },
20
+
21
+ customer: { type: Schema.ObjectId, ref: 'Organization', required: true, index: true },
22
+
23
+ financials: { type: Schema.ObjectId, ref: 'Financials', required: true, index: true },
24
+
25
+ snapshotUUID: { type: String, required: true, index: true },
26
+
27
+ summary: { type: String },
28
+
29
+ insights: [{ type: String }]
30
+
31
+ });
32
+
33
+ FinancialsAnalysis.statics.getByOrg = function getByOrg(orgId, cb) {
34
+
35
+ const self = this;
36
+
37
+ var query = self.findOne({
38
+ 'customer': customerId,
39
+ 'organization': orgId
40
+ }).populate({
41
+ path: 'snapshots.documents.document',
42
+ match: { customer: customerId }
43
+ });
44
+
45
+ query.exec(cb);
46
+
47
+ };
48
+
49
+ FinancialsAnalysis.statics.getByCustomer = function getByCustomer(customerId, cb) {
50
+
51
+ var self = this;
52
+
53
+ var query = self.find({
54
+ 'customer': customerId
55
+ });
56
+
57
+ query.exec(cb);
58
+
59
+ };
60
+
61
+ FinancialsAnalysis.statics.getByFinancials= function getByFinancials(financialsId, cb) {
62
+
63
+ let self = this;
64
+
65
+ let query = self.findOne({
66
+ 'snapshots.uuid': uuid
67
+ });
68
+
69
+ query.populate('organization', 'name logoUrl website');
70
+ query.populate('customer');
71
+ query.populate('snapshots.documents.document');
72
+
73
+ query.exec(function (err, result) {
74
+
75
+ if (err) {
76
+ return cb(err, null);
77
+ }
78
+ else if (!result) {
79
+ return cb(null, null);
80
+ }
81
+ else if (!result.customer) {
82
+ return cb(null, null);
83
+ }
84
+
85
+ _.each(result.snapshots, function (snapshot) {
86
+
87
+ snapshot.documents = _.reject(snapshot.documents, function (d) {
88
+ return d.document && d.document.customer.toString() !== result.customer._id.toString();
89
+ });
90
+
91
+ });
92
+
93
+ return cb(null, result);
94
+
95
+ });
96
+
97
+ };
98
+
99
+ FinancialsAnalysis.statics.getBySnapshot= function getBySnapshot(snapshotUUID, cb) {
100
+
101
+ let self = this;
102
+
103
+ let query = self.findOne({
104
+ 'snapshots.uuid': uuid
105
+ });
106
+
107
+ query.populate('organization', 'name logoUrl website');
108
+ query.populate('customer');
109
+ query.populate('snapshots.documents.document');
110
+
111
+ query.exec(function (err, result) {
112
+
113
+ if (err) {
114
+ return cb(err, null);
115
+ }
116
+ else if (!result) {
117
+ return cb(null, null);
118
+ }
119
+ else if (!result.customer) {
120
+ return cb(null, null);
121
+ }
122
+
123
+ _.each(result.snapshots, function (snapshot) {
124
+
125
+ snapshot.documents = _.reject(snapshot.documents, function (d) {
126
+ return d.document && d.document.customer.toString() !== result.customer._id.toString();
127
+ });
128
+
129
+ });
130
+
131
+ return cb(null, result);
132
+
133
+ });
134
+
135
+ };
136
+
137
+ FinancialsAnalysis.statics.upsert = function upsert({}, cb) {
138
+
139
+ if (!financials) { return cb(new Error('financials is required'), null); }
140
+
141
+ financials.save(cb);
142
+
143
+ };
144
+
145
+ ///////////////////////////////////////////////////////////////////////////////////////
146
+ // CONFIG
147
+ ///////////////////////////////////////////////////////////////////////////////////////
148
+
149
+ FinancialsAnalysis.set('usePushEach', true);
150
+ FinancialsAnalysis.set('autoIndex', false);
151
+
152
+ FinancialsAnalysis.on('index', function(err) { console.log('error building financials analysis indexes: ' + err); });
153
+
154
+ mongoose.model('FinancialsAnalysis', FinancialsAnalysis);
155
+
156
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "11.29.0",
3
+ "version": "11.30.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",