| 22 | }); |
| 23 | |
| 24 | async function log_operation_to_db(data) { |
| 25 | /* Query syntax */ |
| 26 | const query_log_operation = TASK_QUERIES.ACCESS_OPERTION.LOG_OPERATION; |
| 27 | const query_log_operation_error = TASK_QUERIES.ACCESS_OPERTION.LOG_OPERATION_ERROR; |
| 28 | |
| 29 | try { |
| 30 | const pool = await pool_promise; |
| 31 | await pool.request() |
| 32 | .input('token', sql.NVarChar, data.token || '') |
| 33 | .input('ip_address', sql.NVarChar, data.ip_address || '') |
| 34 | .input('sso_account', sql.NVarChar, data.sso_account || '') |
| 35 | .input('query_time', sql.NVarChar, data.query_time || '') |
| 36 | .input('process_id', sql.NVarChar, data.process_id || '') |
| 37 | .input('code', sql.NVarChar, data.code || '') |
| 38 | .input('route', sql.NVarChar, data.route || '') |
| 39 | .input('ref', sql.BigInt, data.ref) |
| 40 | .input('log', sql.NVarChar, data.log || '') |
| 41 | .query(query_log_operation); |
| 42 | } catch (err) { |
| 43 | const pool = await pool_promise; |
| 44 | await pool.request() |
| 45 | .input('token', sql.NVarChar, data.token || '') |
| 46 | .input('ip_address', sql.NVarChar, data.ip_address || '') |
| 47 | .input('sso_account', sql.NVarChar, data.sso_account || '') |
| 48 | .input('query_time', sql.NVarChar, data.query_time || '') |
| 49 | .input('process_id', sql.NVarChar, data.process_id || '') |
| 50 | .input('code', sql.NVarChar, data.code || '-1') |
| 51 | .input('route', sql.NVarChar, data.route || '') |
| 52 | .input('ref', sql.BigInt, data.ref) |
| 53 | .input('err', sql.NVarChar, err || '') |
| 54 | .query(query_log_operation_error); |
| 55 | console.error(`[${process.pid}] log_operation: data write failed ${err}.`); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | module.exports = { |
| 60 | // sql_db, |