jsft-mongodb
Advanced tools
Comparing version 0.6.7 to 0.6.8
@@ -438,2 +438,13 @@ 'use strict'; | ||
it('should skip update when no update props is provided', function () { | ||
_Collection2.default.updateOne.reset(); | ||
_Collection2.default.insertOne.reset(); | ||
return _Collection2.default.upsertOne('tests', _testSchema2.default, entity, {}, {}).then(function (res) { | ||
_sinon2.default.assert.notCalled(_Collection2.default.insertOne); | ||
_sinon2.default.assert.notCalled(_Collection2.default.updateOne); | ||
(0, _chai.expect)(res).to.equal(entity); | ||
}); | ||
}); | ||
it('should run insertOne for entity without id', function () { | ||
@@ -440,0 +451,0 @@ _Collection2.default.updateOne.reset(); |
@@ -348,3 +348,13 @@ 'use strict'; | ||
return entity.id ? Collection.updateOne(collectionName, schema, _extends({}, updateProps, { id: entity.id })) : Collection.insertOne(collectionName, schema, _extends({}, insertOnlyProps, updateProps)); | ||
if (entity.id !== undefined) { | ||
// Update existing entity | ||
if (Object.keys(updateProps).length === 0) { | ||
// No properties to update | ||
return Promise.resolve(entity); | ||
} | ||
return Collection.updateOne(collectionName, schema, _extends({}, updateProps, { id: entity.id })); | ||
} else { | ||
// Insert new entity | ||
return Collection.insertOne(collectionName, schema, _extends({}, insertOnlyProps, updateProps)); | ||
} | ||
}; | ||
@@ -351,0 +361,0 @@ |
{ | ||
"name": "jsft-mongodb", | ||
"version": "0.6.7", | ||
"version": "0.6.8", | ||
"description": "Functional abstraction layer for mongodb-storage of objects with structures defined with json-schema", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59012
1217