@tipe/databox-loader
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "@tipe/databox-loader", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Tipe Databox Loader for talking with Databox", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -30,2 +30,14 @@ const fetch = require('node-fetch') | ||
function databoxFetch(url, model, action, body) { | ||
return fetch(`${url}/api/${model}/${action}`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
query: body | ||
}) | ||
}) | ||
.then(resp => resp.json()) | ||
} | ||
module.exports = function createDatabox(url, _models, _actions) { | ||
@@ -36,15 +48,8 @@ _models = _models || models | ||
_models.forEach(model => { | ||
orm[model] = orm[model] || {} | ||
if (orm[model] === undefined) { | ||
orm[model] = {} | ||
} | ||
_actions.forEach(action => { | ||
orm[model][action] = function databoxFetch(body) { | ||
return fetch(`${url}/api/${model}/${action}`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
query: body | ||
}) | ||
}) | ||
.then(resp => resp.json()) | ||
if (orm[model][action] === undefined) { | ||
orm[model][action] = databoxFetch.bind(url, model, action) | ||
} | ||
@@ -64,4 +69,7 @@ }) | ||
{ | ||
data: {}, | ||
errors: [] | ||
} | ||
*/ |
@@ -13,10 +13,8 @@ const createDatabox = require('./create'); | ||
[ | ||
'action' | ||
'action', | ||
'action2' | ||
]) | ||
}); | ||
// afterEach(() => { | ||
// }); | ||
test('creates obj', () => { | ||
console.log('databox', databox) | ||
expect(databox.hasOwnProperty('testing')).toBe(true); | ||
@@ -27,2 +25,12 @@ expect(databox.hasOwnProperty('testing1')).toBe(true); | ||
}); | ||
test('creates obj with actions', () => { | ||
expect(databox.testing.hasOwnProperty('action')).toBe(true); | ||
expect(databox.testing.hasOwnProperty('action2')).toBe(true); | ||
expect(databox.testing1.hasOwnProperty('action')).toBe(true); | ||
expect(databox.testing1.hasOwnProperty('action2')).toBe(true); | ||
expect(databox.testing2.hasOwnProperty('action')).toBe(true); | ||
expect(databox.testing2.hasOwnProperty('action2')).toBe(true); | ||
expect(databox.testing3.hasOwnProperty('action')).toBe(true); | ||
expect(databox.testing3.hasOwnProperty('action2')).toBe(true); | ||
}); | ||
}) |
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
100305
99