Skip to content

Commit

Permalink
Merge pull request #10 from fabrix-app/v1.1
Browse files Browse the repository at this point in the history
[feat] merge
  • Loading branch information
scott-wyatt authored Aug 3, 2018
2 parents 6371cdd + 8b6358c commit b14ddba
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/errors/ModelError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class ModelError extends Error {
this.statusCode = '404'
break
}
case 'E_FORBIDDEN': {
this.statusCode = '403'
break
}
case 'E_BAD_REQUEST': {
this.statusCode = '400'
break
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export { SequelizeResolver } from './SequelizeResolver'
export { Transformer } from './transformer'
export { Validator } from './validator'
export { Schemas } from './schemas'
export { Utils } from './utils'
export { Errors }
15 changes: 15 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { mergeWith } from 'lodash'
export const Utils = {
mergeConfigUtil: (objValue, srcValue) => {
if (Array.isArray(objValue)) {
return [...objValue, ...srcValue]
}
},
mergeConfig: (...values) => {
const config = {}
values.forEach(val => {
return mergeWith(config, val, Utils.mergeConfigUtil)
})
return config
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/spool-sequelize",
"version": "1.1.6",
"version": "1.1.7",
"description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com",
"scripts": {
"build": "tsc -p ./lib/tsconfig.release.json",
Expand Down
25 changes: 25 additions & 0 deletions test/unit/lib/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const assert = require('assert')
const app = require('../../fixtures/app')
const lib = require('../../../dist/index')

describe('lib.Utils', () => {
describe('#mergeConfig', () => {
it('should merge objects', () => {
const items = lib.Utils.mergeConfig({test1: 1}, {test2: 2}, {test3: 3})
assert.deepEqual(items, {
test1: 1,
test2: 2,
test3: 3
})
})
it('should merge objects with arrays', () => {
const items = lib.Utils.mergeConfig({test1: 1, arr: [1] }, {test2: 2, arr: [2]}, {test3: 3, arr: [3]})
assert.deepEqual(items, {
test1: 1,
test2: 2,
test3: 3,
arr: [1, 2, 3]
})
})
})
})

0 comments on commit b14ddba

Please sign in to comment.