Skip to content

Commit

Permalink
Merge branch 'master' into greenkeeper-input-plugin-password-0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Snugug committed Oct 23, 2016
2 parents 4e15f27 + 1df80b2 commit 3fd7e96
Show file tree
Hide file tree
Showing 7 changed files with 396 additions and 166 deletions.
7 changes: 4 additions & 3 deletions lib/api/apis.js
Expand Up @@ -171,18 +171,19 @@ const ofType = (query, type) => {
*
* @param {object} query - Request queries
* @param {string} id - The GUID to search
* @param {array} base - Array of content type attributes
* @param {array} model - Array of content type attributes
*
* @returns {object} - All items and the pagination for the items
*/
// TODO: Return error if no items are found
const one = (query, id, base) => {
const one = (query, id, model) => {
// const organize = utils.organize(query);

return database('live').select('*').where({
id,
}).then(rows => {
const formatted = utils.format(rows, base)[0];
const formatted = utils.format(rows, model)[0];

if (formatted) {
const type = {
name: formatted.type,
Expand Down
15 changes: 8 additions & 7 deletions lib/api/utils.js
Expand Up @@ -13,12 +13,12 @@ const liveSchema = utils.singleItem('name', 'live', schemas).fields.map(field =>
* Formats raw attributes in to API output
*
* @param {array} attrs - Array of objects representing the raw attribute content
* @param {array} base - Array of objects representing the content type's attribute model
* @param {array} model - Array of objects representing the content type's attribute model
*/
const attributes = (attrs, base) => {
const attributes = (attrs, model) => {
const result = {};

base.forEach(input => {
model.forEach(input => {
if (!input.hasOwnProperty('repeatable')) {
const inputs = Object.keys(input.inputs);
const total = Object.keys(inputs).length;
Expand Down Expand Up @@ -72,11 +72,11 @@ const attributes = (attrs, base) => {
* Formats raw live data in to consumable returns
*
* @param {array} content - Array of objects representing the raw DB query of content
* @param {object} attrs - If included, will include attributes instead of meta, built off of the attribute definition passed in
* @param {object} model - If included, will include attributes instead of meta, built off of the attribute definition passed in
*
* @returns {array} - formatted object of content
*/
const format = (content, attrs) => {
const format = (content, model) => {
return content.map(item => {
const result = {
id: item.id,
Expand All @@ -86,8 +86,8 @@ const format = (content, attrs) => {
key_slug: item['key-slug'], // eslint-disable-line camelcase
};

if (attrs) {
result.attributes = attributes(item.attributes, attrs);
if (model) {
result.attributes = attributes(item.attributes, model);
}
else {
result.meta = {
Expand Down Expand Up @@ -235,6 +235,7 @@ const page = (base, organized, count) => {
};

module.exports = {
attributes,
format,
organize,
page,
Expand Down
14 changes: 5 additions & 9 deletions package.json
Expand Up @@ -20,8 +20,8 @@
"posttest": "gulp build",
"start": "nodemon -e html,js ./index.js",
"lint": "gulp lint",
"ava:watch": "NODE_ENV=test NODE_CONFIG_DIR=../config ava --watch | tap-difflet",
"ava": "NODE_ENV=test NODE_CONFIG_DIR=../config ava | tap-difflet",
"ava:watch": "NODE_ENV=test NODE_CONFIG_DIR=../config ava --watch",
"ava": "NODE_ENV=test NODE_CONFIG_DIR=../config ava",
"nyc": "nyc --all npm run ava",
"dev:database": "postgres -D /usr/local/var/postgres",
"dev:start": "gulp",
Expand Down Expand Up @@ -112,9 +112,6 @@
},
"nyc": {
"exclude": [
"lib/api.js",
"lib/routes/api.js",
"lib/api/**/*",
"tests/**/*",
"config/**/*",
"public/**/*",
Expand All @@ -125,11 +122,10 @@
},
"ava": {
"files": [
"tests/*.js",
"!tests/apis.js"
"tests/*.js"
],
"failFast": true,
"tap": true
"failFast": false,
"tap": false
},
"config": {
"ghooks": {
Expand Down

0 comments on commit 3fd7e96

Please sign in to comment.