-
Notifications
You must be signed in to change notification settings - Fork 18
Add accounting module with bank balance sheet endpoint #2991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
|
||
| function executeSql(sql) { | ||
| try { | ||
| execSync(`docker exec dfx-mssql /opt/mssql-tools18/bin/sqlcmd -U sa -P 'LocalDev2026@SQL' -d dfx -C -Q "${sql.replace(/"/g, '\\"')}"`, { |
Check failure
Code scanning / CodeQL
Uncontrolled command line Critical
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 days ago
In general, the fix is to avoid passing a single concatenated command string to child_process.execSync, and instead use execFileSync with an explicit executable and an array of arguments. This bypasses the shell, so even if sql contains characters like quotes, semicolons, or backticks, they are treated as data for sqlcmd rather than being interpreted by the shell. We should also avoid manual quote-escaping for shell purposes (sql.replace(/"/g, '\\"')), because shell escaping is no longer needed once we remove the shell.
Concretely, in scripts/sync-bank-tx.js:
- Add
execFileSyncto thechild_processimport. - Rewrite
executeSqlso it callsexecFileSync('docker', [...])instead ofexecSyncwith a command string. The arguments array will be:['exec', 'dfx-mssql', '/opt/mssql-tools18/bin/sqlcmd', '-U', 'sa', '-P', 'LocalDev2026@SQL', '-d', 'dfx', '-C', '-Q', sql]
- Remove the
sql.replace(/"/g, '\\"')since shell quoting is no longer required; the rawsqlstring can be passed directly as a single argument. - Keep the existing options
stdio: 'pipe'andmaxBufferto preserve behavior.
No other parts of the file need changing; the rest of the script can continue building SQL as before, but the command execution is now shell-free.
-
Copy modified line R9 -
Copy modified lines R94-R103
| @@ -6,7 +6,7 @@ | ||
| */ | ||
|
|
||
| const https = require('https'); | ||
| const { execSync } = require('child_process'); | ||
| const { execSync, execFileSync } = require('child_process'); | ||
| const path = require('path'); | ||
| require('dotenv').config({ path: path.join(__dirname, '.env.db-debug') }); | ||
|
|
||
| @@ -91,7 +91,16 @@ | ||
|
|
||
| function executeSql(sql) { | ||
| try { | ||
| execSync(`docker exec dfx-mssql /opt/mssql-tools18/bin/sqlcmd -U sa -P 'LocalDev2026@SQL' -d dfx -C -Q "${sql.replace(/"/g, '\\"')}"`, { | ||
| execFileSync('docker', [ | ||
| 'exec', | ||
| 'dfx-mssql', | ||
| '/opt/mssql-tools18/bin/sqlcmd', | ||
| '-U', 'sa', | ||
| '-P', 'LocalDev2026@SQL', | ||
| '-d', 'dfx', | ||
| '-C', | ||
| '-Q', sql | ||
| ], { | ||
| stdio: 'pipe', | ||
| maxBuffer: 50 * 1024 * 1024 | ||
| }); |
|
|
||
| function executeSql(sql) { | ||
| try { | ||
| execSync(`docker exec dfx-mssql /opt/mssql-tools18/bin/sqlcmd -U sa -P 'LocalDev2026@SQL' -d dfx -C -Q "${sql.replace(/"/g, '\\"')}"`, { |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 days ago
In general, you should avoid manually escaping characters when building shell commands, and instead either (a) avoid the shell entirely by using execFile/spawn with an argument array, or (b) if you must stay with execSync and a single command string, ensure that all characters that affect the quoting/escaping rules (notably backslash and the quote characters in use) are handled correctly. For our context, using execSync with an argument array is the most reliable fix and preserves existing functionality.
The best fix here is to stop embedding sql into a double‑quoted -Q "..." argument string inside a larger shell‑quoted command. Instead, call docker directly with arguments, and pass the entire sqlcmd invocation (and the sql string) as arguments. Node’s child_process.execSync supports a form where the first argument is the command and the second is an array of arguments; it then handles escaping correctly according to the underlying platform. This means we no longer need sql.replace(...) at all, eliminating the incomplete escaping issue.
Concretely, in scripts/sync-bank-tx.js, update the executeSql function (around line 92–99):
- Replace the single string command to
execSyncwith a call using the command'docker'and an array of arguments. - Build the argument array equivalent to the original command:
["exec", "dfx-mssql", "/opt/mssql-tools18/bin/sqlcmd", "-U", "sa", "-P", "LocalDev2026@SQL", "-d", "dfx", "-C", "-Q", sql]. - Remove the
sql.replace(/"/g, '\\"')since escaping is now handled by the OS andexecSyncargument processing.
No new imports are needed; we already import { execSync } from child_process.
-
Copy modified lines R94-R103
| @@ -91,7 +91,16 @@ | ||
|
|
||
| function executeSql(sql) { | ||
| try { | ||
| execSync(`docker exec dfx-mssql /opt/mssql-tools18/bin/sqlcmd -U sa -P 'LocalDev2026@SQL' -d dfx -C -Q "${sql.replace(/"/g, '\\"')}"`, { | ||
| execSync('docker', [ | ||
| 'exec', | ||
| 'dfx-mssql', | ||
| '/opt/mssql-tools18/bin/sqlcmd', | ||
| '-U', 'sa', | ||
| '-P', 'LocalDev2026@SQL', | ||
| '-d', 'dfx', | ||
| '-C', | ||
| '-Q', sql | ||
| ], { | ||
| stdio: 'pipe', | ||
| maxBuffer: 50 * 1024 * 1024 | ||
| }); |
3711725 to
b4e1987
Compare
- Add AccountingModule with balance sheet calculation - Add /accounting/balance-sheet/:iban/:year endpoint - Add yearlyBalances field to Bank entity for opening/closing balances - Calculate income (CRDT) and expenses (DBIT) from bank_tx - Validate calculated closing against defined closing balance - Add sync scripts for local development
b4e1987 to
3cfeed0
Compare
Add historical bank balance data for all banks from 2022-2025: - Bank Frick EUR/CHF/USD (IDs 1-3) - Olkypay EUR (ID 4) - Maerki Baumann EUR/CHF (IDs 5-6) - Revolut EUR (ID 7) - Raiffeisen CHF (ID 13) - Yapeal CHF/EUR (IDs 15-16) Also includes formatting fixes for accounting controller and service.
Summary
/accounting/balance-sheet/:iban/:yearendpoint (Admin/Compliance only)yearlyBalancesJSON field to Bank entity for opening/closing balancesTest plan