Comparing version 0.5.0 to 0.5.1
@@ -35,2 +35,8 @@ ## [Unreleased] | ||
## [0.5.1] - 2017-12-28 | ||
### Fixed | ||
* Validation Schema function fields for nested objects. | ||
## [0.5.0] - 2017-12-27 | ||
@@ -259,2 +265,3 @@ | ||
[0.5.1]: https://github.com/Yonirt/moltyjs/compare/v0.5.0...v0.5.1 | ||
[0.5.0]: https://github.com/Yonirt/moltyjs/compare/v0.4.3...v0.5.0 | ||
@@ -261,0 +268,0 @@ [0.4.3]: https://github.com/Yonirt/moltyjs/compare/v0.4.2...v0.4.3 |
@@ -115,15 +115,17 @@ 'use strict'; | ||
_this._validatePayloadFieldNames(payload, _this._schemaNormalized); | ||
let data = null; | ||
// Normalize the payload with the model schema | ||
_this._normalizedPayload = _this._normalizePayload(payload, _this._schemaNormalized); | ||
data = _this._normalizePayload(payload, _this._schemaNormalized); | ||
try { | ||
// Validate all the values | ||
yield _this._validatePayloadFieldValues(_this._normalizedPayload, _this._schemaNormalized, tenant); | ||
yield _this._validatePayloadFieldValues(data, _this._schemaNormalized, tenant, data); | ||
// Returning the new document created | ||
return new Document(_this._normalizedPayload, _this._preHooks, _this._postHooks, _this._methods, _this._schemaOptions, _this._modelName, _this._discriminator, tenant); | ||
const newDoc = new Document(data, _this._preHooks, _this._postHooks, _this._methods, _this._schemaOptions, _this._modelName, _this._discriminator, tenant); | ||
return newDoc; | ||
} catch (err) { | ||
throw err; | ||
} finally { | ||
_this._normalizedPayload = null; | ||
} | ||
@@ -222,3 +224,3 @@ })(); | ||
*/ | ||
_validatePayloadFieldValues(payload, schema, tenant = null) { | ||
_validatePayloadFieldValues(payload, schema, tenant, parentPayload) { | ||
var _this2 = this; | ||
@@ -240,3 +242,3 @@ | ||
if (!schema[key].type && isObject(payload[key])) { | ||
payload[key] = _this2._validatePayloadFieldValues(payload[key], schema[key]); | ||
_this2._validatePayloadFieldValues(payload[key], schema[key], tenant, parentPayload); | ||
continue; | ||
@@ -279,3 +281,3 @@ } | ||
if (schema[key].validate.constructor.name === 'AsyncFunction') { | ||
var _ref = yield to(schema[key].validate(mongoClient, tenant, _this2._normalizedPayload)); | ||
var _ref = yield to(schema[key].validate(mongoClient, tenant, parentPayload)); | ||
@@ -287,3 +289,3 @@ var _ref2 = _slicedToArray(_ref, 2); | ||
} else { | ||
isValid = schema[key].validate(mongoClient, tenant, _this2._normalizedPayload); | ||
isValid = schema[key].validate(mongoClient, tenant, parentPayload); | ||
} | ||
@@ -290,0 +292,0 @@ |
{ | ||
"name": "moltyjs", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "A tiny ODM for MongoDB with multy tenancy support.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
[![npm version](https://badge.fury.io/js/moltyjs.svg)](https://badge.fury.io/js/moltyjs) | ||
[![dependencies Status](https://david-dm.org/Yonirt/moltyjs/status.svg)](https://david-dm.org/Yonirt/moltyjs) | ||
[![devDependencies Status](https://david-dm.org/Yonirt/moltyjs/dev-status.svg)](https://david-dm.org/Yonirt/moltyjs?type=dev) | ||
@@ -7,3 +9,3 @@ # What is moltyjs? | ||
**NOTE: THIS LIBRARY IS NOT SUITABLE FOR A PRODUCTION ENVIRONMENT, IS STILL UNDER CONSTRUCCTIONS AND MIGTH BE BREAKING CHANGES FROM ONE COMMIT TO ANOTHER. PLEASE, USE IT CAREFULLY AND CHECK THE DOCUMENTATION IN EACH VERSION RELEASE AND THE CHANGELOG. THANK YOU!** | ||
**NOTE: THIS LIBRARY IS NOT SUITABLE FOR A PRODUCTION ENVIRONMENT, IS STILL UNDER CONSTRUCCTIONS AND MIGTH BE BREAKING CHANGES FROM ONE COMMIT TO ANOTHER. PLEASE, USE IT CAREFULLY AND CHECK THE DOCUMENTATION AND THE CHANGELOG IN EACH VERSION RELEASE. THANK YOU!** | ||
@@ -10,0 +12,0 @@ ## Install |
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
83255
455