style: updated eslint config
This commit is contained in:
43
src/index.js
43
src/index.js
@ -9,8 +9,8 @@ import qs from 'qs';
|
||||
const register = (server, options = {}, next) => {
|
||||
options.prefix = options.prefix || '';
|
||||
|
||||
let db = server.plugins['hapi-sequelize'].db;
|
||||
let models = db.sequelize.models;
|
||||
const db = server.plugins['hapi-sequelize'].db;
|
||||
const models = db.sequelize.models;
|
||||
|
||||
const onRequest = function (request, reply) {
|
||||
const uri = request.raw.req.url;
|
||||
@ -26,9 +26,9 @@ const register = (server, options = {}, next) => {
|
||||
method: onRequest,
|
||||
});
|
||||
|
||||
for (let modelName of Object.keys(models)) {
|
||||
let model = models[modelName];
|
||||
let { plural, singular } = model.options.name;
|
||||
for (const modelName of Object.keys(models)) {
|
||||
const model = models[modelName];
|
||||
const { plural, singular } = model.options.name;
|
||||
model._plural = plural.toLowerCase();
|
||||
model._singular = singular.toLowerCase();
|
||||
|
||||
@ -37,29 +37,30 @@ const register = (server, options = {}, next) => {
|
||||
|
||||
crud(server, model, options);
|
||||
|
||||
for (let key of Object.keys(model.associations)) {
|
||||
let association = model.associations[key];
|
||||
let { source, target } = association;
|
||||
for (const key of Object.keys(model.associations)) {
|
||||
const association = model.associations[key];
|
||||
const { source, target } = association;
|
||||
|
||||
let sourceName = source.options.name;
|
||||
const sourceName = source.options.name;
|
||||
|
||||
const names = (rev) => {
|
||||
const arr = [{
|
||||
plural: sourceName.plural.toLowerCase(),
|
||||
singular: sourceName.singular.toLowerCase(),
|
||||
original: sourceName,
|
||||
}, {
|
||||
plural: association.options.name.plural.toLowerCase(),
|
||||
singular: association.options.name.singular.toLowerCase(),
|
||||
original: association.options.name,
|
||||
}];
|
||||
plural: sourceName.plural.toLowerCase(),
|
||||
singular: sourceName.singular.toLowerCase(),
|
||||
original: sourceName,
|
||||
}, {
|
||||
plural: association.options.name.plural.toLowerCase(),
|
||||
singular: association.options.name.singular.toLowerCase(),
|
||||
original: association.options.name,
|
||||
}];
|
||||
|
||||
return rev ? { b: arr[0], a: arr[1] } : { a: arr[0], b: arr[1] };
|
||||
};
|
||||
|
||||
let targetAssociations = target.associations[sourceName.plural] || target.associations[sourceName.singular];
|
||||
let sourceType = association.associationType,
|
||||
targetType = (targetAssociations || {}).associationType;
|
||||
const targetAssociations = target.associations[sourceName.plural]
|
||||
|| target.associations[sourceName.singular];
|
||||
const sourceType = association.associationType,
|
||||
targetType = (targetAssociations || {}).associationType;
|
||||
|
||||
try {
|
||||
if (sourceType === 'BelongsTo' && (targetType === 'BelongsTo' || !targetType)) {
|
||||
@ -83,7 +84,7 @@ const register = (server, options = {}, next) => {
|
||||
|
||||
associations.associate(server, source, target, names(), options);
|
||||
associations.associate(server, target, source, names(1), options);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
// There might be conflicts in case of models associated with themselves and some other
|
||||
// rare cases.
|
||||
}
|
||||
|
Reference in New Issue
Block a user