@janiscommerce/api-save
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -10,2 +10,6 @@ # Changelog | ||
## [1.1.0] - 2019-06-28 | ||
### Added | ||
- ApiSaveData now accepts a `format()` hook to manipulate main data before saving | ||
## [1.0.1] - 2019-06-27 | ||
@@ -12,0 +16,0 @@ ### Changed |
@@ -29,2 +29,5 @@ 'use strict'; | ||
if(this.format) | ||
this.dataToSave.main = this.format(this.dataToSave.main); | ||
const apiSaveMain = new ApiSaveMain(this); | ||
@@ -31,0 +34,0 @@ const savedId = await apiSaveMain.process(); |
{ | ||
"name": "@janiscommerce/api-save", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A package to handle JANIS Views Save APIs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,9 +17,43 @@ # API Save | ||
const { ApiSave } = require('@janiscommerce/api-save'); | ||
const { ApiSaveData } = require('@janiscommerce/api-save'); | ||
const { Controller } = require('@janiscommerce/model-controller'); | ||
const { struct } = require('superstruct'); | ||
class MyApiSave extends ApiSave { | ||
class MyApiSaveData extends ApiSaveData { | ||
static get relationshipsParameters() { | ||
return { | ||
children: { | ||
controller: Controller.getInstance('some-relationship-entity'), | ||
mainIdentifierField: 'dbFieldForMainEntity', | ||
secondaryIdentifierField: 'dbFieldForRelatedEntity', | ||
shouldClean: false | ||
} | ||
}; | ||
} | ||
getStruct() { | ||
return struct({ | ||
id: 'number', | ||
data: struct.partial({ | ||
name: 'string', | ||
description: 'string?', | ||
status: 'number' | ||
}), | ||
relationships: struct.partial({ | ||
children: ['number'] | ||
}) | ||
}); | ||
} | ||
format({ someField, ...restoOfTheRecord }) { | ||
return { | ||
...restoOfTheRecord, | ||
someField: `prefix-${someField}` | ||
}; | ||
} | ||
} | ||
module.exports = MyApiSave; | ||
module.exports = MyApiSaveData; | ||
``` |
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
12315
251
59