From 1ecb3f3d2b794a498abeae9d234593dbbd806a2f Mon Sep 17 00:00:00 2001 From: gerard Date: Mon, 18 Jun 2018 13:41:49 +0200 Subject: [PATCH] Bug #358 Credit create no da un error comprensible --- services/loopback/common/locale/en.json | 4 ++-- services/loopback/common/locale/es.json | 5 +++-- services/loopback/common/models/client.js | 12 ++++-------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/services/loopback/common/locale/en.json b/services/loopback/common/locale/en.json index cb55ef678..8074b6492 100644 --- a/services/loopback/common/locale/en.json +++ b/services/loopback/common/locale/en.json @@ -4,7 +4,7 @@ "Unable to mark the equivalence surcharge": "Unable to mark the equivalence surcharge", "The default consignee can not be unchecked": "The default consignee can not be unchecked", "Unable to default a disabled consignee": "Unable to default a disabled consignee", - "Can't be blank": "No puede estar en blanco", + "Can't be blank": "Can't be blank", "Invalid TIN": "Invalid TIN", "TIN must be unique": "TIN must be unique", "A user with that name already exists": "A user with that name already exists", @@ -18,5 +18,5 @@ "That payment method requires an IBAN": "That payment method requires an IBAN", "State cannot be blank": "State cannot be blank", "Cannot change the payment method if no salesperson": "Cannot change the payment method if no salesperson", - "Observation type cannot be blank": "Observation type cannot be blank" + "Only manager can change the credit": "Only manager can change the credit" } \ No newline at end of file diff --git a/services/loopback/common/locale/es.json b/services/loopback/common/locale/es.json index 35e24433b..fc733c388 100644 --- a/services/loopback/common/locale/es.json +++ b/services/loopback/common/locale/es.json @@ -4,7 +4,7 @@ "Unable to mark the equivalence surcharge": "No se puede marcar el recargo de equivalencia", "The default consignee can not be unchecked": "No se puede desmarcar el consignatario predeterminado", "Unable to default a disabled consignee": "No se puede poner predeterminado un consignatario desactivado", - "Can't be blank": "Can't be blank", + "Can't be blank": "No puede estar en blanco", "Invalid TIN": "DNI Incorrecto", "TIN must be unique": "El NIF/CIF debe ser único", "A user with that name already exists": "Ya existe un usuario con ese nombre", @@ -23,5 +23,6 @@ "Observation type must be unique": "El tipo de observación no puede repetirse", "The credit must be an integer greater than or equal to zero": "The credit must be an integer greater than or equal to zero", "The grade must be similar to the last one": "El grade debe ser similar al último", - "NO_AGENCY_AVAILABLE": "NO_AGENCY_AVAILABLE" + "NO_AGENCY_AVAILABLE": "NO_AGENCY_AVAILABLE", + "Only manager can change the credit": "Solo el gerente puede cambiar el credito de este cliente" } \ No newline at end of file diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js index 762cbe2f5..c85a78571 100644 --- a/services/loopback/common/models/client.js +++ b/services/loopback/common/models/client.js @@ -111,11 +111,7 @@ module.exports = Self => { } if (changes.credit !== undefined) { - try { - await validateCreditChange(ctx, finalState); - } catch (e) { - throw new UserError('You are not allowed to change the credit'); - } + await validateCreditChange(ctx, finalState); let filter = {fields: ['id'], where: {userFk: ctx.options.accessToken.userId}}; let worker = await Self.app.models.Worker.findOne(filter); @@ -146,7 +142,7 @@ module.exports = Self => { let limits = await models.ClientCreditLimit.find(filter); if (limits.length == 0) - throw new Error('Credit limits not found'); + throw new UserError('Credit limits not found'); // Si el usuario no tiene alguno de los roles no continua @@ -162,7 +158,7 @@ module.exports = Self => { let count = await models.RoleMapping.count(where); if (count <= 0) - throw new Error('The role cannot set this credit amount'); + throw new UserError('The role cannot set this credit amount'); // Si se puso a 0 por gerencia, solo gerencia puede aumentarlo @@ -185,6 +181,6 @@ module.exports = Self => { let instance = await Self.rawSql(query, [instances[0].workerFk]); if (instance[0].hasRoleManager) - throw new Error('Only manager can change the credit'); + throw new UserError('Only manager can change the credit'); } };