final touches for beta skymoney (at least i think)
This commit is contained in:
133
api/create-multi-overdue-user.cjs
Normal file
133
api/create-multi-overdue-user.cjs
Normal file
@@ -0,0 +1,133 @@
|
||||
// Create test user with MULTIPLE overdue bills
|
||||
const argon2 = require('argon2');
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
|
||||
async function main() {
|
||||
const prisma = new PrismaClient({
|
||||
datasourceUrl: 'postgres://app:app@localhost:5432/skymoney'
|
||||
});
|
||||
|
||||
try {
|
||||
const email = 'test@skymoney.com';
|
||||
const password = 'password123';
|
||||
|
||||
// Clean up existing user
|
||||
await prisma.user.deleteMany({ where: { email } });
|
||||
console.log('✓ Cleaned up old test user');
|
||||
|
||||
// Create user
|
||||
const passwordHash = await argon2.hash(password);
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
email,
|
||||
passwordHash,
|
||||
displayName: 'Test User',
|
||||
incomeFrequency: 'biweekly',
|
||||
totalBudgetCents: BigInt(300000), // $3000
|
||||
timezone: 'America/New_York',
|
||||
},
|
||||
});
|
||||
console.log('✓ Created user:', user.id);
|
||||
|
||||
// Create income source
|
||||
await prisma.incomeEvent.create({
|
||||
data: {
|
||||
id: '00000000-0000-0000-0000-000000000001',
|
||||
userId: user.id,
|
||||
postedAt: new Date(),
|
||||
amountCents: BigInt(300000),
|
||||
note: 'Initial budget',
|
||||
},
|
||||
});
|
||||
console.log('✓ Created income: $3000');
|
||||
|
||||
// Create categories
|
||||
await prisma.variableCategory.createMany({
|
||||
data: [
|
||||
{ userId: user.id, name: 'Groceries', percent: 50, priority: 1, balanceCents: BigInt(150000) },
|
||||
{ userId: user.id, name: 'Other', percent: 50, priority: 2, balanceCents: BigInt(150000) },
|
||||
],
|
||||
});
|
||||
console.log('✓ Created categories (100% total)');
|
||||
|
||||
const today = new Date();
|
||||
today.setHours(6, 0, 0, 0); // 6am today
|
||||
|
||||
const threeDaysAgo = new Date(today);
|
||||
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3);
|
||||
|
||||
const oneWeekAgo = new Date(today);
|
||||
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
|
||||
|
||||
// Create THREE overdue bills with different dates
|
||||
// 1. Rent - $1500, $1000 funded, $500 overdue (oldest - 7 days ago)
|
||||
await prisma.fixedPlan.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Rent',
|
||||
cycleStart: oneWeekAgo,
|
||||
dueOn: today,
|
||||
totalCents: BigInt(150000), // $1500
|
||||
fundedCents: BigInt(100000), // $1000 funded
|
||||
currentFundedCents: BigInt(100000),
|
||||
priority: 1,
|
||||
isOverdue: true,
|
||||
overdueAmount: BigInt(50000), // $500 overdue
|
||||
overdueSince: oneWeekAgo,
|
||||
},
|
||||
});
|
||||
|
||||
// 2. Utilities - $200, $100 funded, $100 overdue (3 days ago)
|
||||
await prisma.fixedPlan.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Utilities',
|
||||
cycleStart: threeDaysAgo,
|
||||
dueOn: today,
|
||||
totalCents: BigInt(20000), // $200
|
||||
fundedCents: BigInt(10000), // $100 funded
|
||||
currentFundedCents: BigInt(10000),
|
||||
priority: 2,
|
||||
isOverdue: true,
|
||||
overdueAmount: BigInt(10000), // $100 overdue
|
||||
overdueSince: threeDaysAgo,
|
||||
},
|
||||
});
|
||||
|
||||
// 3. Phone - $100, $50 funded, $50 overdue (today)
|
||||
await prisma.fixedPlan.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Phone',
|
||||
cycleStart: today,
|
||||
dueOn: today,
|
||||
totalCents: BigInt(10000), // $100
|
||||
fundedCents: BigInt(5000), // $50 funded
|
||||
currentFundedCents: BigInt(5000),
|
||||
priority: 3,
|
||||
isOverdue: true,
|
||||
overdueAmount: BigInt(5000), // $50 overdue
|
||||
overdueSince: today,
|
||||
},
|
||||
});
|
||||
|
||||
console.log('✓ Created 3 overdue plans:');
|
||||
console.log(' - Rent: $1500 total, $1000 funded, $500 overdue (7 days ago)');
|
||||
console.log(' - Utilities: $200 total, $100 funded, $100 overdue (3 days ago)');
|
||||
console.log(' - Phone: $100 total, $50 funded, $50 overdue (today)');
|
||||
console.log('\n✅ Test user ready!');
|
||||
console.log(' Email: test@skymoney.com');
|
||||
console.log(' Password: password123');
|
||||
console.log(' Total overdue: $650');
|
||||
console.log('\n💡 Post $1000 income to see priority order:');
|
||||
console.log(' 1st: Rent $500 (oldest)');
|
||||
console.log(' 2nd: Utilities $100');
|
||||
console.log(' 3rd: Phone $50');
|
||||
console.log(' Remaining $350 → normal allocation');
|
||||
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user