@dhyasama/totem-models 1.30.0 → 1.30.2
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/Organization.js +15 -0
- package/package.json +1 -1
- package/test/Organization.js +15 -2
package/lib/Organization.js
CHANGED
|
@@ -1289,6 +1289,14 @@ module.exports = function(mongoose, config) {
|
|
|
1289
1289
|
});
|
|
1290
1290
|
}
|
|
1291
1291
|
|
|
1292
|
+
// Add website to website aliases
|
|
1293
|
+
// There are unique constraints on website and website aliases
|
|
1294
|
+
// This enables us to enforce uniqueness across both and across documents
|
|
1295
|
+
if (self.website && self.websiteAliases) {
|
|
1296
|
+
self.websiteAliases.push(self.website)
|
|
1297
|
+
self.websiteAliases = _.uniq(self.websiteAliases);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1292
1300
|
};
|
|
1293
1301
|
|
|
1294
1302
|
cleanContactInfo();
|
|
@@ -1311,6 +1319,13 @@ module.exports = function(mongoose, config) {
|
|
|
1311
1319
|
// remove customer details if not viewing self
|
|
1312
1320
|
if (doc._id.toString() != CUSTOMER_ID) doc.customer = {};
|
|
1313
1321
|
|
|
1322
|
+
// Website is stored in aliases to facilitate enforcing uniqueness
|
|
1323
|
+
// Remove it here to make it easier for consumers to provide a good ux
|
|
1324
|
+
// It will get added back in during pre save hook
|
|
1325
|
+
if (doc.website && doc.websiteAliases && doc.websiteAliases.length >= 1) {
|
|
1326
|
+
doc.websiteAliases = _.reject(doc.websiteAliases, function(alias) { return alias == doc.website; });
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1314
1329
|
doc.lps = _.reject(doc.lps, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1315
1330
|
doc.filters = _.reject(doc.filters, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1316
1331
|
doc.docs = _.reject(doc.docs, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
package/package.json
CHANGED
package/test/Organization.js
CHANGED
|
@@ -841,15 +841,28 @@ describe('Organization', function() {
|
|
|
841
841
|
];
|
|
842
842
|
|
|
843
843
|
Organization.upsert(temp, 'test-user', function(err, result) {
|
|
844
|
+
|
|
844
845
|
should.not.exist(err);
|
|
845
846
|
should.exist(result);
|
|
846
847
|
result.website.should.equal('www.yum.net');
|
|
847
|
-
result.websiteAliases.length.should.equal(
|
|
848
|
+
result.websiteAliases.length.should.equal(5); // the four aliases plus the primary
|
|
848
849
|
result.websiteAliases.indexOf('yum.co').should.not.equal(-1);
|
|
849
850
|
result.websiteAliases.indexOf('anglophile.co.uk').should.not.equal(-1);
|
|
850
851
|
result.websiteAliases.indexOf('abc.subdomain.com').should.not.equal(-1);
|
|
851
852
|
result.websiteAliases.indexOf('trailingslash.edu').should.not.equal(-1);
|
|
852
|
-
|
|
853
|
+
|
|
854
|
+
Organization.getById(temp._id, function(err, result) {
|
|
855
|
+
|
|
856
|
+
should.not.exist(err);
|
|
857
|
+
should.exist(result);
|
|
858
|
+
|
|
859
|
+
// main website should no longer be here because of post-find hook
|
|
860
|
+
result.websiteAliases.length.should.equal(4);
|
|
861
|
+
|
|
862
|
+
return done();
|
|
863
|
+
|
|
864
|
+
});
|
|
865
|
+
|
|
853
866
|
});
|
|
854
867
|
|
|
855
868
|
});
|