@dhyasama/totem-models 12.28.0 → 12.30.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.
package/lib/Financials.js CHANGED
@@ -120,6 +120,12 @@ module.exports = function(mongoose, config) {
120
120
  type: Schema.Types.ObjectId,
121
121
  refPath: 'metrics.sources.model',
122
122
  },
123
+ // On a derived/formula metric, the formula component (group) this
124
+ // cell belongs to — "this cell is part of Operating Expenses".
125
+ // Component totals live once per metric in `breakdown`
126
+ // ({ group: value }), keyed by these group names. Unset on raw
127
+ // extracted metrics.
128
+ group: { type: String, trim: true },
123
129
  position: {
124
130
  _id: false,
125
131
  page: { type: Number },
@@ -162,6 +168,7 @@ module.exports = function(mongoose, config) {
162
168
  _id: false,
163
169
  model: { type: String, enum: ['Document', 'Meeting', 'Message', 'Note'] },
164
170
  ref: { type: Schema.Types.ObjectId },
171
+ group: { type: String, trim: true },
165
172
  position: {
166
173
  _id: false,
167
174
  page: { type: Number },
@@ -218,7 +218,8 @@ module.exports = function(mongoose, config) {
218
218
  },
219
219
 
220
220
  inbound: {
221
- active: { type: Boolean, default: false }
221
+ active: { type: Boolean, default: false },
222
+ forward: [{ type: String, trim: true, lowercase: true }]
222
223
  },
223
224
 
224
225
  carta: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "12.28.0",
3
+ "version": "12.30.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
@@ -130,6 +130,39 @@ describe('Financials', function() {
130
130
 
131
131
  });
132
132
 
133
+ it('getOrCreateByOrg returns one document under concurrent calls', async function() {
134
+
135
+ var customer = new mongoose.Types.ObjectId();
136
+ var org = new mongoose.Types.ObjectId();
137
+
138
+ // mirror production's unique index so the losing writer of a race can never insert a duplicate
139
+ await Financials.collection.createIndex({ customer: 1, organization: 1 }, { unique: true });
140
+
141
+ var results = await Promise.all(
142
+ Array.from({ length: 10 }, function() { return Financials.getOrCreateByOrg(customer, org); })
143
+ );
144
+
145
+ var ids = new Set(results.map(function(r) { return r._id.toString(); }));
146
+ ids.size.should.equal(1);
147
+
148
+ var count = await Financials.countDocuments({ customer: customer, organization: org });
149
+ count.should.equal(1);
150
+
151
+ });
152
+
153
+ it('getOrCreateByOrg returns the existing document', function(done) {
154
+
155
+ Financials.getOrCreateByOrg(customerA, orgA, function(err, result) {
156
+ should.not.exist(err);
157
+ should.exist(result);
158
+ result.customer.toString().should.equal(customerA.toString());
159
+ result.organization.toString().should.equal(orgA.toString());
160
+ should.exist(result.asOfDate); // proves it found the doc created above, not a fresh one
161
+ done();
162
+ });
163
+
164
+ });
165
+
133
166
  describe.skip('old so skip for now', function() {
134
167
 
135
168
  it('gets financials for an org', function(done) {