From a9763e728c96621d99d027b8a28bed5d33b77f56 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 6 Sep 2017 09:56:36 +0200 Subject: [PATCH] refactor for backend create.js transaction and it's html error notification for account implemented --- client/client/src/create/create.html | 2 +- services/client/common/methods/client/create.js | 11 ++++++----- services/client/common/models/account.js | 8 ++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 services/client/common/models/account.js diff --git a/client/client/src/create/create.html b/client/client/src/create/create.html index ca7b4d899..61103e638 100644 --- a/client/client/src/create/create.html +++ b/client/client/src/create/create.html @@ -1,4 +1,4 @@ - + { + Client.createUserProfile = (data, callback) => { let user = { name: data.userName, email: data.email, @@ -28,6 +28,7 @@ module.exports = function(Client){ app.models.Account.beginTransaction('READ COMMITTED', (err, transaction) => { app.models.Account.create (user, {transaction}, (err, account) => { if (err) { + transaction.rollback(); return callback(err); } @@ -38,7 +39,7 @@ module.exports = function(Client){ id: account.id }; - Client.create (client, (err, client) => { + Client.create (client, {transaction}, (err, client) => { if (err) { transaction.rollback(); return callback(err); diff --git a/services/client/common/models/account.js b/services/client/common/models/account.js new file mode 100644 index 000000000..5b47bdaa9 --- /dev/null +++ b/services/client/common/models/account.js @@ -0,0 +1,8 @@ +module.exports = function(Account) { + + // Validations + + Account.validatesUniquenessOf('name', { + message: 'Ya existe un usuario con ese nombre' + }); +}; \ No newline at end of file