import sqlite from 'better-sqlite3'; import { sunriseDB } from '../helpers/database.helpers.js'; export default function getContractFees(contractId, connectedDatabase) { const database = connectedDatabase ?? sqlite(sunriseDB, { readonly: true }); const fees = database .prepare(`select o.contractId, o.feeId, c.feeCategory, f.feeName, f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity, f.quantityUnit from ContractFees o left join Fees f on o.feeId = f.feeId left join FeeCategories c on f.feeCategoryId = c.feeCategoryId where o.recordDelete_timeMillis is null and o.contractId = ? order by o.recordCreate_timeMillis`) .all(contractId); if (connectedDatabase === undefined) { database.close(); } return fees; }