diff --git a/services/client/common/methods/client/create.js b/services/client/common/methods/client/create.js index fd7ef6b55..16f764dc1 100644 --- a/services/client/common/methods/client/create.js +++ b/services/client/common/methods/client/create.js @@ -18,29 +18,36 @@ module.exports = function(Client){ } }); - Client.createNew = (data, cb) => { + Client.createNew = (data, callback) => { let user = { name: data.userName, email: data.email, password: parseInt(Math.random() * 100000000000000) }; - app.models.Account.create (user, (err, obj) => { - if (err) { - cb(err); - } else { + + app.models.Account.beginTransaction('READ COMMITTED', (err, transaction) => { + app.models.Account.create (user, {transaction}, (err, account) => { + if (err) { + return callback(err); + } + let client = { name: data.name, fi: data.fi, socialName: data.socialName, - id: obj.id + id: account.id }; - Client.create (client, (err, obj) => { - if (err) - cb(err); - else - cb(null, true); + + Client.create (client, (err, client) => { + if (err) { + transaction.rollback(); + return callback(err); + } + + transaction.commit(); + callback(null, true); }); - }; + }); }); }; -}; +}; \ No newline at end of file