mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 22:50:12 -08:00
This commit resolves an issue where the Update button in the transaction form would remain disabled when attempting to edit a transaction. The problem was in how the transactionStore was managing state updates during transaction editing. Key changes: - Enhanced startEditingTransaction function in transactionStore.ts to ensure proper reactivity - Added clean copy creation of transaction objects to avoid reference issues - Implemented a state update cycle with null value first to force reactivity - Added a small timeout to ensure state changes are properly detected by components The Transaction form now correctly enables the Update button when in edit mode, regardless of account selection state.
88 lines
2.1 KiB
JavaScript
88 lines
2.1 KiB
JavaScript
import { PrismaClient } from '@prisma/client';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('Starting database seeding...');
|
|
|
|
// Clear existing data
|
|
await prisma.transaction.deleteMany({});
|
|
await prisma.account.deleteMany({});
|
|
|
|
console.log('Cleared existing data');
|
|
|
|
// Create accounts
|
|
const checkingAccount = await prisma.account.create({
|
|
data: {
|
|
bankName: 'First National Bank',
|
|
accountNumber: '432198',
|
|
name: 'Checking Account',
|
|
type: 'CHECKING',
|
|
balance: 2500.0,
|
|
notes: 'Primary checking account',
|
|
},
|
|
});
|
|
|
|
const savingsAccount = await prisma.account.create({
|
|
data: {
|
|
bankName: 'First National Bank',
|
|
accountNumber: '876543',
|
|
name: 'Savings Account',
|
|
type: 'SAVINGS',
|
|
balance: 10000.0,
|
|
notes: 'Emergency fund',
|
|
},
|
|
});
|
|
|
|
console.log('Created accounts:', {
|
|
checkingAccount: checkingAccount.id,
|
|
savingsAccount: savingsAccount.id,
|
|
});
|
|
|
|
// Create transactions
|
|
const transactions = await Promise.all([
|
|
prisma.transaction.create({
|
|
data: {
|
|
accountId: checkingAccount.id,
|
|
date: new Date('2025-04-20'),
|
|
description: 'Grocery Store',
|
|
amount: -75.5,
|
|
category: 'Groceries',
|
|
type: 'WITHDRAWAL',
|
|
},
|
|
}),
|
|
prisma.transaction.create({
|
|
data: {
|
|
accountId: checkingAccount.id,
|
|
date: new Date('2025-04-21'),
|
|
description: 'Salary Deposit',
|
|
amount: 3000.0,
|
|
category: 'Income',
|
|
type: 'DEPOSIT',
|
|
},
|
|
}),
|
|
prisma.transaction.create({
|
|
data: {
|
|
accountId: savingsAccount.id,
|
|
date: new Date('2025-04-22'),
|
|
description: 'Transfer to Savings',
|
|
amount: 500.0,
|
|
category: 'Transfer',
|
|
type: 'TRANSFER',
|
|
},
|
|
}),
|
|
]);
|
|
|
|
console.log(`Created ${transactions.length} transactions`);
|
|
console.log('Seeding completed successfully!');
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error('Error during seeding:', e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|