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,62 +3,65 @@ import dbconn = require('../config/dbconn')
var methods = {
// ===================== user db =====================
registerNewUser: function(data:any, callback:any) {
dbconn.user.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) {
if (err) {
return dbconn.user.rollback(function() {
throw err
});
}
let newUserId:number = results.insertId
// set password
var credentialData:any = {
user_id: newUserId,
password: data.password
}
dbconn.user.query('INSERT INTO credential SET ?', credentialData, function (err:any, results:any, fields:any) {
dbconn.user.getConnection(function(err:any, thisconn){
thisconn.beginTransaction(function(err:any) { // START TRANSACTION
if (err) { throw err }
// insert profile
thisconn.query('INSERT INTO user SET ?', data.profile, function (err:any, results:any, fields:any) {
if (err) {
return dbconn.user.rollback(function() {
throw err
});
return thisconn.rollback(function() {
throw err
});
}
// set default user-project-role
var projectRoleData:any = {
project_id: 1, //M4_LAB
role_id: 2, // USER
user_id: newUserId
let newUserId:number = results.insertId
// set password
var credentialData:any = {
user_id: newUserId,
password: data.password
}
dbconn.user.query('INSERT INTO user_project_role SET ?', projectRoleData, 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
});
}
// MLAB-129: INSERT verification token
let verificationData:any = {
user_id: newUserId,
token: data.verificationToken
// set default user-project-role
var projectRoleData:any = {
project_id: 1, //M4_LAB
role_id: 2, // USER
user_id: newUserId
}
dbconn.user.query('INSERT INTO verification SET ?', verificationData, 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
});
}
// COMMIT
dbconn.user.commit(function(err:any) {
// MLAB-129: INSERT verification token
let verificationData:any = {
user_id: newUserId,
token: data.verificationToken
}
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
thisconn.commit(function(err:any) {
if (err) {
return thisconn.rollback(function() {
throw err
})
}
})
})
})
})
});
});
});
callback(err)
});
callback(err)
})
},
......@@ -208,4 +211,4 @@ var methods = {
}
};
export = methods
\ No newline at end of file
export = methods
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