@dhyasama/totem-models 5.3.3 → 5.4.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/Deal.js CHANGED
@@ -17,6 +17,8 @@ module.exports = function(mongoose, config) {
17
17
 
18
18
  stage: { type: String, trim: true, required: true },
19
19
 
20
+ action: { type: String, trim: true },
21
+
20
22
  sources: [{
21
23
  person: { type: Schema.ObjectId, ref: 'Person', required: true },
22
24
  type: { type: String, enum: ['Inbound', 'Outbound', 'Event', 'Referral', 'Other'], required: true }
package/lib/Message.js CHANGED
@@ -262,6 +262,18 @@ module.exports = function(mongoose, config) {
262
262
 
263
263
  };
264
264
 
265
+ Message.statics.getUnprocessedDeals = function getUnprocessedDeals(customerId, cb) {
266
+
267
+ var self = this;
268
+ var query = self.find({
269
+ customer: customerId,
270
+ subtype: 'deals',
271
+ organization: { $exists: false }
272
+ });
273
+ query.exec(cb);
274
+
275
+ };
276
+
265
277
  Message.statics.upsert = function(message, cb) {
266
278
  message.createdOn = new Date();
267
279
  message.save(cb);
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "5.3.2",
3
+ "version": "5.3.4",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "5.3.3",
3
+ "version": "5.4.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
package/test/Message.js CHANGED
@@ -250,4 +250,57 @@ describe('Message', function() {
250
250
 
251
251
  });
252
252
 
253
+ it('gets unprocessed deal messages', function(done) {
254
+
255
+ var message1 = new Message({
256
+ webhook: new mongoose.Types.ObjectId(),
257
+ customer: totemCustomerId2,
258
+ subject: 'test 4',
259
+ type: 'email',
260
+ subtype: 'deals',
261
+ recipients: {
262
+ external: [new mongoose.Types.ObjectId()]
263
+ },
264
+ raw: { test: 'test' }
265
+ });
266
+
267
+ var message2 = new Message({
268
+ webhook: new mongoose.Types.ObjectId(),
269
+ customer: totemCustomerId2,
270
+ subject: 'test 5',
271
+ type: 'email',
272
+ subtype: 'deals',
273
+ recipients: {
274
+ external: [new mongoose.Types.ObjectId()]
275
+ },
276
+ raw: { test: 'test' },
277
+ organization: new mongoose.Types.ObjectId(),
278
+ });
279
+
280
+ Message.upsert(message1, function(err, result) {
281
+
282
+ should.not.exist(err);
283
+ should.exist(result);
284
+
285
+ Message.upsert(message2, function(err, result) {
286
+
287
+ should.not.exist(err);
288
+ should.exist(result);
289
+
290
+ Message.getUnprocessedDeals(totemCustomerId2, function(err, result) {
291
+
292
+ should.not.exist(err);
293
+ should.exist(result);
294
+ result.length.should.equal(1);
295
+ result[0].subject.should.equal('test 4');
296
+ done();
297
+
298
+ });
299
+
300
+ });
301
+
302
+ });
303
+
304
+ });
305
+
253
306
  });