-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-data.js
More file actions
64 lines (54 loc) · 2.12 KB
/
check-data.js
File metadata and controls
64 lines (54 loc) · 2.12 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const sqlite3 = require('sqlite3').verbose();
const path = require('path');
const dbPath = path.join(__dirname, 'financial.db');
const db = new sqlite3.Database(dbPath);
console.log('Checking database data...\n');
// Check users
db.all('SELECT id, username FROM users', [], (err, users) => {
if (err) {
console.error('Error fetching users:', err);
return;
}
console.log('👤 Users:', users.length);
users.forEach(u => console.log(` - ${u.username} (${u.id})`));
if (users.length === 0) {
console.log('\n⚠️ No users found! You need to register first.');
db.close();
return;
}
const userId = users[0].id;
console.log(`\n📊 Checking data for user: ${users[0].username}\n`);
// Check accounts
db.all('SELECT * FROM accounts WHERE user_id = ?', [userId], (err, accounts) => {
console.log('💰 Accounts:', accounts ? accounts.length : 0);
if (accounts && accounts.length > 0) {
accounts.forEach(a => console.log(` - ${a.name} (${a.type}): $${a.balance}`));
}
});
// Check income sources
db.all('SELECT * FROM income_sources WHERE user_id = ?', [userId], (err, income) => {
console.log('\n💵 Income Sources:', income ? income.length : 0);
if (income && income.length > 0) {
income.forEach(i => console.log(` - ${i.source_name} (${i.source_type}): $${i.amount} ${i.frequency}`));
}
});
// Check retirement
db.all('SELECT * FROM retirement_accounts WHERE user_id = ?', [userId], (err, retirement) => {
console.log('\n🏦 Retirement Accounts:', retirement ? retirement.length : 0);
if (retirement && retirement.length > 0) {
retirement.forEach(r => console.log(` - ${r.name} (${r.type}): $${r.balance}`));
}
});
// Check assets
db.all('SELECT * FROM assets WHERE user_id = ?', [userId], (err, assets) => {
console.log('\n🏠 Assets:', assets ? assets.length : 0);
if (assets && assets.length > 0) {
assets.forEach(a => console.log(` - ${a.name} (${a.type}): $${a.value}`));
}
// Close after last query
setTimeout(() => {
console.log('\n✅ Database check complete!');
db.close();
}, 100);
});
});