@dhyasama/totem-models 9.32.0 → 9.33.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/Event.js +28 -0
- package/package.json +1 -1
package/lib/Event.js
CHANGED
|
@@ -83,6 +83,34 @@ module.exports = function(mongoose, config) {
|
|
|
83
83
|
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
+
// Get a single event
|
|
87
|
+
// Double check customer id
|
|
88
|
+
// Optionally populate customer
|
|
89
|
+
Event.statics.getByProviderEventId = function (id, options, cb) {
|
|
90
|
+
|
|
91
|
+
const self = this;
|
|
92
|
+
|
|
93
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
94
|
+
if (!id) { return cb(new Error('id is required'), null); }
|
|
95
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
96
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
97
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
98
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
99
|
+
|
|
100
|
+
let query = self.findOne({
|
|
101
|
+
'EventId': id,
|
|
102
|
+
'customer': options.CUSTOMER_ID
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
if (options.populate) {
|
|
106
|
+
query.populate('Attendees');
|
|
107
|
+
query.populate('customer');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
query.exec(cb);
|
|
111
|
+
|
|
112
|
+
};
|
|
113
|
+
|
|
86
114
|
// Get all events a customer has held
|
|
87
115
|
// Optionally populate customer
|
|
88
116
|
Event.statics.list = function(customerId, options, cb) {
|