-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_transaction.js
More file actions
35 lines (26 loc) · 1011 Bytes
/
add_transaction.js
File metadata and controls
35 lines (26 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const { Pool } = require('pg');
// Create a new instance of the Pool class
const pool = new Pool({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_DB,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT,
});
async function insertIncomeTransaction(memberId, transactionDate, description, amount) {
try {
const query = `
INSERT INTO income_transactions (member_id, transaction_date, description, amount)
VALUES ($1, $2, $3, $4)`;
const values = [memberId, transactionDate, description, amount];
await pool.query(query, values);
console.log('Income transaction inserted successfully');
} catch (error) {
console.error('Error inserting income transaction:', error);
}
}
// Example usage of insertIncomeTransaction
insertIncomeTransaction(1, '2023-05-10', 'Freelance Work', 500.0);