@dhyasama/totem-models 7.0.3 → 7.2.2

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/Financials.js CHANGED
@@ -12,6 +12,11 @@ module.exports = function(mongoose, config) {
12
12
  var Schema = mongoose.Schema;
13
13
  var async = require('async');
14
14
  var _ = require('underscore');
15
+
16
+ // scheduled
17
+ // not scheduled (skipped)
18
+ // submitted
19
+
15
20
 
16
21
  var Financials = new Schema({
17
22
 
@@ -23,26 +28,14 @@ module.exports = function(mongoose, config) {
23
28
 
24
29
  currency: { type: String, required: true, default: 'USD' },
25
30
 
26
- notifications: {
27
-
28
- company: {
29
-
30
- contact: {
31
-
32
- exclude: { type: Boolean, default: false, required: true },
33
- email: { type: String, trim: true },
34
- name: { type: String, trim: true }
35
-
36
- }
37
-
38
- }
39
-
40
- },
41
-
42
31
  snapshots: [{
43
32
 
44
33
  uuid: { type: String },
45
34
 
35
+ campaignId: { type: String },
36
+
37
+ status: { type: String },
38
+
46
39
  year: { type: Number, default: 0 },
47
40
  period: { type: String, enum: ['Annual', 'Q1', 'Q2', 'Q3', 'Q4', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] },
48
41
 
@@ -194,23 +187,6 @@ module.exports = function(mongoose, config) {
194
187
  // Methods operate on a single document
195
188
  ///////////////////////////////////////////////////////////////////////////////////////
196
189
 
197
- Financials.methods.snapshotStatus = function(uuid) {
198
-
199
- if (!uuid) { return null; }
200
-
201
- var snapshot = _.find(this.snapshots, function(s) {
202
- if (!s || !s.uuid) { return; }
203
- return s.uuid.toLowerCase() === uuid.toLowerCase();
204
- });
205
-
206
- if (!snapshot) { return null; }
207
- else if (snapshot.submittedOn) { return "Submitted"; }
208
- else if (snapshot.notifications.company.reminder.status) { return snapshot.notifications.company.reminder.status; }
209
- else if (snapshot.notifications.company.initial.status) { return snapshot.notifications.company.initial.status; }
210
- else { return null; }
211
-
212
- };
213
-
214
190
 
215
191
 
216
192
  //////////////////////////////////////////////////////
@@ -402,7 +378,26 @@ module.exports = function(mongoose, config) {
402
378
 
403
379
  var self = this;
404
380
 
405
- // todo
381
+ _.each(self.snapshots, function(snapshot) {
382
+
383
+ if(!snapshot) return;
384
+
385
+ else if(!snapshot.uuid || snapshot.submittedOn) snapshot.status = 'Completed';
386
+
387
+ else if(snapshot.notifications.company.initial.sendOn) {
388
+
389
+ var isScheduled = moment().isBefore(moment(snapshot.notifications.company.initial.sendOn));
390
+ var isOverdue = moment().subtract(30, 'd').isAfter(snapshot.notifications.company.reminder.sendOn || snapshot.notifications.company.initial.sendOn);
391
+
392
+ if(isScheduled) snapshot.status = 'Scheduled';
393
+ else if(isOverdue) snapshot.status = 'Overdue';
394
+ else snapshot.status = 'In Progress';
395
+
396
+ }
397
+
398
+ else snapshot.status = 'Not Scheduled';
399
+
400
+ });
406
401
 
407
402
  return next();
408
403
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "7.0.3",
3
+ "version": "7.2.2",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
@@ -14,7 +14,7 @@ var customerB = new mongoose.Types.ObjectId();
14
14
  var orgA = new mongoose.Types.ObjectId();
15
15
  var orgB = new mongoose.Types.ObjectId();
16
16
 
17
- describe.skip('Financials', function() {
17
+ describe('Financials', function() {
18
18
 
19
19
  before(function(done) {
20
20
  if (mongoose.connection.db) return done();
@@ -87,54 +87,77 @@ describe.skip('Financials', function() {
87
87
 
88
88
  });
89
89
 
90
- it('gets financials for an org', function(done) {
90
+ // getByOrg
91
+ // getByPostmarkMessageId
92
+ // getByUUID
93
+ // getForCampaign
94
+ // getForCustomer
95
+ // getToSend
96
+ // getUUIDsToSendInitial
97
+ // getUUIDsToSendReminder
98
+ // removeCustomerFinancials
99
+ // upsert
91
100
 
92
- Financials.getByOrg(customerA, orgA, function(err, result) {
93
- should.not.exist(err);
94
- should.exist(result);
95
- result.length.should.equal(1);
96
- result[0].monthsOfRunway.should.equal(1);
97
- done();
98
- });
101
+ it('creates a snapshot', function(done) {
102
+
103
+ // todo
104
+
105
+ done();
99
106
 
100
107
  });
101
108
 
102
- it('gets financials for the same org but different customer', function(done) {
109
+ describe.skip('old so skip for now', function() {
110
+
111
+ it('gets financials for an org', function(done) {
112
+
113
+ Financials.getByOrg(customerA, orgA, function(err, result) {
114
+ should.not.exist(err);
115
+ should.exist(result);
116
+ result.length.should.equal(1);
117
+ result[0].monthsOfRunway.should.equal(1);
118
+ done();
119
+ });
103
120
 
104
- Financials.getByOrg(customerA, orgA, function(err, result) {
105
- should.not.exist(err);
106
- should.exist(result);
107
- result.length.should.equal(1);
108
- result[0].monthsOfRunway.should.equal(4);
109
- done();
110
121
  });
111
122
 
112
- });
123
+ it('gets financials for the same org but different customer', function(done) {
113
124
 
114
- it('removes financials for a customer', function(done) {
125
+ Financials.getByOrg(customerA, orgA, function(err, result) {
126
+ should.not.exist(err);
127
+ should.exist(result);
128
+ result.length.should.equal(1);
129
+ result[0].monthsOfRunway.should.equal(4);
130
+ done();
131
+ });
115
132
 
116
- config.CUSTOMER_ID = customerA;
133
+ });
117
134
 
118
- Financials.find({}, function(err, result) {
135
+ it('removes financials for a customer', function(done) {
119
136
 
120
- should.not.exist(err);
121
- should.exist(result);
122
- result.length.should.equal(4);
137
+ config.CUSTOMER_ID = customerA;
123
138
 
124
- Financials.removeCustomerFinancials(config.CUSTOMER_ID, function(err, result) {
139
+ Financials.find({}, function(err, result) {
125
140
 
126
141
  should.not.exist(err);
127
142
  should.exist(result);
143
+ result.length.should.equal(4);
128
144
 
129
- Financials.find({}, function(err, result) {
145
+ Financials.removeCustomerFinancials(config.CUSTOMER_ID, function(err, result) {
130
146
 
131
147
  should.not.exist(err);
132
148
  should.exist(result);
133
- result.length.should.equal(2);
134
- result[0].monthsOfRunway.should.equal(3);
135
- result[1].monthsOfRunway.should.equal(4);
136
149
 
137
- done();
150
+ Financials.find({}, function(err, result) {
151
+
152
+ should.not.exist(err);
153
+ should.exist(result);
154
+ result.length.should.equal(2);
155
+ result[0].monthsOfRunway.should.equal(3);
156
+ result[1].monthsOfRunway.should.equal(4);
157
+
158
+ done();
159
+
160
+ });
138
161
 
139
162
  });
140
163