Commit 31d44844 authored by Wolfgang Knopki's avatar Wolfgang Knopki
Browse files

Merge branch 'MLAB-566-fix' into 'testing'

pick connection from pool before transaction

See merge request !118
parents 0a1273fd e00f0382
Pipeline #4846 passed with stage
in 36 seconds
......@@ -3,12 +3,13 @@ import dbconn = require('../config/dbconn')
var methods = {
// ===================== user db =====================
registerNewUser: function(data:any, callback:any) {
dbconn.user.beginTransaction(function(err:any) { // START TRANSACTION
dbconn.user.getConnection(function(err:any, thisconn){
thisconn.beginTransaction(function(err:any) { // START TRANSACTION
if (err) { throw err }
// insert profile
dbconn.user.query('INSERT INTO user SET ?', data.profile, function (err:any, results:any, fields:any) {
thisconn.query('INSERT INTO user SET ?', data.profile, function (err:any, results:any, fields:any) {
if (err) {
return dbconn.user.rollback(function() {
return thisconn.rollback(function() {
throw err
});
}
......@@ -18,9 +19,9 @@ var methods = {
user_id: newUserId,
password: data.password
}
dbconn.user.query('INSERT INTO credential SET ?', credentialData, function (err:any, results:any, fields:any) {
thisconn.query('INSERT INTO credential SET ?', credentialData, function (err:any, results:any, fields:any) {
if (err) {
return dbconn.user.rollback(function() {
return thisconn.rollback(function() {
throw err
});
}
......@@ -30,9 +31,9 @@ var methods = {
role_id: 2, // USER
user_id: newUserId
}
dbconn.user.query('INSERT INTO user_project_role SET ?', projectRoleData, function (err:any, results:any, fields:any) {
thisconn.query('INSERT INTO user_project_role SET ?', projectRoleData, function (err:any, results:any, fields:any) {
if (err) {
return dbconn.user.rollback(function() {
return thisconn.rollback(function() {
throw err
});
}
......@@ -41,16 +42,16 @@ var methods = {
user_id: newUserId,
token: data.verificationToken
}
dbconn.user.query('INSERT INTO verification SET ?', verificationData, function (err:any, results:any, fields:any) {
thisconn.query('INSERT INTO verification SET ?', verificationData, function (err:any, results:any, fields:any) {
if (err) {
return dbconn.user.rollback(function() {
return thisconn.rollback(function() {
throw err
});
}
// COMMIT
dbconn.user.commit(function(err:any) {
thisconn.commit(function(err:any) {
if (err) {
return dbconn.user.rollback(function() {
return thisconn.rollback(function() {
throw err
})
}
......@@ -60,6 +61,8 @@ var methods = {
});
});
callback(err)
});
callback(err)
})
},
getUserByEmail: async function(email:any) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment