@janiscommerce/api-save
Advanced tools
Comparing version 1.1.2 to 2.0.0
@@ -10,2 +10,7 @@ # Changelog | ||
## [2.0.0] - 2019-07-18 | ||
### Changed | ||
- Browse APIs paths changed. Now MS_PATH env var is taken into account. | ||
- Now relationships configurations receive a `modelClass` instead of a `model` | ||
## [1.1.2] - 2019-07-02 | ||
@@ -12,0 +17,0 @@ ### Fixed |
@@ -22,3 +22,3 @@ 'use strict'; | ||
this.controller = apiSaveValidator.validateController(); | ||
this.model = apiSaveValidator.validateModel(); | ||
} | ||
@@ -25,0 +25,0 @@ |
@@ -16,7 +16,7 @@ 'use strict'; | ||
if(this.apiInstance.dataToSave.id) { | ||
const updateResult = await this.apiInstance.controller.update(dataToSave, { id: this.apiInstance.dataToSave.id }); | ||
const updateResult = await this.apiInstance.model.update(dataToSave, { id: this.apiInstance.dataToSave.id }); | ||
return !updateResult ? updateResult : this.apiInstance.dataToSave.id; | ||
} | ||
return this.apiInstance.controller.insert(dataToSave); | ||
return this.apiInstance.model.insert(dataToSave); | ||
} | ||
@@ -23,0 +23,0 @@ |
@@ -35,7 +35,8 @@ 'use strict'; | ||
const { controller } = relationshipParameters; | ||
const { modelClass: ModelClass } = relationshipParameters; | ||
const relationshipsToSave = this._formatRelationshipsToInsert(relationship, relationshipParameters); | ||
return controller.multiInsert(relationshipsToSave); | ||
const model = new ModelClass(); | ||
return model.multiInsert(relationshipsToSave); | ||
} | ||
@@ -45,5 +46,6 @@ | ||
const { controller, mainIdentifierField } = relationshipParameters; | ||
const { modelClass: ModelClass, mainIdentifierField } = relationshipParameters; | ||
const currentRelationships = controller.get({ | ||
const model = new ModelClass(); | ||
const currentRelationships = model.get({ | ||
[mainIdentifierField]: this.mainId | ||
@@ -56,4 +58,4 @@ }); | ||
const removePromise = removeData.length ? controller.multiRemove(removeData) : Promise.resolve(); | ||
const insertPromise = insertData.length ? controller.multiInsert(insertData) : Promise.resolve(); | ||
const removePromise = removeData.length ? model.multiRemove(removeData) : Promise.resolve(); | ||
const insertPromise = insertData.length ? model.multiInsert(insertData) : Promise.resolve(); | ||
@@ -60,0 +62,0 @@ return Promise.all([removePromise, insertPromise]); |
'use strict'; | ||
const { Controller } = require('@janiscommerce/model-controller'); | ||
const { struct } = require('superstruct'); | ||
const path = require('path'); | ||
@@ -33,10 +33,10 @@ const ApiSaveError = require('./api-save-error'); | ||
} catch(e) { | ||
const path = e.path.join('.'); | ||
throw new ApiSaveError(`${e.message} in ${path}`, ApiSaveError.codes.INVALID_REQUEST_DATA); | ||
const errorParh = e.path.join('.'); | ||
throw new ApiSaveError(`${e.message} in ${errorParh}`, ApiSaveError.codes.INVALID_REQUEST_DATA); | ||
} | ||
} | ||
validateController() { | ||
validateModel() { | ||
try { | ||
return Controller.getInstance(this.apiInstance.entity); | ||
return this._getModelInstance(); | ||
} catch(e) { | ||
@@ -47,4 +47,11 @@ throw new ApiSaveError(e.message, ApiSaveError.codes.INVALID_ENTITY); | ||
/* istanbul ignore next */ | ||
_getModelInstance() { | ||
// eslint-disable-next-line global-require, import/no-dynamic-require | ||
const Model = require(path.join(process.cwd(), process.env.MS_PATH, 'models', this.apiInstance.entity)); | ||
return new Model(); | ||
} | ||
} | ||
module.exports = ApiSaveValidator; |
{ | ||
"name": "@janiscommerce/api-save", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"description": "A package to handle JANIS Views Save APIs", | ||
@@ -21,6 +21,6 @@ "main": "index.js", | ||
"devDependencies": { | ||
"husky": "^2.4.1", | ||
"eslint": "^5.16.0", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-config-airbnb-base": "^13.2.0", | ||
"eslint-plugin-import": "^2.17.3", | ||
"husky": "^2.7.0", | ||
"mocha": "^5.2.0", | ||
@@ -37,7 +37,7 @@ "nyc": "^13.1.0", | ||
"dependencies": { | ||
"@janiscommerce/api-view": "^1.2.0", | ||
"@janiscommerce/model-controller": "^1.4.0", | ||
"lodash": "^4.17.11", | ||
"@janiscommerce/api-view": "^1.3.0", | ||
"@janiscommerce/model": "^1.1.1", | ||
"lodash": "^4.17.14", | ||
"superstruct": "^0.6.1" | ||
} | ||
} |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
13036
261
2
+ Added@janiscommerce/model@^1.1.1
+ Added@janiscommerce/model@1.2.0(transitive)
- Removed@janiscommerce/model-controller@1.6.1(transitive)
- Removed@janiscommerce/modules-path@1.1.0(transitive)
Updatedlodash@^4.17.14