diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 0a0865bdfe..67f9082eca 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -72,7 +72,7 @@ "The secret can't be blank": "La contraseña no puede estar en blanco", "We weren't able to send this SMS": "No hemos podido enviar el SMS", "This client can't be invoiced": "Este cliente no puede ser facturado", - "You must provide the correction information to generate a corrective invoice": "Debes informar la información de corrección para generar una factura rectificativa", + "You must provide the correction information to generate a corrective invoice": "Debes informar la información de corrección para generar una factura rectificativa", "This ticket can't be invoiced": "Este ticket no puede ser facturado", "You cannot add or modify services to an invoiced ticket": "No puedes añadir o modificar servicios a un ticket facturado", "This ticket can not be modified": "Este ticket no puede ser modificado", @@ -336,5 +336,6 @@ "Incorrect pin": "Pin incorrecto", "You already have the mailAlias": "Ya tienes este alias de correo", "The alias cant be modified": "Este alias de correo no puede ser modificado", - "No tickets to invoice": "No hay tickets para facturar" + "No tickets to invoice": "No hay tickets para facturar", + "An email is necessary": "Es necesario un email" } diff --git a/modules/client/back/methods/client/createWithUser.js b/modules/client/back/methods/client/createWithUser.js index 8e0d56f49e..06b885ab82 100644 --- a/modules/client/back/methods/client/createWithUser.js +++ b/modules/client/back/methods/client/createWithUser.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = function(Self) { Self.remoteMethod('createWithUser', { description: 'Creates both client and its web account', @@ -29,7 +31,11 @@ module.exports = function(Self) { myOptions.transaction = tx; } - const firstEmail = data.email ? data.email.split(',')[0] : null; + if (!data.email) + throw new UserError('An email is necessary'); + + const firstEmail = data.email.split(',')[0]; + const user = { name: data.userName, email: firstEmail, diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index 03106acc11..074cb289a9 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -13,6 +13,8 @@ describe('Client Create', () => { businessTypeFk: 'florist', provinceFk: 1 }; + const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount)); + delete newAccountWithoutEmail.email; beforeAll(async() => { const activeCtx = { @@ -48,6 +50,24 @@ describe('Client Create', () => { } }); + it('should not create a new account', async() => { + const tx = await models.Client.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + await models.Client.createWithUser(newAccountWithoutEmail, options); + + await tx.rollback(); + } catch (e) { + error = e.message; + + await tx.rollback(); + } + + expect(error).toEqual(`An email is necessary`); + }); + it('should create a new account', async() => { const tx = await models.Client.beginTransaction({});