Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
m4lab_tv1
User Account
Commits
e00f0382
Commit
e00f0382
authored
Sep 24, 2021
by
Wolfgang Knopki
Browse files
pick connection from pool before transaction
parent
0a1273fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
functions/methods.ts
View file @
e00f0382
...
...
@@ -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
:
newUserI
d
let
newUserId
:
number
=
results
.
insertId
// set password
var
credentialData
:
any
=
{
user
_id
:
newUserId
,
password
:
data
.
passwor
d
}
dbconn
.
user
.
query
(
'
INSERT INTO
user_project_role SET ?
'
,
projectRole
Data
,
function
(
err
:
any
,
results
:
any
,
fields
:
any
)
{
thisconn
.
query
(
'
INSERT INTO
credential SET ?
'
,
credential
Data
,
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 ?
'
,
verification
Data
,
function
(
err
:
any
,
results
:
any
,
fields
:
any
)
{
thisconn
.
query
(
'
INSERT INTO
user_project_role SET ?
'
,
projectRole
Data
,
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment