@@ -112,26 +112,19 @@ class DBuser {
112
112
113
113
// Creates the user roles table
114
114
async create_table_user_roles ( ) {
115
- const client = await this . pool . connect ( ) ;
115
+ const client = await this . pool . connect ( ) ;
116
116
try {
117
117
// if ((await this.check_table("user_roles")) == false) {
118
118
119
119
await client . query ( "BEGIN" ) ;
120
- const query = `CREATE TABLE user_roles (
121
- rid INTEGER PRIMARY KEY,
122
- userid BIGINT NOT NULL,
123
- role varchar(64),
124
- time_assigned TIMESTAMP
125
- )` ;
126
- await client . query ( query ) ;
127
- await client . query ( "COMMIT" ) ;
128
- // } else {
129
- // console.log("Deleting create_user_roles_table");
130
- // await client.query("BEGIN");
131
- // const query = `DROP TABLE user_roles`;
132
- // await client.query(query);
133
- // await client.query("COMMIT");
134
- // }
120
+ const query = `CREATE TABLE user_roles (
121
+ rid INTEGER PRIMARY KEY,
122
+ userid BIGINT NOT NULL,
123
+ role varchar(64),
124
+ time_assigned TIMESTAMP
125
+ )` ;
126
+ await client . query ( query ) ;
127
+ await client . query ( "COMMIT" ) ;
135
128
} catch ( ex ) {
136
129
console . log ( `Something wrong happende:${ ex } ` ) ;
137
130
} finally {
@@ -259,7 +252,8 @@ class DBuser {
259
252
let result = await client . query ( query ) ;
260
253
261
254
const count = result . rows [ 0 ] [ "max" ] + 1 ;
262
- query = "INSERT INTO user_roles (RID, USERID, ROLE, TIME_ASSIGNED) VALUES ($1,$2,$3,NOW())" ;
255
+ query =
256
+ "INSERT INTO user_roles (RID, USERID, ROLE, TIME_ASSIGNED) VALUES ($1,$2,$3,NOW())" ;
263
257
const values = [ count , userid , role ] ;
264
258
result = await client . query ( query , values ) ;
265
259
@@ -271,7 +265,7 @@ class DBuser {
271
265
client . release ( ) ;
272
266
// console.log("Client released successfully.")
273
267
}
274
- }
268
+ }
275
269
276
270
// Removing a user role
277
271
async remove_user_role ( userid , role ) {
@@ -467,23 +461,22 @@ class DBuser {
467
461
const query = `
468
462
SELECT * FROM user_roles WHERE time_assigned < NOW() - interval '1 year'
469
463
` ;
470
-
464
+
471
465
const result = await client . query ( query ) ;
472
466
473
- const old_roles = result . rows . map ( row => ( {
467
+ const old_roles = result . rows . map ( ( row ) => ( {
474
468
role_name : row . role ,
475
- userid : row . userid
469
+ userid : row . userid ,
476
470
} ) ) ;
477
-
471
+
478
472
return old_roles ;
479
473
} catch ( error ) {
480
474
console . error ( error ) ;
481
- return old_roles ;
475
+ return [ ] ;
482
476
} finally {
483
477
client . release ( ) ;
484
478
}
485
479
}
486
-
487
480
}
488
481
489
482
module . exports = {
0 commit comments