@dhyasama/totem-models 2.2.3 → 2.3.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
@@ -53,6 +53,7 @@ var bootstrap = function(mongoose, config) {
53
53
  require('./lib/Activity.js')(mongoose, config);
54
54
  require('./lib/CalendarEvent.js')(mongoose, config);
55
55
  require('./lib/CapTable.js')(mongoose, config);
56
+ require('./lib/Financials.js')(mongoose, config);
56
57
  require('./lib/Interaction.js')(mongoose, config);
57
58
  require('./lib/Investment.js')(mongoose, config);
58
59
  require('./lib/List.js')(mongoose, config);
@@ -111,6 +111,17 @@ module.exports = function(mongoose, config) {
111
111
  .exec(cb);
112
112
  };
113
113
 
114
+ CalendarEvent.statics.markAsProcessed = function markAsProcessed(id, cb) {
115
+
116
+ var self = this;
117
+ var filter = { '_id': id };
118
+ var update = { $set: { processed: true } };
119
+ var options = { 'upsert': false, 'new': true };
120
+
121
+ self.findOneAndUpdate(filter, update, options, cb);
122
+
123
+ };
124
+
114
125
  CalendarEvent.statics.upsert = function(calendarEvent, cb) {
115
126
 
116
127
  var self = this;
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+
3
+ ///////////////////////////////////////////////////////////////////////////////////////
4
+ // NOTES
5
+ //
6
+ // This is private data
7
+ //
8
+ ///////////////////////////////////////////////////////////////////////////////////////
9
+
10
+ module.exports = function(mongoose, config) {
11
+
12
+ var Schema = mongoose.Schema;
13
+ var Round = mongoose.model('Round');
14
+ var async = require('async');
15
+ var _ = require('underscore');
16
+
17
+ var Financials = 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
+ asOfDate: { type: Date, required: true },
24
+ burn: { type: Number, default: 0 },
25
+ runway: { type: Number, default: 0 },
26
+ cashBalance: { type: Number, default: 0 },
27
+
28
+ revenue: {
29
+ ytd: { type: Number, default: 0 },
30
+ projected: { type: Number, default: 0 },
31
+ past: [{
32
+ year: { type: Number, default: 0 },
33
+ amount: { type: Number, default: 0 }
34
+ }]
35
+ },
36
+
37
+ expenses: {
38
+ ytd: { type: Number, default: 0 },
39
+ projected: { type: Number, default: 0 },
40
+ past: [{
41
+ year: { type: Number, default: 0 },
42
+ amount: { type: Number, default: 0 }
43
+ }]
44
+ },
45
+
46
+ grossProfit: {
47
+ ytd: { type: Number, default: 0 },
48
+ projected: { type: Number, default: 0 },
49
+ past: [{
50
+ year: { type: Number, default: 0 },
51
+ amount: { type: Number, default: 0 }
52
+ }]
53
+ },
54
+
55
+ operatingIncome: {
56
+ ytd: { type: Number, default: 0 },
57
+ projected: { type: Number, default: 0 },
58
+ past: [{
59
+ year: { type: Number, default: 0 },
60
+ amount: { type: Number, default: 0 }
61
+ }]
62
+ },
63
+
64
+ // Catch-all for customer specific key-value pairs from sheet that aren't supported by our schema
65
+ details: [{
66
+ key: { type: String, trim: true, required: true },
67
+ value: { type: String, trim: true, required: true },
68
+ _id: false
69
+ }],
70
+
71
+ });
72
+
73
+
74
+
75
+ ///////////////////////////////////////////////////////////////////////////////////////
76
+ // VIRTUALS
77
+ // Properties that are not persisted to the database
78
+ ///////////////////////////////////////////////////////////////////////////////////////
79
+
80
+
81
+
82
+ //////////////////////////////////////////////////////
83
+ // STATICS
84
+ // Statics operate on the entire collection
85
+ //////////////////////////////////////////////////////
86
+
87
+ Financials.statics.getByOrg = function getByOrg(orgId, cb) {
88
+
89
+ var self = this;
90
+
91
+ var query = self.find({
92
+ 'organization': orgId,
93
+ 'customer': config.CUSTOMER_ID
94
+ });
95
+
96
+ query.exec(function(err, rounds) {
97
+
98
+ if (err) return cb(err, null);
99
+ if (!rounds || rounds.length == 0) return cb(null, []);
100
+
101
+ var error = checkForUnpopulatedData(rounds, 'Round.getByOrg');
102
+ if (error) return cb(error, null);
103
+
104
+ // reverse chronological
105
+ rounds = _.sortBy(rounds, function(r) {
106
+
107
+ var date = r.closingDate;
108
+
109
+ // use investment date in absence of closing date
110
+ if (!date && r.vehicles.length && r.vehicles[0].investments.length) {
111
+ date = r.vehicles[0].investments[0].investmentDate;
112
+ }
113
+
114
+ return date;
115
+
116
+ }).reverse();
117
+
118
+ return cb(null, rounds);
119
+
120
+ });
121
+
122
+ };
123
+
124
+ Financials.statics.removeCustomerFinancials = function removeCustomerFinancials(customerId, cb) {
125
+
126
+ var self = this;
127
+
128
+ self
129
+ .remove({customer: customerId})
130
+ .exec(cb);
131
+
132
+ };
133
+
134
+ Financials.statics.upsert = function upsert(financials, cb) {
135
+ if (!financials) { return cb(new Error('financials is required'), null); }
136
+ financials.save(cb);
137
+ };
138
+
139
+
140
+
141
+ ///////////////////////////////////////////////////////////////////////////////////////
142
+ // HOOKS
143
+ // Pre-save: fired on every document before it is saved
144
+ // Post-init: fired on every document when it's returned from a query
145
+ // Post-remove: fired on every document after it's deleted
146
+ ///////////////////////////////////////////////////////////////////////////////////////
147
+
148
+ Financials.pre('save', function(next) {
149
+
150
+ var self = this;
151
+
152
+ // todo
153
+
154
+ return next();
155
+
156
+ });
157
+
158
+ Financials.post('init', function(doc, next) {
159
+
160
+ doc.revenue.past = _.sortBy(doc.revenue.past, '-year');
161
+ doc.expenses.past = _.sortBy(doc.expenses.past, '-year');
162
+ doc.grossProfit.past = _.sortBy(doc.grossProfit.past, '-year');
163
+ doc.operatingIncome.past = _.sortBy(doc.operatingIncome.past, '-year');
164
+
165
+ return next();
166
+
167
+ });
168
+
169
+ Financials.post('remove', function(doc) {
170
+ // todo
171
+ });
172
+
173
+
174
+
175
+ ///////////////////////////////////////////////////////////////////////////////////////
176
+ // CONFIG
177
+ ///////////////////////////////////////////////////////////////////////////////////////
178
+
179
+ Financials.set('toJSON', { virtuals: true });
180
+ Financials.set('autoIndex', false);
181
+
182
+ Financials.on('index', function(err) { console.log('error building financials indexes: ' + err); });
183
+
184
+ mongoose.model('Financials', Financials);
185
+
186
+ };
187
+
188
+
@@ -778,7 +778,8 @@ module.exports = function(mongoose, config) {
778
778
  'people': {
779
779
  $elemMatch: {
780
780
  'person': personId,
781
- 'board': { $in: ['chairman', 'director', 'observer'] }
781
+ 'board': { $in: ['chairman', 'director', 'observer'] },
782
+ 'current': true
782
783
  }
783
784
  }
784
785
  })
@@ -1208,15 +1209,15 @@ module.exports = function(mongoose, config) {
1208
1209
 
1209
1210
  };
1210
1211
 
1211
- Organization.statics.modify = function(orgId, update, cb) {
1212
+ Organization.statics.modify = function(filter, update, cb) {
1212
1213
 
1213
1214
  if (!cb) throw new Error('cb is required');
1214
- if (!orgId) { return cb(new Error('orgId is required'), null); }
1215
+ if (!filter) { return cb(new Error('filter is required'), null); }
1215
1216
  if (!update) { return cb(new Error('update is required'), null); }
1216
1217
 
1217
1218
  var self = this;
1218
1219
 
1219
- self.findOneAndUpdate({ _id: orgId }, update, { upsert: false, new: true }, cb);
1220
+ self.findOneAndUpdate(filter, update, { upsert: false, new: true }, cb);
1220
1221
 
1221
1222
  };
1222
1223
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "2.2.3",
3
+ "version": "2.3.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",