"use strict"; function attachAccountTransaction(db, { actor, target, users } = {}) { if (db.pool) return db; const reads = []; const lookup = (id) => users ? users.get(Number(id)) : Number(target?.id) === Number(id) ? target : null; return { ...db, reads, pool: { getConnection: async () => ({ beginTransaction: async () => {}, commit: async () => {}, rollback: async () => {}, release() {}, execute: async (sql, params = []) => { if (sql.startsWith("SELECT id, admin, suspended, session_epoch")) { reads.push({ sql, params }); const liveActor = users?.has(Number(actor?.id)) ? users.get(Number(actor.id)) : actor; return [[liveActor].filter((row) => row && Number(row.admin) === 1)]; } if (sql.startsWith("SELECT id, email, admin, session_epoch")) { reads.push({ sql, params }); const live = lookup(params[0]); return [live ? [{ ...live }] : []]; } return [await db.query(sql, params)]; } }) } }; } module.exports = { attachAccountTransaction };