My-Weekly-ToDo-List/scripts/seed-connection.ts

41 lines
1.3 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
const user = await prisma.user.findFirst();
if (!user) {
console.log('No user found to seed connection for.');
return;
}
console.log(`Seeding Calendar Connection for user: ${user.email}`);
// Clean up existing google connections
await prisma.calendarConnection.deleteMany({
where: { userId: user.id, provider: 'google' }
});
// Create mock connection with FUTURE expiry
await prisma.calendarConnection.create({
data: {
userId: user.id,
provider: 'google',
accessToken: 'mock-access-token',
refreshToken: 'mock-refresh-token',
expiresAt: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000), // 1 Year from now
calendars: [
{ id: 'primary', title: 'Primary Calendar', isPrimary: true, selected: true },
{ id: 'work', title: 'Work Calendar', isPrimary: false, selected: true },
{ id: 'holidays', title: 'Public Holidays', isPrimary: false, selected: false }
]
}
});
console.log('Seeded Mock Google Connection with 3 calendars (Valid for 1 year).');
}
main()
.catch(e => console.error(e))
.finally(async () => await prisma.$disconnect());