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