Skip to content

Commit

Permalink
Merge 6ede050 into 1845f24
Browse files Browse the repository at this point in the history
  • Loading branch information
gastonpereyra committed Sep 11, 2019
2 parents 1845f24 + 6ede050 commit a610ebf
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 59 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Changed
- `_formatFields` method name to `_getFormatFields`

### Fixed
- Non-undefined falsies values can be iserted/saved


## [1.3.4] - 2019-09-06
### Changed
Expand Down
12 changes: 8 additions & 4 deletions lib/query-builder.js
Expand Up @@ -108,7 +108,7 @@ class QueryBuilder {
* @param {Array<objects>} items Array of Objects
*/

async _formatFields(items) {
async _getFormatFields(items) {

const tableFields = Object.keys(await this._getFields());

Expand All @@ -119,7 +119,11 @@ class QueryBuilder {
const validFields = {};

tableFields.forEach(field => {
validFields[field] = item[convertToCamelCase(field)] || (this.constructor.dateFields.includes(field) ? time : null);

if(item[convertToCamelCase(field)] !== undefined)
validFields[field] = item[convertToCamelCase(field)];
else
validFields[field] = this.constructor.dateFields.includes(field) ? time : null;
});

return validFields;
Expand Down Expand Up @@ -198,7 +202,7 @@ class QueryBuilder {
throw new QueryBuilderError('Not valid items to Insert', QueryBuilderError.codes.NO_ITEMS);
}
// Format Items to have valid fields
items = await this._formatFields(items);
items = await this._getFormatFields(items);

try {
return this.knexStatement.insert(items);
Expand Down Expand Up @@ -227,7 +231,7 @@ class QueryBuilder {
throw new QueryBuilderError('Not valid items to Save', QueryBuilderError.codes.NO_ITEMS);
}
// Format Items to have valid fields
items = await this._formatFields(items);
items = await this._getFormatFields(items);

try {

Expand Down

0 comments on commit a610ebf

Please sign in to comment.