hp-prod-tracker/scripts/seed-dates.ts
Leivur Djurhuus 1bbc9fd195 feat(calendar): implement calendar view with event filtering and detail display
- Added CalendarDayDetail component for displaying detailed event information for a selected day.
- Created CalendarEventPill component to represent individual events in a compact format.
- Introduced CalendarFilters component to filter events by project, stage type, and status.
- Developed CalendarGrid component to render the calendar layout and manage event interactions.
- Implemented CalendarView component to manage the overall calendar state and navigation.
- Added useCalendar hook to fetch calendar events based on specified filters.
- Created calendar-service to handle fetching events from the database with filtering capabilities.
- Updated data model to include necessary fields for calendar events and filters.
- Added system prompt and tools for AI assistant to manage calendar-related tasks.
2026-03-12 21:20:11 -05:00

77 lines
2.3 KiB
TypeScript

import "dotenv/config";
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "../src/generated/prisma/client";
import { addDays } from "date-fns";
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL! });
const prisma = new PrismaClient({ adapter });
async function main() {
console.log("Seeding stage dates for ALL stages (calendar view)...");
// Get all stages grouped by deliverable so we can create realistic timelines
const stages = await prisma.deliverableStage.findMany({
include: {
template: { select: { order: true, estimatedDays: true } },
},
orderBy: [
{ deliverableId: "asc" },
{ template: { order: "asc" } },
],
});
if (stages.length === 0) {
console.log("No stages found to update.");
return;
}
const today = new Date();
let currentDeliverableId = "";
let deliverableStart = today;
let previousEnd = today;
let updated = 0;
for (const stage of stages) {
// When we hit a new deliverable, pick a random project start date
if (stage.deliverableId !== currentDeliverableId) {
currentDeliverableId = stage.deliverableId;
// Spread project starts from 60 days ago to 30 days in the future
const startOffset = Math.floor(Math.random() * 90) - 60;
deliverableStart = addDays(today, startOffset);
previousEnd = deliverableStart;
}
// Each stage starts when the previous one ends (with 0-2 day gap)
const gap = Math.floor(Math.random() * 3);
const startDate = addDays(previousEnd, gap);
// Duration based on template estimatedDays or a reasonable default
const baseDays = stage.template.estimatedDays || (5 + Math.floor(Math.random() * 10));
const variance = Math.floor(Math.random() * 5) - 2;
const durationDays = Math.max(2, baseDays + variance);
const dueDate = addDays(startDate, durationDays);
previousEnd = dueDate;
await prisma.deliverableStage.update({
where: { id: stage.id },
data: { startDate, dueDate },
});
updated++;
if (updated % 100 === 0) {
console.log(`Updated ${updated} stages...`);
}
}
console.log(`Successfully updated ${updated} stages with dates.`);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});