@janiscommerce/api-save
Advanced tools
Comparing version 4.2.1 to 4.3.0
@@ -8,2 +8,6 @@ # Changelog | ||
## [4.3.0] - 2019-12-10 | ||
### Added | ||
- New method `postStructValidate` to add extra validation post struc validation | ||
## [4.2.1] - 2019-11-13 | ||
@@ -10,0 +14,0 @@ ### Changed |
@@ -39,2 +39,10 @@ 'use strict'; | ||
this.model = apiSaveValidator.validateModel(); | ||
if(this.postStructValidate) { | ||
try { | ||
await this.postStructValidate(); | ||
} catch(e) { | ||
throw new ApiSaveError(e, ApiSaveError.codes.INVALID_REQUEST_DATA); | ||
} | ||
} | ||
} | ||
@@ -41,0 +49,0 @@ |
@@ -10,2 +10,3 @@ 'use strict'; | ||
INVALID_ENTITY: 2, | ||
VALIDATION_ERROR: 3, | ||
INTERNAL_ERROR: 99 | ||
@@ -12,0 +13,0 @@ }; |
@@ -40,3 +40,3 @@ 'use strict'; | ||
e.message = `${e.message} in ${errorPath}`; | ||
throw new ApiSaveError(e, ApiSaveError.codes.INVALID_REQUEST_DATA); | ||
throw new ApiSaveError(e, ApiSaveError.codes.VALIDATION_ERROR); | ||
} | ||
@@ -43,0 +43,0 @@ } |
{ | ||
"name": "@janiscommerce/api-save", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "A package to handle JANIS Views Save APIs", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -54,2 +54,6 @@ # API Save | ||
postStructValidate() { | ||
return someAsyncTask(this.dataToSave.main); | ||
} | ||
format({ someField, ...restoOfTheRecord }) { | ||
@@ -99,2 +103,6 @@ return { | ||
### postStructValidate() | ||
This is used to validate the data received in the request, making additional validation even injecting data to the received data. | ||
If it returns a Promise, it will be awaited. | ||
### format(record) | ||
@@ -101,0 +109,0 @@ You can use this to format your main record before it's saved. For example, mapping user friendly values to DB friendly values, add default values, etc. |
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
19039
327
113