@dhyasama/totem-models 7.57.0 → 8.0.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/.npmignore +14 -0
- package/helpers.js +89 -0
- package/index.js +0 -1
- package/lib/Account.js +125 -79
- package/lib/Activity.js +0 -2
- package/lib/CalendarEvent.js +1 -7
- package/lib/CapTable.js +0 -1
- package/lib/Deal.js +215 -151
- package/lib/Document.js +57 -56
- package/lib/Financials.js +115 -172
- package/lib/Flag.js +37 -14
- package/lib/Fund.js +6 -33
- package/lib/Interaction.js +79 -32
- package/lib/Investment.js +4 -10
- package/lib/LimitedPartner.js +303 -634
- package/lib/List.js +105 -147
- package/lib/Message.js +100 -51
- package/lib/News.js +1 -53
- package/lib/Note.js +60 -66
- package/lib/Organization.js +470 -645
- package/lib/Person.js +342 -650
- package/lib/Round.js +191 -134
- package/lib/Snapshot.js +3 -5
- package/lib/Webhook.js +1 -4
- package/package-lock.json +1927 -0
- package/package.json +2 -3
- package/test/Account.js +53 -38
- package/test/Deal.js +14 -30
- package/test/Document.js +51 -50
- package/test/Financials.js +5 -3
- package/test/Flag.js +18 -14
- package/test/Interaction.js +1 -31
- package/test/Investment.js +2 -3
- package/test/LimitedPartner.js +399 -554
- package/test/List.js +24 -29
- package/test/Message.js +7 -46
- package/test/News.js +12 -29
- package/test/Note.js +23 -22
- package/test/Organization.js +33 -307
- package/test/Person.js +6 -253
- package/test/Round.js +11 -11
- package/lib/Sync.js +0 -48
package/lib/Document.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = function(mongoose, config) {
|
|
4
4
|
|
|
5
5
|
var
|
|
6
6
|
|
|
7
7
|
Schema = mongoose.Schema,
|
|
8
|
-
|
|
9
|
-
s3 = require('@dhyasama/ffvc-s3'),
|
|
10
|
-
utils = require('@dhyasama/ffvc-utilities'),
|
|
11
|
-
postFind = require('mongoose-post-find'),
|
|
8
|
+
utilities = require('@dhyasama/ffvc-utilities'),
|
|
12
9
|
_ = require('underscore');
|
|
13
10
|
|
|
14
11
|
var Document = new Schema({
|
|
@@ -50,14 +47,14 @@ module.exports = function(mongoose, config) {
|
|
|
50
47
|
|
|
51
48
|
// Probably an Exchange file
|
|
52
49
|
// Exchange creates files such as ATT00001.htm and ATT00002.txt, one for each attachment
|
|
53
|
-
if (name.indexOf('ATT00')
|
|
50
|
+
if (name.indexOf('ATT00') === 0) return true;
|
|
54
51
|
|
|
55
52
|
// Google Calendar invitation
|
|
56
53
|
// No need to show since it's in-lined
|
|
57
|
-
else if (name
|
|
54
|
+
else if (name === 'INVITE.ICS' || name === 'INVITATION.ICS') return true;
|
|
58
55
|
|
|
59
56
|
// Probably a signature logo
|
|
60
|
-
else if (name.indexOf('IMAGE0')
|
|
57
|
+
else if (name.indexOf('IMAGE0') === 0 && contentLength < 3000) return true;
|
|
61
58
|
|
|
62
59
|
else return false;
|
|
63
60
|
|
|
@@ -79,7 +76,7 @@ module.exports = function(mongoose, config) {
|
|
|
79
76
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
80
77
|
|
|
81
78
|
Document.methods.friendlyFilesize = function() {
|
|
82
|
-
return
|
|
79
|
+
return utilities.humanizeFilesize(this.contentLength);
|
|
83
80
|
};
|
|
84
81
|
|
|
85
82
|
|
|
@@ -91,6 +88,8 @@ module.exports = function(mongoose, config) {
|
|
|
91
88
|
|
|
92
89
|
Document.statics.createForModel = function(doc, Model, modelId, cb) {
|
|
93
90
|
|
|
91
|
+
// No population so no need to scrub
|
|
92
|
+
|
|
94
93
|
var addToModel = function(err, createdDoc) {
|
|
95
94
|
if (err) return cb(err, null);
|
|
96
95
|
Model.findByIdAndUpdate(modelId, { $push: { documents: createdDoc }}, { new: true, upsert: false }, function(err, addedTo) {
|
|
@@ -107,52 +106,83 @@ module.exports = function(mongoose, config) {
|
|
|
107
106
|
|
|
108
107
|
};
|
|
109
108
|
|
|
110
|
-
Document.statics.delete = function(id, cb) {
|
|
109
|
+
Document.statics.delete = function(id, options, cb) {
|
|
111
110
|
|
|
112
|
-
|
|
111
|
+
let self = this;
|
|
112
|
+
|
|
113
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
114
|
+
if (!id) { return cb(new Error('id is required'), null); }
|
|
115
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
116
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
117
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
118
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
113
119
|
|
|
114
120
|
// Not strictly necessary but provides verification that the document being deleted belongs to the customer doing the deleting
|
|
115
|
-
|
|
121
|
+
|
|
122
|
+
let query = self.findOne({
|
|
116
123
|
'_id': id,
|
|
117
|
-
'customer':
|
|
118
|
-
}
|
|
124
|
+
'customer': options.CUSTOMER_ID
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
query.exec(function(err, doc) {
|
|
119
128
|
|
|
120
129
|
if (err) return cb(err, null);
|
|
121
130
|
else if (!doc) return cb(null, null);
|
|
122
131
|
|
|
132
|
+
// No population so no need to scrub
|
|
133
|
+
|
|
123
134
|
doc.remove(cb);
|
|
124
135
|
|
|
125
136
|
});
|
|
126
137
|
|
|
127
138
|
};
|
|
128
139
|
|
|
129
|
-
Document.statics.getById = function (id, cb) {
|
|
140
|
+
Document.statics.getById = function (id, options, cb) {
|
|
130
141
|
|
|
131
|
-
|
|
142
|
+
let self = this;
|
|
132
143
|
|
|
133
|
-
|
|
144
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
145
|
+
if (!id) { return cb(new Error('id is required'), null); }
|
|
146
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
147
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
148
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
149
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
150
|
+
|
|
151
|
+
let query = self.findOne({
|
|
134
152
|
'_id': id,
|
|
135
|
-
'customer':
|
|
136
|
-
})
|
|
137
|
-
|
|
153
|
+
'customer': options.CUSTOMER_ID
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// No population so no need to scrub
|
|
157
|
+
|
|
158
|
+
query.exec(cb);
|
|
159
|
+
|
|
138
160
|
};
|
|
139
161
|
|
|
140
|
-
Document.statics.modifyById = function(id, update, cb) {
|
|
162
|
+
Document.statics.modifyById = function(id, update, options, cb) {
|
|
163
|
+
|
|
164
|
+
let self = this;
|
|
141
165
|
|
|
142
166
|
// VERY IMPORTANT NOTE
|
|
143
167
|
// findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
|
|
144
168
|
|
|
145
|
-
if (!cb) throw new Error('cb is required');
|
|
169
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
146
170
|
if (!id) { return cb(new Error('id is required'), null); }
|
|
171
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
147
172
|
if (!update) { return cb(new Error('update is required'), null); }
|
|
148
|
-
|
|
149
|
-
|
|
173
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
174
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
175
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
150
176
|
|
|
151
177
|
// https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
152
178
|
// options runValidators defaults false which is ok since we have upsert false
|
|
153
179
|
// new returns the updated document
|
|
154
180
|
|
|
155
|
-
self.
|
|
181
|
+
let query = self.findOneAndUpdate({ _id: id, customer: options.CUSTOMER_ID }, update, { upsert: false, new: true });
|
|
182
|
+
|
|
183
|
+
// No population so no need to scrub
|
|
184
|
+
|
|
185
|
+
query.exec(cb);
|
|
156
186
|
|
|
157
187
|
};
|
|
158
188
|
|
|
@@ -160,40 +190,12 @@ module.exports = function(mongoose, config) {
|
|
|
160
190
|
|
|
161
191
|
if (!doc) { return cb(new Error('doc is required'), null); }
|
|
162
192
|
|
|
193
|
+
// No population so no need to scrub
|
|
194
|
+
|
|
163
195
|
doc.save(cb);
|
|
164
196
|
|
|
165
197
|
};
|
|
166
198
|
|
|
167
|
-
Document.plugin(postFind, {
|
|
168
|
-
|
|
169
|
-
find: function(results, done) {
|
|
170
|
-
|
|
171
|
-
var CUSTOMER_ID = config.CUSTOMER_ID;
|
|
172
|
-
|
|
173
|
-
if (CUSTOMER_ID == 'GLOBAL_PROCESS') return done(null, results);
|
|
174
|
-
|
|
175
|
-
// Reject any item that is for a different customer
|
|
176
|
-
results = _.reject(results, function(item) {
|
|
177
|
-
return item.customer.toString() != CUSTOMER_ID;
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
return done(null, results);
|
|
181
|
-
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
findOne: function(result, done) {
|
|
185
|
-
|
|
186
|
-
var CUSTOMER_ID = config.CUSTOMER_ID;
|
|
187
|
-
|
|
188
|
-
if (!result) return done(null, null);
|
|
189
|
-
else if (CUSTOMER_ID == 'GLOBAL_PROCESS') return done(null, result);
|
|
190
|
-
else if (result.customer.toString() == CUSTOMER_ID) return done(null, result);
|
|
191
|
-
else return done(null, null);
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
});
|
|
196
|
-
|
|
197
199
|
|
|
198
200
|
|
|
199
201
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
@@ -202,7 +204,6 @@ module.exports = function(mongoose, config) {
|
|
|
202
204
|
|
|
203
205
|
Document.set('toJSON', { virtuals: true });
|
|
204
206
|
Document.set('autoIndex', false);
|
|
205
|
-
Document.set('usePushEach', true);
|
|
206
207
|
Document.on('index', function(err) { console.log('error building document indexes: ' + err); });
|
|
207
208
|
|
|
208
209
|
mongoose.model('Document', Document);
|