@dhyasama/totem-models 5.9.2 → 5.10.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/lib/Deal.js +97 -12
- package/lib/Organization.js +1 -1
- package/package.json +1 -1
package/lib/Deal.js
CHANGED
|
@@ -48,12 +48,17 @@ module.exports = function(mongoose, config) {
|
|
|
48
48
|
timestamp: { type: Date, required: true, default: Date.now },
|
|
49
49
|
account: { type: Schema.ObjectId, ref: 'Account', required: true },
|
|
50
50
|
stage: { type: String, required: true },
|
|
51
|
+
fundraise: {
|
|
52
|
+
amount: { type: Number, default: 0 },
|
|
53
|
+
valuation: { type: Number, default: 0 },
|
|
54
|
+
details: { type: String, trim: true }
|
|
55
|
+
},
|
|
51
56
|
description: { type: String, trim: true, required: true }
|
|
52
57
|
}],
|
|
53
58
|
|
|
54
59
|
votes: [{
|
|
55
60
|
timestamp: { type: Date, required: true, default: Date.now },
|
|
56
|
-
account: { type: Schema.ObjectId, ref: '
|
|
61
|
+
account: { type: Schema.ObjectId, ref: 'Person', required: true },
|
|
57
62
|
value: { type: Number }
|
|
58
63
|
}]
|
|
59
64
|
|
|
@@ -167,6 +172,7 @@ module.exports = function(mongoose, config) {
|
|
|
167
172
|
.populate('messages')
|
|
168
173
|
.populate('sources.person', 'name avatarUrl title')
|
|
169
174
|
.populate('referrers.person', 'name avatarUrl title')
|
|
175
|
+
.populate('votes.account', 'name avatarUrl title')
|
|
170
176
|
.populate({
|
|
171
177
|
path: 'documents',
|
|
172
178
|
match: { customer: customerId }
|
|
@@ -218,8 +224,30 @@ module.exports = function(mongoose, config) {
|
|
|
218
224
|
path: 'documents',
|
|
219
225
|
match: { customer: config.CUSTOMER_ID }
|
|
220
226
|
})
|
|
221
|
-
.
|
|
222
|
-
|
|
227
|
+
.exec(function(err, deal) {
|
|
228
|
+
if(deal && deal.history) {
|
|
229
|
+
deal.deepPopulate('history.account.person', {
|
|
230
|
+
populate: { 'history.account.person': { select: 'name avatarUrl title doNotDisplay' } }
|
|
231
|
+
}, cb);
|
|
232
|
+
}
|
|
233
|
+
else cb(err, deal);
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
Deal.statics.addVote = function(dealId, user, vote, cb) {
|
|
238
|
+
|
|
239
|
+
var self = this;
|
|
240
|
+
|
|
241
|
+
self.findByIdAndUpdate(dealId, {$push:
|
|
242
|
+
{
|
|
243
|
+
votes: {
|
|
244
|
+
timestamp: new Date(),
|
|
245
|
+
account: user,
|
|
246
|
+
value: vote
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}, cb);
|
|
250
|
+
|
|
223
251
|
};
|
|
224
252
|
|
|
225
253
|
Deal.statics.upsert = function upsert(deal, user, cb) {
|
|
@@ -239,21 +267,78 @@ module.exports = function(mongoose, config) {
|
|
|
239
267
|
|
|
240
268
|
};
|
|
241
269
|
|
|
270
|
+
var getLastFundraiseAmount = function() {
|
|
271
|
+
|
|
272
|
+
if (!deal.history || deal.history.length == 0) return null;
|
|
273
|
+
|
|
274
|
+
var history = _.sortBy(deal.history);
|
|
275
|
+
var last = history[history.length - 1];
|
|
276
|
+
|
|
277
|
+
return last.fundraise.amount;
|
|
278
|
+
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
var getLastFundraiseValuation = function() {
|
|
282
|
+
|
|
283
|
+
if (!deal.history || deal.history.length == 0) return null;
|
|
284
|
+
|
|
285
|
+
var history = _.sortBy(deal.history);
|
|
286
|
+
var last = history[history.length - 1];
|
|
287
|
+
|
|
288
|
+
return last.fundraise.valuation;
|
|
289
|
+
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
var getLastFundraiseDetails = function () {
|
|
293
|
+
|
|
294
|
+
if (!deal.history || deal.history.length == 0 || !deal.fundraise.description) return null;
|
|
295
|
+
|
|
296
|
+
var history = _.sortBy(deal.history);
|
|
297
|
+
var last = history[history.length - 1];
|
|
298
|
+
|
|
299
|
+
return last.fundraise.details;
|
|
300
|
+
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
var formatMoney = function(n, c, d, t) {
|
|
304
|
+
var c = isNaN(c = Math.abs(c)) ? 2 : c,
|
|
305
|
+
d = d == undefined ? "." : d,
|
|
306
|
+
t = t == undefined ? "," : t,
|
|
307
|
+
s = n < 0 ? "-" : "",
|
|
308
|
+
i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))),
|
|
309
|
+
j = (j = i.length) > 3 ? j % 3 : 0;
|
|
310
|
+
|
|
311
|
+
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
|
|
312
|
+
};
|
|
313
|
+
|
|
242
314
|
var description = '';
|
|
243
315
|
var lastStage = getLastStage();
|
|
316
|
+
var lastFundraiseAmount = getLastFundraiseAmount();
|
|
317
|
+
var lastFundraiseValuation = getLastFundraiseValuation();
|
|
318
|
+
var lastFundraiseDetails = getLastFundraiseDetails();
|
|
244
319
|
|
|
245
320
|
if (lastStage == null) description = 'The deal was created';
|
|
246
|
-
else
|
|
247
|
-
|
|
321
|
+
else {
|
|
322
|
+
if (lastStage != deal.stage) description += 'The deal was updated from ' + lastStage + ' to ' + deal.stage;
|
|
323
|
+
if (lastFundraiseAmount != deal.fundraise.amount) description += 'Fundraise amount was updated from $' + formatMoney(lastFundraiseAmount, 0) + ' to $' + formatMoney(deal.fundraise.amount, 0);
|
|
324
|
+
if (lastFundraiseValuation != deal.fundraise.valuation) description += 'Fundraise valuation was updated from $' + formatMoney(lastFundraiseValuation, 0) + ' to $' + formatMoney(deal.fundraise.valuation, 0);
|
|
325
|
+
if (lastFundraiseDetails != deal.fundraise.details) description += 'Fundraise details were updated from $' + lastFundraiseDetails + ' to ' + deal.fundraise.details;
|
|
326
|
+
}
|
|
248
327
|
|
|
249
|
-
|
|
328
|
+
// only add history if the description is set from the above conditions
|
|
329
|
+
if(description != '') {
|
|
250
330
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
331
|
+
deal.history = deal.history || [];
|
|
332
|
+
|
|
333
|
+
deal.history.push({
|
|
334
|
+
timestamp: new Date(),
|
|
335
|
+
account: user,
|
|
336
|
+
stage: deal.stage,
|
|
337
|
+
fundraise: deal.fundraise,
|
|
338
|
+
description: description
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
}
|
|
257
342
|
|
|
258
343
|
deal.save(cb);
|
|
259
344
|
|
package/lib/Organization.js
CHANGED
|
@@ -210,7 +210,7 @@ module.exports = function(mongoose, config) {
|
|
|
210
210
|
active: { type: Boolean, default: true }
|
|
211
211
|
}],
|
|
212
212
|
voting: {
|
|
213
|
-
active: { type: Boolean, default:
|
|
213
|
+
active: { type: Boolean, default: false },
|
|
214
214
|
votes: [{
|
|
215
215
|
name: { type: String, trim: true },
|
|
216
216
|
value: { type: Number }
|