-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from nzzdev/release-3.1.0
Release 3.1.0
- Loading branch information
Showing
12 changed files
with
300 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const Boom = require('boom'); | ||
const Hoek = require('hoek'); | ||
const fetch = require('node-fetch'); | ||
|
||
module.exports = { | ||
name: 'q-fixtures', | ||
dependencies: 'q-base', | ||
register: async function (server, options) { | ||
Hoek.assert(server.settings.app.tools && typeof server.settings.app.tools.get === 'function', new Error('server.settings.app.tools.get needs to be a function')); | ||
|
||
// get a list of already existing (stored in db) and new fixture data | ||
server.method('plugins.q.fixtures.get', async () => { | ||
const tools = server.settings.app.tools.get(''); | ||
const fixtures = { | ||
existing: [], | ||
new: [] | ||
}; | ||
for (const tool of Object.keys(tools)) { | ||
// fetch fixture data of configured tools | ||
const response = await server.inject({ | ||
url: `/tools/${tool}/fixtures/data` | ||
}); | ||
// all other status codes will be ignored, | ||
// e.g. 502 - tool is not running or | ||
// 404 - tool has no fixture data endpoint | ||
if (response.statusCode === 200) { | ||
const toolFixtureData = JSON.parse(response.payload); | ||
for (const [index, item] of toolFixtureData.entries()) { | ||
item._id = `${tool}-${index}`; | ||
item.tool = tool; | ||
item.active = true; | ||
// check if fixture data with id already exists | ||
const response = await server.inject({ | ||
url: `/item/${item._id}` | ||
}); | ||
if (response.statusCode === 200) { | ||
const origItem = JSON.parse(response.payload); | ||
item._rev = origItem._rev; | ||
fixtures.existing.push(item); | ||
} else if (response.statusCode === 404) { | ||
item.activateDate = new Date().toISOString(); | ||
fixtures.new.push(item); | ||
} | ||
} | ||
} | ||
} | ||
return fixtures; | ||
}) | ||
|
||
server.route([ | ||
require('./routes.js').storeFixtures, | ||
require('./routes.js').getExistingFixtureIds | ||
]) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const Boom = require('boom'); | ||
|
||
module.exports = { | ||
storeFixtures: { | ||
path: '/fixtures/data', | ||
method: 'POST', | ||
options: { | ||
auth: 'q-auth', | ||
cors: { | ||
credentials: true | ||
}, | ||
description: 'creates fixture data items for all tools and stores them in db', | ||
tags: ['api', 'fixtures', 'non-critical'] | ||
}, | ||
handler: async (request, h) => { | ||
try { | ||
const fixtures = await request.server.methods.plugins.q.fixtures.get(); | ||
let result = { | ||
saved: [], | ||
errors: [] | ||
} | ||
|
||
// update all existing fixture data items in db | ||
for (const item of fixtures.existing) { | ||
const updateResponse = await request.server.inject({ | ||
url: `/item`, | ||
method: 'PUT', | ||
payload: item, | ||
credentials: request.auth.credentials | ||
}); | ||
if (updateResponse.statusCode === 200) { | ||
result.saved.push(item._id); | ||
} else { | ||
result.errors.push(`Error ${updateResponse.statusCode} - ${updateResponse.result.message} for ${item._id}`); | ||
} | ||
} | ||
|
||
// create all new fixture data items in db | ||
for (const item of fixtures.new) { | ||
const createResponse = await request.server.inject({ | ||
url: `/item`, | ||
method: 'POST', | ||
payload: item, | ||
credentials: request.auth.credentials | ||
}); | ||
if (createResponse.statusCode === 200) { | ||
result.saved.push(item._id); | ||
} else { | ||
result.errors.push(`Error ${createResponse.statusCode} - ${createResponse.result.message} for ${item._id}`); | ||
} | ||
} | ||
return result; | ||
} catch (e) { | ||
return Boom.internal(e.message); | ||
} | ||
|
||
} | ||
}, | ||
getExistingFixtureIds: { | ||
path: '/fixtures/data', | ||
method: 'GET', | ||
options: { | ||
description: 'returns all available fixture data ids', | ||
tags: ['api', 'fixtures', 'non-critical'] | ||
}, | ||
handler: async (request, h) => { | ||
try { | ||
const fixtures = await request.server.methods.plugins.q.fixtures.get(); | ||
if (fixtures) { | ||
return fixtures.existing.map(item => { | ||
return { | ||
_id: item._id | ||
} | ||
}); | ||
} | ||
} catch (e) { | ||
return Boom.internal(e.message); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.