import { type ResultSetHeader, type RowDataPacket, type QueryOptions } from "mysql2" import pool from 'miscellaneous/db' interface CashTransaction extends RowDataPacket { id?: number; rawMessage?: string; day?: number; month?: number; year?: number; amount?: number; type?: number; company?: string; } async function save(rawMessage: string, day: number, month: number, year: number, amount: number, type: number, company: string): Promise { try { const options: QueryOptions = { sql: "INSERT INTO bankCardTransaction (raw, day, month, year, amount, type, company) VALUES (?,?,?,?,?,?,?)", values: [rawMessage, day, month, year, amount, type, company] }; const [result, fields] = await pool.query(options); return result.affectedRows; } catch (err) { console.log(err); } return 0; } async function find(): Promise { try { const [rows, fields] = await pool.query("SELECT * FROM bankCardTransaction;"); return rows; } catch (err) { console.log(err); } return []; } async function findWithPar(month: number, year: number): Promise { try { const [rows, fields] = await pool.query("SELECT * FROM bankCardTransaction;"); return rows; } catch (err) { console.log(err); } return []; } async function findOneAndDelete(type: number): Promise { try { const [result, fields] = await pool.query("DELETE FROM bankCardTransaction WHERE type = ?;", [type]); return result.affectedRows; } catch (err) { console.log(err); } return 0; } export default { find, findWithPar, save, findOneAndDelete };