style: updated eslint config
This commit is contained in:
parent
aa06808ab2
commit
6786b9b487
@ -23,7 +23,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel": "5.8.3",
|
"babel": "5.8.3",
|
||||||
"eslint": "2.10.2",
|
"eslint": "2.10.2",
|
||||||
"eslint-config-pichak": "1.0.1",
|
"eslint-config-pichak": "1.1.0",
|
||||||
"ghooks": "1.0.3",
|
"ghooks": "1.0.3",
|
||||||
"grunt": "0.4.5",
|
"grunt": "0.4.5",
|
||||||
"grunt-babel": "5.0.3",
|
"grunt-babel": "5.0.3",
|
||||||
|
@ -14,13 +14,13 @@ export default (server, a, b, names, options) => {
|
|||||||
|
|
||||||
@error
|
@error
|
||||||
async handler(request, reply) {
|
async handler(request, reply) {
|
||||||
let instanceb = await b.findOne({
|
const instanceb = await b.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: request.params.bid,
|
id: request.params.bid,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let instancea = await a.findOne({
|
const instancea = await a.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: request.params.aid,
|
id: request.params.aid,
|
||||||
},
|
},
|
||||||
|
@ -73,7 +73,7 @@ export const list = (server, a, b, names) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const scope = (server, a, b, names) => {
|
export const scope = (server, a, b, names) => {
|
||||||
let scopes = Object.keys(b.options.scopes);
|
const scopes = Object.keys(b.options.scopes);
|
||||||
|
|
||||||
server.route({
|
server.route({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -112,7 +112,7 @@ export const scope = (server, a, b, names) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const scopeScope = (server, a, b, names) => {
|
export const scopeScope = (server, a, b, names) => {
|
||||||
let scopes = {
|
const scopes = {
|
||||||
a: Object.keys(a.options.scopes),
|
a: Object.keys(a.options.scopes),
|
||||||
b: Object.keys(b.options.scopes),
|
b: Object.keys(b.options.scopes),
|
||||||
};
|
};
|
||||||
@ -126,7 +126,7 @@ export const scopeScope = (server, a, b, names) => {
|
|||||||
const include = parseInclude(request);
|
const include = parseInclude(request);
|
||||||
const where = parseWhere(request);
|
const where = parseWhere(request);
|
||||||
|
|
||||||
let list = await b.scope(request.params.scopeb).findAll({
|
const list = await b.scope(request.params.scopeb).findAll({
|
||||||
where,
|
where,
|
||||||
include: include.concat({
|
include: include.concat({
|
||||||
model: a.scope(request.params.scopea),
|
model: a.scope(request.params.scopea),
|
||||||
@ -175,7 +175,7 @@ export const destroy = (server, a, b, names) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const destroyScope = (server, a, b, names) => {
|
export const destroyScope = (server, a, b, names) => {
|
||||||
let scopes = Object.keys(b.options.scopes);
|
const scopes = Object.keys(b.options.scopes);
|
||||||
|
|
||||||
server.route({
|
server.route({
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
|
@ -73,7 +73,7 @@ export const get = (server, model) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const scope = (server, model) => {
|
export const scope = (server, model) => {
|
||||||
let scopes = Object.keys(model.options.scopes);
|
const scopes = Object.keys(model.options.scopes);
|
||||||
|
|
||||||
server.route({
|
server.route({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -156,7 +156,7 @@ export const destroyAll = (server, model) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const destroyScope = (server, model) => {
|
export const destroyScope = (server, model) => {
|
||||||
let scopes = Object.keys(model.options.scopes);
|
const scopes = Object.keys(model.options.scopes);
|
||||||
|
|
||||||
server.route({
|
server.route({
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
@ -167,7 +167,7 @@ export const destroyScope = (server, model) => {
|
|||||||
const include = parseInclude(request);
|
const include = parseInclude(request);
|
||||||
const where = parseWhere(request);
|
const where = parseWhere(request);
|
||||||
|
|
||||||
let list = await model.scope(request.params.scope).findAll({ include, where });
|
const list = await model.scope(request.params.scope).findAll({ include, where });
|
||||||
|
|
||||||
await Promise.all(list.map(instance => instance.destroy()));
|
await Promise.all(list.map(instance => instance.destroy()));
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export default (target, key, descriptor) => {
|
export default (target, key, descriptor) => {
|
||||||
let fn = descriptor.value;
|
const fn = descriptor.value;
|
||||||
|
|
||||||
descriptor.value = async (request, reply) => {
|
descriptor.value = async (request, reply) => {
|
||||||
try {
|
try {
|
||||||
|
23
src/index.js
23
src/index.js
@ -9,8 +9,8 @@ import qs from 'qs';
|
|||||||
const register = (server, options = {}, next) => {
|
const register = (server, options = {}, next) => {
|
||||||
options.prefix = options.prefix || '';
|
options.prefix = options.prefix || '';
|
||||||
|
|
||||||
let db = server.plugins['hapi-sequelize'].db;
|
const db = server.plugins['hapi-sequelize'].db;
|
||||||
let models = db.sequelize.models;
|
const models = db.sequelize.models;
|
||||||
|
|
||||||
const onRequest = function (request, reply) {
|
const onRequest = function (request, reply) {
|
||||||
const uri = request.raw.req.url;
|
const uri = request.raw.req.url;
|
||||||
@ -26,9 +26,9 @@ const register = (server, options = {}, next) => {
|
|||||||
method: onRequest,
|
method: onRequest,
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let modelName of Object.keys(models)) {
|
for (const modelName of Object.keys(models)) {
|
||||||
let model = models[modelName];
|
const model = models[modelName];
|
||||||
let { plural, singular } = model.options.name;
|
const { plural, singular } = model.options.name;
|
||||||
model._plural = plural.toLowerCase();
|
model._plural = plural.toLowerCase();
|
||||||
model._singular = singular.toLowerCase();
|
model._singular = singular.toLowerCase();
|
||||||
|
|
||||||
@ -37,11 +37,11 @@ const register = (server, options = {}, next) => {
|
|||||||
|
|
||||||
crud(server, model, options);
|
crud(server, model, options);
|
||||||
|
|
||||||
for (let key of Object.keys(model.associations)) {
|
for (const key of Object.keys(model.associations)) {
|
||||||
let association = model.associations[key];
|
const association = model.associations[key];
|
||||||
let { source, target } = association;
|
const { source, target } = association;
|
||||||
|
|
||||||
let sourceName = source.options.name;
|
const sourceName = source.options.name;
|
||||||
|
|
||||||
const names = (rev) => {
|
const names = (rev) => {
|
||||||
const arr = [{
|
const arr = [{
|
||||||
@ -57,8 +57,9 @@ const register = (server, options = {}, next) => {
|
|||||||
return rev ? { b: arr[0], a: arr[1] } : { a: arr[0], b: arr[1] };
|
return rev ? { b: arr[0], a: arr[1] } : { a: arr[0], b: arr[1] };
|
||||||
};
|
};
|
||||||
|
|
||||||
let targetAssociations = target.associations[sourceName.plural] || target.associations[sourceName.singular];
|
const targetAssociations = target.associations[sourceName.plural]
|
||||||
let sourceType = association.associationType,
|
|| target.associations[sourceName.singular];
|
||||||
|
const sourceType = association.associationType,
|
||||||
targetType = (targetAssociations || {}).associationType;
|
targetType = (targetAssociations || {}).associationType;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -8,7 +8,8 @@ export const parseInclude = request => {
|
|||||||
const noRequestModels = !request.models;
|
const noRequestModels = !request.models;
|
||||||
|
|
||||||
if (noGetDb && noRequestModels) {
|
if (noGetDb && noRequestModels) {
|
||||||
return new Error('`request.getDb` or `request.models` are not defined. Be sure to load hapi-sequelize before hapi-sequelize-crud.');
|
return new Error('`request.getDb` or `request.models` are not defined.'
|
||||||
|
+ 'Be sure to load hapi-sequelize before hapi-sequelize-crud.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { models } = noGetDb ? request : request.getDb();
|
const { models } = noGetDb ? request : request.getDb();
|
||||||
|
Loading…
Reference in New Issue
Block a user