fixed ESLint errores for the commited files.
This commit is contained in:
parent
9ed9e13b54
commit
76b0b955cf
|
@ -1,4 +1,4 @@
|
|||
module.exports = function(Client){
|
||||
module.exports = function(Client) {
|
||||
Client.remoteMethod('activate', {
|
||||
description: 'Activate or deactive client',
|
||||
accepts: {
|
||||
|
@ -9,7 +9,7 @@ module.exports = function(Client){
|
|||
http: {source: 'path'}
|
||||
},
|
||||
returns: {
|
||||
arg: 'active',
|
||||
arg: 'active',
|
||||
type: 'boolean'
|
||||
},
|
||||
http: {
|
||||
|
@ -17,13 +17,13 @@ module.exports = function(Client){
|
|||
path: '/:id/activate'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Client.activate = function(id, cb) {
|
||||
Client.findById(id, function(err, client) {
|
||||
if(!err) {
|
||||
Client.update({id: client.id}, {active: !client.active});
|
||||
if (!err) {
|
||||
Client.update({id: client.id}, {active: !client.active});
|
||||
cb(null, !client.active);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = function(Client){
|
||||
module.exports = function(Client) {
|
||||
Client.remoteMethod('addressesList', {
|
||||
description: 'List items using a filter',
|
||||
accessType: 'READ',
|
||||
|
@ -21,7 +21,7 @@ module.exports = function(Client){
|
|||
}
|
||||
],
|
||||
returns: {
|
||||
arg: 'data',
|
||||
arg: 'data',
|
||||
type: ['Address'],
|
||||
root: true
|
||||
},
|
||||
|
@ -31,17 +31,19 @@ module.exports = function(Client){
|
|||
}
|
||||
});
|
||||
|
||||
Client.addressesList = function(id, p, cb) {
|
||||
Client.addressesList = function(id, params, callback) {
|
||||
let filter = {
|
||||
where: {
|
||||
clientFk: id,
|
||||
clientFk: id
|
||||
},
|
||||
skip: (p.page - 1) * p.size,
|
||||
limit: p.size
|
||||
skip: (params.page - 1) * params.size,
|
||||
limit: params.size
|
||||
};
|
||||
|
||||
Client.app.models.Address.find(filter, function(err, instances) {
|
||||
(err)? cb(err, null) : cb(null, instances);
|
||||
if (err)
|
||||
return callback(err, null);
|
||||
callback(null, instances);
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
|
||||
module.exports = function(Client) {
|
||||
var CREDIT_CARD = 5;
|
||||
|
||||
Client.observe('before save', function(ctx, next) {
|
||||
|
||||
Client.observe('before save', function(ctx, next) {
|
||||
if (ctx.instance) {
|
||||
Object.assign(ctx.instance, doIfNullSalesPerson(ctx.instance));
|
||||
|
||||
if (!ctx.instance.dueDay)
|
||||
ctx.instance.dueDay = 5;
|
||||
|
||||
if(ctx.instance.equalizationTax && !canMarkEqualizationTax(ctx.instance))
|
||||
if (ctx.instance.equalizationTax && !canMarkEqualizationTax(ctx.instance))
|
||||
generateErrorEqualizationTax();
|
||||
|
||||
next();
|
||||
} else {
|
||||
Client.findById(ctx.where.id, function(err, instance) {
|
||||
Client.findById(ctx.where.id, (_, instance) => {
|
||||
Object.assign(ctx.data, doIfNullSalesPerson(instance));
|
||||
|
||||
if (instance
|
||||
|
@ -22,10 +22,10 @@ module.exports = function(Client) {
|
|||
&& instance.dueDay == ctx.data.dueDay)
|
||||
ctx.data.dueDay = 5;
|
||||
|
||||
if(instance.fi !== undefined && ctx.data.equalizationTax && !canMarkEqualizationTax(instance))
|
||||
if (instance.fi !== undefined && ctx.data.equalizationTax && !canMarkEqualizationTax(instance))
|
||||
next(generateErrorEqualizationTax());
|
||||
|
||||
if(instance.equalizationTax !== undefined && instance.equalizationTax && ctx.data.fi && !!canMarkEqualizationTax(ctx.data))
|
||||
if (instance.equalizationTax !== undefined && instance.equalizationTax && ctx.data.fi && Boolean(canMarkEqualizationTax(ctx.data)))
|
||||
next(generateErrorEqualizationTax());
|
||||
|
||||
next();
|
||||
|
@ -33,9 +33,9 @@ module.exports = function(Client) {
|
|||
}
|
||||
});
|
||||
|
||||
function doIfNullSalesPerson(instance){
|
||||
function doIfNullSalesPerson(instance) {
|
||||
var data = {};
|
||||
if(instance.salesPerson === null){
|
||||
if (instance.salesPerson === null) {
|
||||
data.credit = 0;
|
||||
data.discount = 0;
|
||||
data.payMethodFk = CREDIT_CARD;
|
||||
|
@ -43,17 +43,18 @@ module.exports = function(Client) {
|
|||
return data;
|
||||
}
|
||||
|
||||
function canMarkEqualizationTax(instance){
|
||||
function canMarkEqualizationTax(instance) {
|
||||
var firstLetter = instance.fi.toUpperCase().charAt(0);
|
||||
if(firstLetter != "A" && firstLetter != "B")
|
||||
if (firstLetter != "A" && firstLetter != "B")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function generateErrorEqualizationTax(){
|
||||
function generateErrorEqualizationTax() {
|
||||
var error = new Error();
|
||||
error.message = "No se puede marcar el recargo de equivalencia";
|
||||
error.status = 500;
|
||||
return error;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ module.exports = function(Client) {
|
|||
http: {source: 'path'}
|
||||
},
|
||||
returns: {
|
||||
arg: 'data',
|
||||
arg: 'data',
|
||||
type: 'Client',
|
||||
root: true
|
||||
},
|
||||
|
@ -18,7 +18,7 @@ module.exports = function(Client) {
|
|||
path: '/:id/card'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Client.card = function(id, cb) {
|
||||
let filter = {
|
||||
where: {
|
||||
|
@ -28,9 +28,9 @@ module.exports = function(Client) {
|
|||
};
|
||||
|
||||
Client.find(filter, function(err, instances) {
|
||||
if(!err) {
|
||||
if (!err) {
|
||||
cb(null, instances[0]);
|
||||
}
|
||||
})
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = function(Client){
|
||||
module.exports = function(Client) {
|
||||
Client.remoteMethod('employeeList', {
|
||||
description: 'List employee',
|
||||
accessType: 'READ',
|
||||
|
@ -13,18 +13,20 @@ module.exports = function(Client){
|
|||
}
|
||||
});
|
||||
|
||||
Client.employeeList = function(cb) {
|
||||
var include = {include: { relation: 'user'}, where: { userFk: { neq: null }}};
|
||||
Client.employeeList = function(cb) {
|
||||
var include = {include: {relation: 'user'}, where: {userFk: {neq: null}}};
|
||||
Client.app.models.Employee.find(include, function(err, instances) {
|
||||
(err) ? cb(err, null) : cb(null, generateEmployees(instances));
|
||||
});
|
||||
if (err)
|
||||
cb(err, null);
|
||||
cb(null, generateEmployees(instances));
|
||||
});
|
||||
};
|
||||
|
||||
function generateEmployees(instances){
|
||||
function generateEmployees(instances) {
|
||||
var emps = [];
|
||||
instances.forEach(function(e) {
|
||||
emps.push({id: e.id, name: e.user().name});
|
||||
}, this);
|
||||
return emps;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
module.exports = function(Client){
|
||||
module.exports = function(Client) {
|
||||
Client.installMethod('filter', filterClients);
|
||||
|
||||
function filterClients(params) {
|
||||
if(params.search)
|
||||
if (params.search)
|
||||
return searchWhere(params);
|
||||
return andWhere(params);
|
||||
}
|
||||
|
||||
function searchWhere(params){
|
||||
function searchWhere(params) {
|
||||
return {
|
||||
where: {
|
||||
or:[
|
||||
{id: params.search,},
|
||||
or: [
|
||||
{id: params.search},
|
||||
{name: {regexp: params.search}}
|
||||
]
|
||||
|
||||
|
||||
},
|
||||
skip: (params.page - 1) * params.size,
|
||||
limit: params.size
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function andWhere(params){
|
||||
function andWhere(params) {
|
||||
let filters = {
|
||||
where: {},
|
||||
skip: (params.page - 1) * params.size,
|
||||
|
@ -30,8 +30,8 @@ module.exports = function(Client){
|
|||
|
||||
delete params.page;
|
||||
delete params.size;
|
||||
|
||||
if(params.phone){
|
||||
|
||||
if (params.phone) {
|
||||
filters.where.or = [
|
||||
{phone: params.phone},
|
||||
{mobile: params.phone}
|
||||
|
@ -40,9 +40,9 @@ module.exports = function(Client){
|
|||
}
|
||||
Object.keys(params).forEach(
|
||||
key => {
|
||||
filters.where[key] = (key === 'postcode' || key === 'fi')? params[key] : {regexp: params[key]};
|
||||
filters.where[key] = (key === 'postcode' || key === 'fi') ? params[key] : {regexp: params[key]};
|
||||
}
|
||||
)
|
||||
);
|
||||
return filters;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = (Client) => {
|
||||
module.exports = Client => {
|
||||
Client.remoteMethod('getRoleCustomer', {
|
||||
description: 'devuelve true/false si es Customer el client',
|
||||
accessType: 'READ',
|
||||
|
@ -15,13 +15,13 @@ module.exports = (Client) => {
|
|||
type: 'object',
|
||||
required: true,
|
||||
description: 'Filter defining where',
|
||||
http: function(ctx) {
|
||||
return ctx.req.query;
|
||||
http: function(context) {
|
||||
return context.req.query;
|
||||
}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
arg: 'data',
|
||||
arg: 'data',
|
||||
type: Boolean,
|
||||
root: true
|
||||
},
|
||||
|
@ -31,15 +31,15 @@ module.exports = (Client) => {
|
|||
}
|
||||
});
|
||||
|
||||
Client.getRoleCustomer = (id, ctx, cb) => {
|
||||
Client.getRoleCustomer = (id, context, callback) => {
|
||||
let query = `SELECT count(*) isCustomer FROM Account ac JOIN Role ON Role.id = ac.roleFK WHERE Role.\`name\`='customer' AND ac.id IN (?)`;
|
||||
const params = [id];
|
||||
Client.rawSql(query, params, cb)
|
||||
.then((response) => {
|
||||
cb(null, response);
|
||||
})
|
||||
.catch((reject) => {
|
||||
cb (reject, null)
|
||||
});
|
||||
Client.rawSql(query, params, callback)
|
||||
.then(response => {
|
||||
callback(null, response);
|
||||
})
|
||||
.catch(reject => {
|
||||
callback(reject, null);
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue