My-Weekly-ToDo-List/fill-ext-events.js
mARTin 3e19ebe85a fix: security hardening, Prisma singleton, tsconfig cleanup
- tsconfig: remove deprecated downlevelIteration (es2017 has native iterators),
  change moduleResolution from node to bundler
- auth: set allowDangerousEmailAccountLinking=false on all OAuth providers,
  restrict debug mode to development only
- prisma: replace new PrismaClient() with singleton import in 10 API routes
  to prevent connection pool exhaustion
- goal API: validate user-supplied quote URLs to block SSRF (private IPs,
  non-http(s) schemes)
- email: guard DEV verification/reset link console.logs behind NODE_ENV check

v1.98.0
2026-04-20 19:52:47 +02:00

119 lines
3.6 KiB
JavaScript

const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
const eventNames = [
"Dentist Appointment",
"Coffee with Sarah",
"Quarterly Review",
"Car Inspection",
"Therapy Session",
"Lunch with Bob"
];
const allDayEvents = [
"Spring Festival",
"Bank Holiday",
"Company Offsite",
"Project Deadline"
];
function getWeekStart(date) {
const d = new Date(date);
d.setUTCHours(0, 0, 0, 0);
const day = d.getUTCDay();
const diff = d.getUTCDate() - day + (day === 0 ? -6 : 1); // Monday is 1
d.setUTCDate(diff);
return d;
}
async function main() {
const user = await prisma.user.findUnique({
where: { email: 'kugelblitz@gmx.de' }
});
if (!user) return;
// 1. Ensure a dummy calendar connection exists
let connection = await prisma.calendarConnection.findFirst({
where: { userId: user.id, provider: 'google' }
});
if (!connection) {
connection = await prisma.calendarConnection.create({
data: {
userId: user.id,
provider: 'google',
accessToken: 'dummy-token',
calendars: JSON.stringify([{ id: 'primary', name: 'My Calendar', color: '#4285F4' }])
}
});
}
// 2. Clear old generated mock events
const mockTitles = [...eventNames, ...allDayEvents];
await prisma.cachedCalendarEvent.deleteMany({
where: {
connectionId: connection.id,
title: { in: mockTitles }
}
});
const startDate = new Date('2026-03-16T00:00:00Z');
const endDate = new Date('2026-04-12T00:00:00Z');
let idCounter = 1;
for (let d = new Date(startDate); d <= endDate; d.setUTCDate(d.getUTCDate() + 1)) {
console.log('Processing date:', d.toISOString());
const dateStr = d.toISOString().split('T')[0];
const weekStart = getWeekStart(d);
if (Math.random() > 0.6) {
// Add All-Day Event
await prisma.cachedCalendarEvent.create({
data: {
userId: user.id,
externalId: `mock-allday-${idCounter++}`,
connectionId: connection.id,
provider: 'google',
calendarId: 'primary',
calendarTitle: 'My Calendar',
calendarColor: '#EA4335',
title: allDayEvents[Math.floor(Math.random() * allDayEvents.length)],
startDate: dateStr,
endDate: dateStr,
weekStart: weekStart
}
});
}
if (Math.random() > 0.5) {
// Add Timed Event
const hour = Math.floor(Math.random() * 6) + 10; // 10 to 15
const startDt = new Date(d);
startDt.setUTCHours(hour, 0, 0, 0);
const endDt = new Date(d);
endDt.setUTCHours(hour + 1, 0, 0, 0);
await prisma.cachedCalendarEvent.create({
data: {
userId: user.id,
externalId: `mock-timed-${idCounter++}`,
connectionId: connection.id,
provider: 'google',
calendarId: 'primary',
calendarTitle: 'My Calendar',
calendarColor: '#4285F4',
title: eventNames[Math.floor(Math.random() * eventNames.length)],
startDateTime: startDt,
endDateTime: endDt,
weekStart: weekStart
}
});
}
}
console.log("Successfully added simulated external calendar events!");
}
main().catch(console.error).finally(() => prisma.$disconnect());