diff --git a/lib/errors/ModelError.ts b/lib/errors/ModelError.ts index b2b7056..4143851 100755 --- a/lib/errors/ModelError.ts +++ b/lib/errors/ModelError.ts @@ -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 diff --git a/lib/index.ts b/lib/index.ts index e68dd74..46a5060 100755 --- a/lib/index.ts +++ b/lib/index.ts @@ -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 } diff --git a/lib/utils.ts b/lib/utils.ts new file mode 100644 index 0000000..0567d86 --- /dev/null +++ b/lib/utils.ts @@ -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 + } +} diff --git a/package-lock.json b/package-lock.json index 548ddca..daf5617 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": "1.1.6", + "version": "1.1.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 07a7bac..88c91c5 100755 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/unit/lib/utils.test.js b/test/unit/lib/utils.test.js new file mode 100644 index 0000000..40da875 --- /dev/null +++ b/test/unit/lib/utils.test.js @@ -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] + }) + }) + }) +})