@dhyasama/totem-models 9.125.0 → 9.126.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 +23 -2
- package/package.json +1 -1
package/lib/Deal.js
CHANGED
|
@@ -61,8 +61,9 @@ module.exports = function(mongoose, config) {
|
|
|
61
61
|
latestMessage: { type: Schema.ObjectId, ref: 'Message', required: false },
|
|
62
62
|
|
|
63
63
|
applications: [{
|
|
64
|
-
|
|
65
|
-
appliedOn: { type: Date, default: Date.now }
|
|
64
|
+
application: { type: String, trim: true },
|
|
65
|
+
appliedOn: { type: Date, default: Date.now },
|
|
66
|
+
appliedBy: { type: String, trim: true }
|
|
66
67
|
}]
|
|
67
68
|
|
|
68
69
|
});
|
|
@@ -249,6 +250,26 @@ module.exports = function(mongoose, config) {
|
|
|
249
250
|
|
|
250
251
|
};
|
|
251
252
|
|
|
253
|
+
Deal.statics.getByApplication = function (application, options, cb) {
|
|
254
|
+
|
|
255
|
+
let self = this;
|
|
256
|
+
|
|
257
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
258
|
+
if (!application) { return cb(new Error('application is required'), null); }
|
|
259
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
260
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
261
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
262
|
+
|
|
263
|
+
let query = self.find({
|
|
264
|
+
'applications.application': application,
|
|
265
|
+
'customer': options.CUSTOMER_ID
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
query.populate('organization', 'name description');
|
|
269
|
+
query.exec(cb);
|
|
270
|
+
|
|
271
|
+
};
|
|
272
|
+
|
|
252
273
|
// Get a deal for a org, belonging to current customer
|
|
253
274
|
Deal.statics.getForOrg = function (orgId, options, cb) {
|
|
254
275
|
|