@dhyasama/totem-models 1.30.1 → 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 +7 -0
- package/package.json +1 -1
- package/test/Organization.js +14 -1
package/lib/Organization.js
CHANGED
|
@@ -1319,6 +1319,13 @@ module.exports = function(mongoose, config) {
|
|
|
1319
1319
|
// remove customer details if not viewing self
|
|
1320
1320
|
if (doc._id.toString() != CUSTOMER_ID) doc.customer = {};
|
|
1321
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
|
+
|
|
1322
1329
|
doc.lps = _.reject(doc.lps, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1323
1330
|
doc.filters = _.reject(doc.filters, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1324
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,6 +841,7 @@ 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');
|
|
@@ -849,7 +850,19 @@ describe('Organization', function() {
|
|
|
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
|
});
|