Comparing version 0.8.8 to 0.8.9
@@ -34,2 +34,8 @@ ## [Unreleased] | ||
## [0.8.9] - 2018-02-22 | ||
### Fixed | ||
* Bug when timestamps equal true in schema definition didn't update the 'updatedAt' field on update() method | ||
## [0.8.8] - 2018-02-19 | ||
@@ -439,2 +445,3 @@ | ||
[0.8.9]: https://github.com/Yonirt/moltyjs/compare/v0.8.8...v0.8.9 | ||
[0.8.8]: https://github.com/Yonirt/moltyjs/compare/v0.8.7...v0.8.8 | ||
@@ -441,0 +448,0 @@ [0.8.7]: https://github.com/Yonirt/moltyjs/compare/v0.8.6...v0.8.7 |
@@ -160,19 +160,22 @@ 'use strict'; | ||
/** | ||
* _applyDocumentOptions(): Checkf if the document has associtaed | ||
* any options from the schema settings like timestamp or discriminators | ||
* _applyTimestamps(): Checkf if the model has associtaed | ||
* any options from the schema settings like timestamp and apply | ||
* to the object | ||
* | ||
* @param {Document} doc | ||
* @param {Object} obj | ||
* @param {Sting} operation ('insert', 'update') | ||
*/ | ||
_applyDocumentOptions(doc, operation) { | ||
if (doc._options.timestamps && operation === 'insert') { | ||
doc._data['createdAt'] = new Date(); | ||
doc._data['updatedAt'] = new Date(); | ||
_applyTimestamps(obj, model, operation) { | ||
if (model._schemaOptions.timestamps && operation === 'insert') { | ||
obj._data['createdAt'] = new Date(); | ||
obj._data['updatedAt'] = new Date(); | ||
} | ||
if (doc._options.timestamps && operation === 'update') { | ||
doc._data['updatedAt'] = new Date(); | ||
if (model._schemaOptions.timestamps && operation === 'update') { | ||
obj['$currentDate'] = { | ||
updatedAt: true | ||
}; | ||
} | ||
return doc; | ||
return obj; | ||
} | ||
@@ -442,3 +445,3 @@ | ||
const docAux = _this._applyDocumentOptions(doc, 'insert'); | ||
const docAux = _this._applyTimestamps(doc, model, 'insert'); | ||
@@ -557,3 +560,3 @@ // Ensure index are created | ||
// Check and apply document options before saving | ||
const docAux = _this2._applyDocumentOptions(docs[i], 'insert'); | ||
const docAux = _this2._applyTimestamps(docs[i], model, 'insert'); | ||
@@ -569,3 +572,3 @@ // Preparing the doc | ||
// Check and apply document options before saving | ||
const docAux = _this2._applyDocumentOptions(docs[i], 'insert'); | ||
const docAux = _this2._applyTimestamps(docs[i], model, 'insert'); | ||
@@ -797,2 +800,4 @@ // Preparing the doc | ||
payload = _this4._applyTimestamps(payload, model, 'update'); | ||
// Ensure index are created | ||
@@ -799,0 +804,0 @@ if (_this4._indexes[collection] && _this4._indexes[collection].length > 0) { |
{ | ||
"name": "moltyjs", | ||
"version": "0.8.8", | ||
"version": "0.8.9", | ||
"description": "A tiny ODM for MongoDB with multy tenancy support.", | ||
@@ -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
123428
2306