Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Create mock data generator for activities

Khuram Niaz3a65c3d7985a
diff --git a/src/actions/mock.actions.ts b/src/actions/mock.actions.ts
new file mode 100644
index 0000000..af8441e
--- /dev/null
+++ b/src/actions/mock.actions.ts
@@ -0,0 +1,145 @@
+"use server";
+import prisma from "@/lib/db";
+import { handleError } from "@/lib/utils";
+import { getCurrentUser } from "@/utils/user.utils";
+import { generateMockActivities } from "@/lib/mock.utils";
+import {
+ mockActivityTypes,
+ MOCK_DATA_IDENTIFIER,
+} from "@/lib/data/mockActivities";
+
+export const generateMockActivitiesAction = async (): Promise<any> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
+ // Check if dev mode is enabled
+ if (process.env.NODE_ENV !== "development") {
+ throw new Error(
+ "Mock data generation is only available in development mode",
+ );
+ }
+
+ // Check which activity types already exist
+ const existingTypes = await prisma.activityType.findMany({
+ where: {
+ value: {
+ in: mockActivityTypes.map((t) => t.value),
+ },
+ },
+ });
+
+ const existingValues = new Set(existingTypes.map((t) => t.value));
+
+ // Create only the activity types that don't exist
+ const typesToCreate = mockActivityTypes.filter(
+ (t) => !existingValues.has(t.value),
+ );
+
+ if (typesToCreate.length > 0) {
+ await prisma.activityType.createMany({
+ data: typesToCreate.map((t) => ({
+ label: t.label,
+ value: t.value,
+ createdBy: user.id,
+ })),
+ });
+ }
+
+ // Get all activity type IDs (both existing and newly created)
+ const activityTypes = await prisma.activityType.findMany({
+ where: {
+ value: {
+ in: mockActivityTypes.map((t) => t.value),
+ },
+ },
+ });
+
+ // Generate mock activities
+ const mockActivities = generateMockActivities(user.id, 10, 25);
+
+ // Create a map of activity type values to IDs
+ const typeMap = new Map(activityTypes.map((t) => [t.value, t.id]));
+
+ // Create activities in the database
+ const createdActivities = await Promise.all(
+ mockActivities.map((activity) => {
+ const typeValue = activity.activityType as string;
+ const typeId = typeMap.get(typeValue);
+
+ if (!typeId) {
+ throw new Error(`Activity type not found for ${typeValue}`);
+ }
+
+ return prisma.activity.create({
+ data: {
+ activityName: activity.activityName,
+ activityTypeId: typeId,
+ userId: user.id,
+ startTime: activity.startTime,
+ endTime: activity.endTime,
+ duration: activity.duration,
+ description: activity.description,
+ },
+ });
+ }),
+ );
+
+ return {
+ success: true,
+ message: `Generated ${createdActivities.length} mock activities`,
+ data: createdActivities,
+ };
+ } catch (error) {
+ const msg = "Failed to generate mock activities";
+ return handleError(error, msg);
+ }
+};
+
+export const clearMockActivitiesAction = async (): Promise<any> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
+ // Check if dev mode is enabled
+ if (process.env.NODE_ENV !== "development") {
+ throw new Error(
+ "Mock data clearing is only available in development mode",
+ );
+ }
+
+ // Find and delete only mock activities (those with [MOCK_DATA] in description)
+ const mockActivities = await prisma.activity.findMany({
+ where: {
+ userId: user.id,
+ description: {
+ contains: MOCK_DATA_IDENTIFIER,
+ },
+ },
+ });
+
+ // Delete the activities
+ const deleteResult = await prisma.activity.deleteMany({
+ where: {
+ id: {
+ in: mockActivities.map((a) => a.id),
+ },
+ },
+ });
+
+ return {
+ success: true,
+ message: `Deleted ${deleteResult.count} mock activities`,
+ deletedCount: deleteResult.count,
+ };
+ } catch (error) {
+ const msg = "Failed to clear mock activities";
+ return handleError(error, msg);
+ }
+};
diff --git a/src/app/dashboard/developer/page.tsx b/src/app/dashboard/developer/page.tsx
new file mode 100644
index 0000000..46730fa
--- /dev/null
+++ b/src/app/dashboard/developer/page.tsx
@@ -0,0 +1,17 @@
+import { Metadata } from "next";
+import DeveloperContainer from "@/components/developer/DeveloperContainer";
+
+export const metadata: Metadata = {
+ title: "Developer Options | JobSync",
+ description: "Developer tools and utilities for development mode",
+};
+
+export default function DeveloperPage() {
+ return (
+ <main className="flex flex-1 flex-col gap-4 p-4 md:gap-8 md:p-8">
+ <div className="mx-auto w-full max-w-6xl">
+ <DeveloperContainer />
+ </div>
+ </main>
+ );
+}
diff --git a/src/components/Header.tsx b/src/components/Header.tsx
index 75875d4..d14e10d 100644
--- a/src/components/Header.tsx
+++ b/src/components/Header.tsx
@@ -39,6 +39,10 @@ async function Header() {
</Link>
</SheetClose>
{SIDEBAR_LINKS.map((item) => {
+ // Only show dev-only items in development mode
+ if (item.devOnly && process.env.NODE_ENV !== "development") {
+ return null;
+ }
return (
<SheetClose asChild key={item.label}>
<Link
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 3f19f02..212197e 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -21,6 +21,10 @@ function Sidebar() {
</Link>
<TooltipProvider delayDuration={800}>
{SIDEBAR_LINKS.map((item) => {
+ // Only show dev-only items in development mode
+ if (item.devOnly && process.env.NODE_ENV !== "development") {
+ return null;
+ }
return (
<div key={item.label} className="text-white fill-color">
<NavLink
diff --git a/src/components/developer/DeveloperContainer.tsx b/src/components/developer/DeveloperContainer.tsx
new file mode 100644
index 0000000..2e609a7
--- /dev/null
+++ b/src/components/developer/DeveloperContainer.tsx
@@ -0,0 +1,153 @@
+"use client";
+import { useState } from "react";
+import { Button } from "@/components/ui/button";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+} from "@/components/ui/card";
+import { AlertCircle, CheckCircle2, Loader2 } from "lucide-react";
+import {
+ generateMockActivitiesAction,
+ clearMockActivitiesAction,
+} from "@/actions/mock.actions";
+
+export default function DeveloperContainer() {
+ const [isGenerating, setIsGenerating] = useState(false);
+ const [isClearing, setIsClearing] = useState(false);
+ const [message, setMessage] = useState<{
+ type: "success" | "error";
+ text: string;
+ } | null>(null);
+
+ const handleGenerateActivities = async () => {
+ setIsGenerating(true);
+ setMessage(null);
+
+ const result = await generateMockActivitiesAction();
+
+ if (result.success) {
+ setMessage({
+ type: "success",
+ text: result.message || "Mock activities generated successfully",
+ });
+ } else {
+ setMessage({
+ type: "error",
+ text: result.message || "Failed to generate mock activities",
+ });
+ }
+
+ setIsGenerating(false);
+ };
+
+ const handleClearActivities = async () => {
+ if (
+ !confirm(
+ "Are you sure you want to delete all mock activities? This action cannot be undone.",
+ )
+ ) {
+ return;
+ }
+
+ setIsClearing(true);
+ setMessage(null);
+
+ const result = await clearMockActivitiesAction();
+
+ if (result.success) {
+ setMessage({
+ type: "success",
+ text: result.message || "Mock activities cleared successfully",
+ });
+ } else {
+ setMessage({
+ type: "error",
+ text: result.message || "Failed to clear mock activities",
+ });
+ }
+
+ setIsClearing(false);
+ };
+
+ return (
+ <div className="space-y-6">
+ <div>
+ <h1 className="text-3xl font-bold tracking-tight">Developer Options</h1>
+ <p className="text-muted-foreground mt-2">
+ Tools for development and testing. Only available in development mode.
+ </p>
+ </div>
+
+ {message && (
+ <div
+ className={`flex items-start gap-3 rounded-lg border p-4 ${
+ message.type === "error"
+ ? "border-red-200 bg-red-50 text-red-900"
+ : "border-green-200 bg-green-50 text-green-900"
+ }`}
+ >
+ {message.type === "error" ? (
+ <AlertCircle className="h-5 w-5 flex-shrink-0 mt-0.5" />
+ ) : (
+ <CheckCircle2 className="h-5 w-5 flex-shrink-0 mt-0.5" />
+ )}
+ <div className="flex-1">
+ <p className="font-semibold">
+ {message.type === "error" ? "Error" : "Success"}
+ </p>
+ <p className="text-sm">{message.text}</p>
+ </div>
+ </div>
+ )}
+
+ <Card>
+ <CardHeader>
+ <CardTitle>Mock Data Management</CardTitle>
+ <CardDescription>
+ Generate or clear mock activities for testing
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="space-y-4">
+ <div>
+ <h3 className="font-semibold mb-2">Generate Mock Activities</h3>
+ <p className="text-sm text-muted-foreground mb-4">
+ Creates 25+ mock activities for the last 10 days with types:
+ Learning, Side Project 1, Side Project 2, Job Search, and
+ Interview Preparation. Duration is between 20-120 minutes.
+ </p>
+ <Button
+ onClick={handleGenerateActivities}
+ disabled={isGenerating || isClearing}
+ className="w-full"
+ >
+ {isGenerating && (
+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />
+ )}
+ {isGenerating ? "Generating..." : "Generate Mock Activities"}
+ </Button>
+ </div>
+
+ <div className="border-t pt-4">
+ <h3 className="font-semibold mb-2">Clear Mock Activities</h3>
+ <p className="text-sm text-muted-foreground mb-4">
+ Deletes only mock activities (marked with [MOCK_DATA] identifier).
+ Regular activities are not affected.
+ </p>
+ <Button
+ onClick={handleClearActivities}
+ disabled={isClearing || isGenerating}
+ variant="destructive"
+ className="w-full"
+ >
+ {isClearing && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
+ {isClearing ? "Clearing..." : "Clear Mock Activities"}
+ </Button>
+ </div>
+ </CardContent>
+ </Card>
+ </div>
+ );
+}
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index 5384734..9b5a602 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -5,6 +5,7 @@ import {
CalendarClock,
UserRound,
Sheet,
+ Wrench,
} from "lucide-react";
export enum APP_CONSTANTS {
@@ -44,4 +45,10 @@ export const SIDEBAR_LINKS = [
route: "/dashboard/admin",
label: "Administration",
},
+ {
+ icon: Wrench,
+ route: "/dashboard/developer",
+ label: "Developer Options",
+ devOnly: true,
+ },
];
diff --git a/src/lib/data/mockActivities.ts b/src/lib/data/mockActivities.ts
new file mode 100644
index 0000000..32188f0
--- /dev/null
+++ b/src/lib/data/mockActivities.ts
@@ -0,0 +1,35 @@
+import { Activity } from "@/models/activity.model";
+
+export const MOCK_DATA_IDENTIFIER = "[MOCK_DATA]";
+
+export interface MockActivityData extends Activity {
+ activityTypeId?: string;
+}
+
+export const mockActivityTypes = [
+ {
+ id: "mock-learning",
+ label: "Learning",
+ value: "Learning",
+ },
+ {
+ id: "mock-side-project-1",
+ label: "Side Project 1",
+ value: "Side Project 1",
+ },
+ {
+ id: "mock-side-project-2",
+ label: "Side Project 2",
+ value: "Side Project 2",
+ },
+ {
+ id: "mock-job-search",
+ label: "Job Search",
+ value: "Job Search",
+ },
+ {
+ id: "mock-interview-prep",
+ label: "Interview Preparation",
+ value: "Interview Preparation",
+ },
+];
diff --git a/src/lib/mock.utils.ts b/src/lib/mock.utils.ts
index 5ee6088..76739a5 100644
--- a/src/lib/mock.utils.ts
+++ b/src/lib/mock.utils.ts
@@ -4,13 +4,14 @@ import {
JobTitle,
JobResponse,
} from "@/models/job.model";
+import { Activity } from "@/models/activity.model";
import { MY_JOBS_DATA } from "./data/myJobsData";
import { addDays, format, subDays } from "date-fns";
export function getMockJobsList(
page: number,
jobsPerPage: number,
- filter?: string
+ filter?: string,
): Promise<{ data: JobResponse[]; total: number }> {
return new Promise((resolve) => {
// Filter data by status
@@ -68,7 +69,7 @@ export const getRandomInt = (min: number, max: number): number => {
export const getMockJobActivityData = (
daysAgo: number,
skipProbability: number = 0.3,
- formatType: string = "yyyy-MM-dd"
+ formatType: string = "yyyy-MM-dd",
): Promise<{ day: string; value: number }[]> => {
return new Promise((resolve) => {
const result: { day: string; value: number }[] = [];
@@ -100,7 +101,7 @@ export const getMockRecentJobs = (): Promise<JobResponse[]> => {
export function getMockList(
page = 1,
recordsPerPage = 10,
- type: "companies" | "jobTitles" | "locations"
+ type: "companies" | "jobTitles" | "locations",
): Promise<{ data: any[]; total: number }> {
return new Promise((resolve) => {
const result: { [key: string]: any } = {};
@@ -156,3 +157,103 @@ export function getMockList(
resolve({ data, total: data.length });
});
}
+
+const MOCK_ACTIVITY_TYPES = [
+ "Learning",
+ "Side Project 1",
+ "Side Project 2",
+ "Job Search",
+ "Interview Preparation",
+];
+
+const MOCK_ACTIVITY_TITLES: { [key: string]: string[] } = {
+ Learning: [
+ "TypeScript Advanced Concepts",
+ "React Hooks Deep Dive",
+ "Next.js Performance",
+ "Web Security Fundamentals",
+ "Database Optimization",
+ ],
+ "Side Project 1": [
+ "Build Portfolio Website",
+ "Implement New Features",
+ "Code Refactoring",
+ "Add Testing Coverage",
+ "Improve Documentation",
+ ],
+ "Side Project 2": [
+ "Mobile App Development",
+ "API Integration",
+ "UI/UX Improvements",
+ "Database Migration",
+ "Deployment Setup",
+ ],
+ "Job Search": [
+ "Research Companies",
+ "Apply to Jobs",
+ "Update Resume",
+ "Network on LinkedIn",
+ "Review Job Listings",
+ ],
+ "Interview Preparation": [
+ "Practice Coding Challenges",
+ "System Design Review",
+ "Mock Interview",
+ "Behavioral Interview Prep",
+ "Technical Questions Study",
+ ],
+};
+
+/**
+ * Generates mock activities for the last N days
+ * @param userId - User ID for the activities
+ * @param daysBack - Number of days back to generate activities (default: 10)
+ * @param totalRecords - Minimum total records to generate (default: 25)
+ * @returns Array of mock activities
+ */
+export const generateMockActivities = (
+ userId: string,
+ daysBack: number = 10,
+ totalRecords: number = 25,
+): Activity[] => {
+ const activities: Activity[] = [];
+ const endDate = new Date();
+ const startDate = subDays(endDate, daysBack);
+ let recordsGenerated = 0;
+
+ for (let i = 0; i < daysBack && recordsGenerated < totalRecords; i++) {
+ const currentDate = addDays(startDate, i);
+ const recordsPerDay = Math.ceil(
+ (totalRecords - recordsGenerated) / (daysBack - i),
+ );
+
+ for (let j = 0; j < recordsPerDay && recordsGenerated < totalRecords; j++) {
+ const activityType =
+ MOCK_ACTIVITY_TYPES[getRandomInt(0, MOCK_ACTIVITY_TYPES.length - 1)];
+ const titles = MOCK_ACTIVITY_TITLES[activityType];
+ const activityName = titles[getRandomInt(0, titles.length - 1)];
+ const duration = getRandomInt(20, 120);
+
+ const startTime = new Date(currentDate);
+ startTime.setHours(getRandomInt(6, 22));
+ startTime.setMinutes(getRandomInt(0, 59));
+
+ const endTime = new Date(startTime);
+ endTime.setMinutes(endTime.getMinutes() + duration);
+
+ activities.push({
+ activityName,
+ activityType,
+ startTime,
+ endTime,
+ duration,
+ description: `[MOCK_DATA] ${activityName}`,
+ userId,
+ });
+
+ recordsGenerated++;
+ }
+ }
+
+ return activities;
+};