adding user-defined-fields
| | |
| | | getUserCount, |
| | | getUserByLogin, |
| | | getUserByUserId, |
| | | getUserDefinedFields, |
| | | getUserDefinedField, |
| | | } |
| | | |
| | | ///////////////////////////////////////////////////////////////////////// |
| | |
| | | async function getUsers (offset = 0, limit = 10) { |
| | | const sel = `usr_id, login, firstname, lastname, gender, email, institution, street, city, zipcode, country, department, active` |
| | | // TODO user defined fields |
| | | // TODO check args for SQL Injection |
| | | |
| | | const pool = await poolP |
| | | const [results, fields] = await pool.query( |
| | |
| | | async function getUserByLogin (login) { |
| | | const sel = `usr_id, login, firstname, lastname, gender, email, institution, street, city, zipcode, country, department, active` |
| | | // TODO user defined fields |
| | | // TODO check args for SQL Injection |
| | | |
| | | const pool = await poolP |
| | | const [results, fields] = await pool.query( |
| | |
| | | WHERE login = '${login}' |
| | | AND login REGEXP '^[0-9]+$'` |
| | | ) |
| | | return results |
| | | return joinUDF(results[0]) |
| | | } |
| | | |
| | | async function getUserByUserId (userId) { |
| | | const sel = `usr_id, login, firstname, lastname, gender, email, institution, street, city, zipcode, country, department, active` |
| | | // TODO user defined fields |
| | | // TODO check args for SQL Injection |
| | | |
| | | const pool = await poolP |
| | | const [results, fields] = await pool.query( |
| | |
| | | WHERE usr_id = '${userId}' |
| | | AND login REGEXP '^[0-9]+$'` |
| | | ) |
| | | return joinUDF(results[0]) |
| | | } |
| | | |
| | | async function getUserDefinedFields () { |
| | | const pool = await poolP |
| | | const [results] = await pool.query( |
| | | `SELECT ut.usr_id, ud.field_name, ut.value |
| | | FROM ilias.udf_definition ud |
| | | JOIN ilias.udf_text ut ON ut.field_id = ud.field_id` |
| | | ) |
| | | return results |
| | | } |
| | | |
| | | async function getUserDefinedField (usr_id) { |
| | | const pool = await poolP |
| | | const [results] = await pool.query( |
| | | `SELECT ut.usr_id, ud.field_name, ut.value |
| | | FROM ilias.udf_definition ud |
| | | JOIN ilias.udf_text ut ON ut.field_id = ud.field_id |
| | | WHERE ut.usr_id = '${usr_id}' |
| | | ` |
| | | ) |
| | | return results |
| | | } |
| | | |
| | |
| | | async function promiseDelay (ms) { |
| | | return new Promise(resolve => setTimeout(resolve, ms)) |
| | | } |
| | | |
| | | async function joinUDF (user) { |
| | | const fields = await getUserDefinedField(user.usr_id) |
| | | for(const field of fields) { |
| | | user[field.field_name] = field.value |
| | | } |
| | | return user |
| | | } |
| | |
| | | ///////////////////////////////////////////////////////////////////////// |
| | | |
| | | async function run() { |
| | | const user = await db.getUserByLogin("242424") |
| | | console.log("user", user) |
| | | // const user = await db.getUserByLogin("242424") |
| | | // console.log("user", user) |
| | | // |
| | | // const user2 = await db.getUserByUserId(317) |
| | | // console.log("user2", user2) |
| | | // |
| | | // const start = new Date() |
| | | // const users = await db.getUsers(10,0) |
| | | // const users2 = users.map(({usr_id,login,firstname,lastname,email,institution}) => ({usr_id,login,firstname,lastname,institution})) |
| | | // console.table(users2) |
| | | // console.log(new Date() - start + "ms") |
| | | // |
| | | // const count = await db.getUserCount() |
| | | // console.log("count",count) |
| | | |
| | | const user2 = await db.getUserByUserId(317) |
| | | console.log("user2", user2) |
| | | // console.time("udf") |
| | | // const udf = await db.getUserDefinedFields() |
| | | // console.log(udf) |
| | | // console.timeEnd("udf") |
| | | |
| | | const start = new Date() |
| | | const users = await db.getUsers(10,0) |
| | | const users2 = users.map(({usr_id,login,firstname,lastname,email,institution}) => ({usr_id,login,firstname,lastname,institution})) |
| | | console.table(users2) |
| | | console.log(new Date() - start + "ms") |
| | | // const usr = await db.getUserByUserId(316) |
| | | const usr = await db.getUserByLogin("051134") |
| | | console.log(usr) |
| | | |
| | | const count = await db.getUserCount() |
| | | console.log("count",count) |
| | | // console.time("udf1") |
| | | // const udf1 = await db.getUserDefinedField(316) |
| | | // console.log(udf1) |
| | | // console.timeEnd("udf1") |
| | | |
| | | |
| | | } |
| | | |
| | | // async function run () { |