Lint in strapi-bookshelf

This commit is contained in:
soupette 2018-05-04 17:29:44 +02:00
parent 6633b14ef3
commit e9f68a3bc9
6 changed files with 36 additions and 33 deletions

View File

@ -8,7 +8,7 @@
/* eslint-disable */
import './public-path';
import 'babel-polyfill';
/* eslint-disable no-console */
// Import all the third party stuff
import { Provider } from 'react-redux';
import React from 'react';

View File

@ -12,12 +12,12 @@ const _ = require('lodash');
const bookshelf = require('bookshelf');
const pluralize = require('pluralize');
// Local helpers.
const utils = require('./utils/');
// Strapi helpers for models.
const utilsModels = require('strapi-utils').models;
// Local helpers.
const utils = require('./utils/');
const PIVOT_PREFIX = '_pivot_';
const GLOBALS = {};
@ -25,6 +25,9 @@ const GLOBALS = {};
* Bookshelf hook
*/
/* eslint-disable no-unused-vars */
/* eslint-disable prefer-template */
/* eslint-disable no-case-declarations */
module.exports = function(strapi) {
const hook = {
/**
@ -86,18 +89,18 @@ module.exports = function(strapi) {
// Register the final model for Bookshelf.
const loadedModel = _.assign({
tableName: definition.collectionName,
hasTimestamps: _.get(definition, 'options.timestamps') === true,
idAttribute: _.get(definition, 'options.idAttribute', 'id'),
associations: [],
defaults: Object.keys(definition.attributes).reduce((acc, current) => {
if (definition.attributes[current].type && definition.attributes[current].default) {
acc[current] = definition.attributes[current].default;
}
tableName: definition.collectionName,
hasTimestamps: _.get(definition, 'options.timestamps') === true,
idAttribute: _.get(definition, 'options.idAttribute', 'id'),
associations: [],
defaults: Object.keys(definition.attributes).reduce((acc, current) => {
if (definition.attributes[current].type && definition.attributes[current].default) {
acc[current] = definition.attributes[current].default;
}
return acc;
}, {})
}, definition.options);
return acc;
}, {})
}, definition.options);
if (_.isString(_.get(connection, 'options.pivot_prefix'))) {
loadedModel.toJSON = function(options = {}) {
@ -201,7 +204,7 @@ module.exports = function(strapi) {
});
return attrs;
}
};
// Initialize lifecycle callbacks.
loadedModel.initialize = function() {
@ -497,7 +500,7 @@ module.exports = function(strapi) {
.query(qb => {
qb.where(_.get(model, `attributes.${details.via}.filter`, 'field'), name);
});
}
};
break;
}
case 'morphMany': {
@ -513,7 +516,7 @@ module.exports = function(strapi) {
.query(qb => {
qb.where(_.get(collection, `attributes.${details.via}.filter`, 'field'), name);
});
}
};
break;
}
case 'belongsToMorph':
@ -605,7 +608,7 @@ module.exports = function(strapi) {
cb();
},
getQueryParams: (value, type, key) => {
getQueryParams: (value, type, key) => {
const result = {};
switch (type) {
@ -821,7 +824,7 @@ module.exports = function(strapi) {
strapi.plugins[obj.source].models[obj.ref]:
strapi.models[obj.ref];
virtualFields.push(this.addRelationMorph(details.model || details.collection, {
virtualFields.push(this.addRelationMorph(details.model || details.collection, {
id: response[this.primaryKey],
alias: association.alias,
ref: model.collectionName,
@ -840,7 +843,7 @@ module.exports = function(strapi) {
}
return value;
})
});
}
if (association.type === 'model') {
@ -987,11 +990,11 @@ module.exports = function(strapi) {
}
return await Model.morph.forge({
[`${Model.collectionName}_id`]: params.id,
[`${params.alias}_id`]: params.refId,
[`${params.alias}_type`]: params.ref,
field: params.field
})
[`${Model.collectionName}_id`]: params.id,
[`${params.alias}_id`]: params.refId,
[`${params.alias}_type`]: params.ref,
field: params.field
})
.save();
},

View File

@ -24,8 +24,8 @@ module.exports = (scope, success, error) => {
success();
})
.catch(() => {
logger.warn('Database connection has failed! Make sure your database is running.');
error();
});
.catch(() => {
logger.warn('Database connection has failed! Make sure your database is running.');
error();
});
};

View File

@ -8,7 +8,7 @@
const _ = require('lodash');
// Strapi helper for GraphQL.
const helpers = require('strapi/lib/configuration/hooks/graphql/helpers/');
const helpers = require('strapi/lib/configuration/hooks/graphql/helpers/'); // eslint-disable-line import/no-unresolved
const utils = require('./');
/**

View File

@ -10,7 +10,7 @@ const _ = require('lodash');
/**
* Utils functions for BookShelf
*/
/* eslint-disable prefer-template */
module.exports = {
/**

View File

@ -27,7 +27,7 @@ const watcher = (label, pckgName, type = 'front') => {
const packagesPath = path.resolve(process.env.PWD, 'packages');
shell.ls('* -d', packagesPath)
// TODO temporary just for eslint
.filter(package => package === 'strapi')
.filter(package => package === 'strapi-bookshelf')
// .filter(package => package !== 'README.md')
.forEach(package => {
watcher(`Testing ${package}`, package);