@@ -7,11 +7,11 @@ const request = require('superagent')
7
7
const config = require ( 'config' )
8
8
9
9
/**
10
- *
10
+ *
11
11
* @param {string } handle - The member handle
12
- * @returns {Promise<object> } The member details from the member API
12
+ * @returns {Promise<object> } The member details from the member API
13
13
*/
14
- async function getMemberDetailsByHandle ( handle ) {
14
+ async function getMemberDetailsByHandle ( handle ) {
15
15
const token = await helper . getM2MToken ( )
16
16
let res
17
17
try {
@@ -45,24 +45,23 @@ const processRemainingUUIDs = async (tableName, columnNames) => {
45
45
console . log ( )
46
46
47
47
for ( const columnName of _ . split ( columnNames , ',' ) ) {
48
-
49
- let transaction = await models . sequelize . transaction ( )
48
+ const transaction = await models . sequelize . transaction ( )
50
49
51
50
try {
52
51
// check each column to find distinct existing uuids which have not yet been converted to TC legacy user id
53
52
const query = `SELECT DISTINCT ${ columnName } FROM bookings.${ tableName } WHERE LENGTH(${ columnName } ) > 9 AND ${ columnName } <> '00000000-0000-0000-0000-000000000000';`
54
53
console . log ( `Executing query in table ${ tableName } against column ${ columnName } ` )
55
54
console . log ( `SQL query: ${ query } ` )
56
55
let results = await models . sequelize . query ( query , { type : Sequelize . QueryTypes . SELECT } )
57
-
56
+
58
57
if ( results . length > 0 ) {
59
58
results = _ . uniq ( _ . map ( _ . filter ( results , val => toString ( val [ `${ columnName } ` ] ) . length > 9 ) , val => val [ `${ columnName } ` ] ) )
60
59
console . log ( `SQL query result: ${ JSON . stringify ( results ) } ` )
61
-
60
+
62
61
// get the ubahn uuid to handle map
63
62
const ubahnConn = await tcUserId . getUbahnDatabaseConnection ( dbUrl )
64
63
const uuidToHandleMap = await tcUserId . getUserUbahnUUIDToHandleMap ( ubahnConn , results )
65
-
64
+
66
65
// get the handle to legacy topcoder id map
67
66
for ( const handle of Object . values ( uuidToHandleMap ) ) {
68
67
console . log ( `handle to search for ${ handle } ` )
@@ -71,20 +70,20 @@ const processRemainingUUIDs = async (tableName, columnNames) => {
71
70
handleToIDMap [ member . handleLower ] = member . userId
72
71
}
73
72
}
74
-
73
+
75
74
// build the update queries
76
75
let sql = ''
77
76
for ( const [ key , value ] of Object . entries ( uuidToHandleMap ) ) {
78
77
if ( ! _ . isUndefined ( handleToIDMap [ value . toLowerCase ( ) ] ) ) {
79
78
sql += `UPDATE bookings.${ tableName } SET ${ columnName } = '${ handleToIDMap [ value . toLowerCase ( ) ] } ' WHERE ${ columnName } = '${ key } ';`
80
79
}
81
80
}
82
-
81
+
83
82
// execute update queries if and only if it's not in test mode
84
83
if ( sql !== '' ) {
85
84
console . log ( `SQL UPDATE statements: ${ sql } ` )
86
85
if ( MODE !== 'test' ) {
87
- console . log ( ` Executing UPDATE statements` )
86
+ console . log ( ' Executing UPDATE statements' )
88
87
await models . sequelize . query ( sql , { type : Sequelize . QueryTypes . UPDATE , transaction : transaction } )
89
88
}
90
89
} else {
@@ -93,15 +92,14 @@ const processRemainingUUIDs = async (tableName, columnNames) => {
93
92
} else {
94
93
console . log ( `No data eligible to be updated for table: ${ tableName } against column ${ columnName } ` )
95
94
}
96
-
95
+
97
96
// only for readability
98
97
console . log ( '---------------------------------------------------------------------------------------------------------------' )
99
98
console . log ( )
100
99
101
100
await transaction . commit ( )
102
-
103
101
} catch ( error ) {
104
- console . log ( ` Error encountered` )
102
+ console . log ( ' Error encountered' )
105
103
console . error ( JSON . stringify ( error ) )
106
104
await transaction . rollback ( )
107
105
}
@@ -119,7 +117,7 @@ processRemainingUUIDs(tableName, columnNames).then(res => {
119
117
console . log ( `Processed remaining records for model '${ tableName } ' against columns: ${ columnNames } ` )
120
118
process . exit ( 0 )
121
119
} ) . catch ( err => {
122
- console . log ( ` Error encountered!` )
120
+ console . log ( ' Error encountered!' )
123
121
console . error ( `${ JSON . stringify ( err ) } ` )
124
122
process . exit ( 1 )
125
- } )
123
+ } )
0 commit comments