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.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
feat(job): restructure job actions into separate modules for better organization and maintainability refactor(activity, profile): move requireUser to shared module for reuse across action directories
Khuram Niaz3f067818a5d7
diff --git a/src/actions/activity/activities.ts b/src/actions/activity/activities.tsindex 3334eb6..c9036fc 100644--- a/src/actions/activity/activities.ts+++ b/src/actions/activity/activities.ts@@ -4,7 +4,19 @@ import { handleError } from "@/lib/utils";import { APP_CONSTANTS } from "@/lib/constants";import { Activity } from "@/models/activity.model";import { revalidatePath } from "next/cache";-import { ACTIVITY_LIST_SELECT, requireUser } from "./shared";+import { requireUser } from "./shared";++// Completed activities carry duration but no break state+const ACTIVITY_LIST_SELECT = {+ id: true,+ activityName: true,+ startTime: true,+ endTime: true,+ duration: true,+ description: true,+ createdAt: true,+ activityType: true,+};export const getActivitiesList = async (page: number = 1,diff --git a/src/actions/activity/shared.ts b/src/actions/activity/shared.tsindex abaa439..4f952f1 100644--- a/src/actions/activity/shared.ts+++ b/src/actions/activity/shared.ts@@ -1,16 +1,11 @@import { APP_CONSTANTS } from "@/lib/constants";-import { getCurrentUser } from "@/utils/user.utils";// Not a "use server" module: it exports selects and sync helpers, so it stays// internal to src/actions/activity/ and is never imported by a client component.-export const requireUser = async () => {- const user = await getCurrentUser();- if (!user) {- throw new Error("Not authenticated");- }- return user;-};+// Re-exported so the existing "./shared" import in each activity module keeps+// working now that requireUser is shared with the other action directories.+export { requireUser } from "../shared";// One shape for every action that returns the running activity, so the client// can never receive a copy missing its break state.@@ -27,18 +22,6 @@ export const RUNNING_ACTIVITY_SELECT = {breakPlannedMins: true,};-// Completed activities carry duration but no break state-export const ACTIVITY_LIST_SELECT = {- id: true,- activityName: true,- startTime: true,- endTime: true,- duration: true,- description: true,- createdAt: true,- activityType: true,-};-export const clampBreakMinutes = (minutes: number) =>Math.min(Math.max(minutes, APP_CONSTANTS.ACTIVITY_BREAK_MIN_MINUTES),diff --git a/src/actions/job.actions.ts b/src/actions/job.actions.tsindex 2df8630..d47eb3f 100644--- a/src/actions/job.actions.ts+++ b/src/actions/job.actions.ts@@ -1,543 +1,20 @@-"use server";-import prisma from "@/lib/db";-import { handleError } from "@/lib/utils";-import { canonicalizeEntityValue } from "@/lib/jobs/canonicalize";-import { AddJobFormSchema } from "@/models/addJobForm.schema";-import { JOB_TYPES, JobStatus } from "@/models/job.model";-import { getCurrentUser } from "@/utils/user.utils";-import { APP_CONSTANTS } from "@/lib/constants";-import { revalidatePath } from "next/cache";-import { z } from "zod";--export const getStatusList = async (): Promise<any | undefined> => {- try {- const statuses = await prisma.jobStatus.findMany();- return statuses;- } catch (error) {- const msg = "Failed to fetch status list. ";- return handleError(error, msg);- }-};--export const getJobSourceList = async (): Promise<any | undefined> => {- try {- const user = await getCurrentUser();- if (!user) {- throw new Error("Not authenticated");- }- const list = await prisma.jobSource.findMany({- where: {- createdBy: user.id,- },- });- return list;- } catch (error) {- const msg = "Failed to fetch job source list. ";- return handleError(error, msg);- }-};--export const getJobsList = async (- page: number = 1,- limit: number = APP_CONSTANTS.RECORDS_PER_PAGE,- filter?: string,- search?: string,- companyValue?: string,- appliedOnly?: boolean,- titleValue?: string,- locationValue?: string,- sourceValue?: string,-): Promise<any | undefined> => {- try {- const user = await getCurrentUser();-- if (!user) {- throw new Error("Not authenticated");- }- const skip = (page - 1) * limit;-- const filterBy = filter- ? filter === Object.keys(JOB_TYPES)[1]- ? {- jobType: filter,- }- : filter === "accepted" || filter === "dismissed"- ? {- discoveryStatus: filter,- }- : {- Status: {- value: filter,- },- }- : {};-- const whereClause: any = {- userId: user.id,- ...filterBy,- };-- // Dismissed discovered jobs are kept only for dedup and shouldn't- // clutter the tracked jobs list unless explicitly filtered for.- if (filter !== "dismissed") {- whereClause.AND = [- {- OR: [{ discoveryStatus: null }, { discoveryStatus: { not: "dismissed" } }],- },- ];- }-- if (companyValue) {- whereClause.Company = { value: companyValue };- }-- if (titleValue) {- whereClause.JobTitle = { value: titleValue };- }-- if (locationValue) {- whereClause.Location = { value: locationValue };- }-- if (sourceValue) {- whereClause.JobSource = { value: sourceValue };- }-- if (appliedOnly) {- whereClause.applied = true;- }-- if (search) {- const searchConditions: Record<string, any>[] = [];- if (!titleValue) {- searchConditions.push({ JobTitle: { label: { contains: search } } });- }- if (!companyValue) {- searchConditions.push({ Company: { label: { contains: search } } });- }- if (!locationValue) {- searchConditions.push({ Location: { label: { contains: search } } });- }- if (!sourceValue) {- searchConditions.push({ JobSource: { label: { contains: search } } });- }- searchConditions.push(- { description: { contains: search } },- );- whereClause.OR = searchConditions;- }-- const [data, total] = await Promise.all([- prisma.job.findMany({- where: whereClause,- skip,- take: limit,- select: {- id: true,- JobSource: true,- JobTitle: true,- jobType: true,- workplaceType: true,- Company: true,- Status: true,- Location: true,- dueDate: true,- appliedDate: true,- description: false,- Resume: true,- CoverLetter: true,- matchScore: true,- discoveryStatus: true,- _count: { select: { Notes: true } },- },- orderBy: {- createdAt: "desc",- // appliedDate: "desc",- },- }),- prisma.job.count({- where: whereClause,- }),- ]);- return { success: true, data, total };- } catch (error) {- const msg = "Failed to fetch jobs list. ";- return handleError(error, msg);- }-};--export async function* getJobsIterator(filter?: string, pageSize = 200) {- const user = await getCurrentUser();- if (!user) {- throw new Error("Not authenticated");- }- let page = 1;- let fetchedCount = 0;-- while (true) {- const skip = (page - 1) * pageSize;- const filterBy = filter- ? filter === Object.keys(JOB_TYPES)[1]- ? { status: filter }- : { type: filter }- : {};-- const chunk = await prisma.job.findMany({- where: {- userId: user.id,- ...filterBy,- },- select: {- id: true,- createdAt: true,- JobSource: true,- JobTitle: true,- jobType: true,- workplaceType: true,- Company: true,- Status: true,- Location: true,- dueDate: true,- applied: true,- appliedDate: true,- },- skip,- take: pageSize,- orderBy: { createdAt: "desc" },- });-- if (!chunk.length) {- break;- }-- yield chunk;- fetchedCount += chunk.length;- page++;- }-}--export const getJobDetails = async (- jobId: string,-): Promise<any | undefined> => {- try {- if (!jobId) {- throw new Error("Please provide job id");- }- const user = await getCurrentUser();-- if (!user) {- throw new Error("Not authenticated");- }-- const job = await prisma.job.findUnique({- where: {- id: jobId,- userId: user.id,- },- include: {- JobSource: true,- JobTitle: true,- Company: true,- Status: true,- Location: true,- Resume: {- include: {- File: true,- },- },- CoverLetter: true,- tags: true,- },- });- return { job, success: true };- } catch (error) {- const msg = "Failed to fetch job details. ";- return handleError(error, msg);- }-};--export const createLocation = async (- label: string,-): Promise<any | undefined> => {- try {- const user = await getCurrentUser();-- if (!user) {- throw new Error("Not authenticated");- }-- const value = canonicalizeEntityValue(label.trim());-- if (!value) {- throw new Error("Please provide location name");- }-- const existing = await prisma.location.findFirst({- where: { value, createdBy: user.id },- });- if (existing) {- return { data: existing, success: true };- }-- const location = await prisma.location.create({- data: { label, value, createdBy: user.id },- });-- return { data: location, success: true };- } catch (error) {- const msg = "Failed to create job location. ";- return handleError(error, msg);- }-};--export const createJobSource = async (- label: string,-): Promise<any | undefined> => {- try {- const user = await getCurrentUser();-- if (!user) {- throw new Error("Not authenticated");- }-- const value = canonicalizeEntityValue(label.trim());-- if (!value) {- throw new Error("Please provide job source name");- }-- const existing = await prisma.jobSource.findFirst({- where: { value, createdBy: user.id },- });- if (existing) {- return { data: existing, success: true };- }-- const jobSource = await prisma.jobSource.create({- data: { label, value, createdBy: user.id },- });-- return { data: jobSource, success: true };- } catch (error) {- const msg = "Failed to create job source. ";- return handleError(error, msg);- }-};--import { createJobRecord } from "@/lib/jobs/createJobRecord";--export const addJob = async (- data: z.infer<typeof AddJobFormSchema>,-): Promise<any | undefined> => {- try {- const user = await getCurrentUser();-- if (!user) {- throw new Error("Not authenticated");- }-- const {- title,- company,- location,- type,- workplaceType,- status,- source,- salaryRange,- dueDate,- dateApplied,- jobDescription,- jobUrl,- applied,- resume,- coverLetter,- tags,- } = data;-- const job = await createJobRecord({- jobTitleId: title,- companyId: company,- locationId: location,- statusId: status,- jobSourceId: source,- salaryRange,- dueDate,- appliedDate: dateApplied,- description: jobDescription,- jobType: type,- workplaceType,- userId: user.id,- jobUrl,- applied,- resumeId: resume,- coverLetterId: coverLetter,- tagIds: tags ?? [],- });- revalidatePath("/dashboard");- return { success: true, data: job };- } catch (error) {- const msg = "Failed to create job. ";- return handleError(error, msg);- }-};--export const updateJob = async (- data: z.infer<typeof AddJobFormSchema>,-): Promise<any | undefined> => {- try {- const user = await getCurrentUser();-- if (!user) {- throw new Error("Not authenticated");- }- if (!data.id) {- throw new Error("Job id is required");- }-- const {- id,- title,- company,- location,- type,- workplaceType,- status,- source,- salaryRange,- dueDate,- dateApplied,- jobDescription,- jobUrl,- applied,- resume,- coverLetter,- tags,- } = data;-- const tagIds = tags ?? [];-- const job = await prisma.job.update({- where: {- id,- userId: user.id,- },- data: {- jobTitleId: title,- companyId: company,- locationId: location,- statusId: status,- jobSourceId: source,- salaryRange: salaryRange,- createdAt: new Date(),- dueDate: dueDate,- appliedDate: dateApplied,- description: jobDescription,- jobType: type,- workplaceType,- jobUrl,- applied,- resumeId: resume,- coverLetterId: coverLetter,- tags: { set: tagIds.map((id) => ({ id })) },- },- });- revalidatePath("/dashboard");- return { success: true, data: job };- } catch (error) {- const msg = "Failed to update job. ";- return handleError(error, msg);- }-};--export const updateJobStatus = async (- jobId: string,- status: JobStatus,-): Promise<any | undefined> => {- try {- const user = await getCurrentUser();-- if (!user) {- throw new Error("Not authenticated");- }- const dataToUpdate = () => {- switch (status.value) {- case "applied":- return {- statusId: status.id,- applied: true,- appliedDate: new Date(),- };- case "interview":- return {- statusId: status.id,- applied: true,- };- default:- return {- statusId: status.id,- };- }- };-- const job = await prisma.job.update({- where: {- id: jobId,- userId: user.id,- },- data: dataToUpdate(),- });- revalidatePath("/dashboard");- return { job, success: true };- } catch (error) {- const msg = "Failed to update job status.";- return handleError(error, msg);- }-};--export const saveJobMatchResult = async (- jobId: string,- matchScore: number,- matchData: string,-): Promise<any | undefined> => {- try {- const user = await getCurrentUser();- if (!user) {- throw new Error("Not authenticated");- }-- await prisma.job.update({- where: { id: jobId, userId: user.id },- data: { matchScore, matchData },- });-- return { success: true };- } catch (error) {- const msg = "Failed to save match result.";- return handleError(error, msg);- }-};--export const deleteJobById = async (- jobId: string,-): Promise<any | undefined> => {- try {- const user = await getCurrentUser();-- if (!user) {- throw new Error("Not authenticated");- }-- const res = await prisma.job.delete({- where: {- id: jobId,- userId: user.id,- },- });- revalidatePath("/dashboard");- return { res, success: true };- } catch (error) {- const msg = "Failed to delete job.";- return handleError(error, msg);- }-};+// Barrel for the job server actions, split into src/actions/job/.+// Each module below carries its own "use server"; this file only re-exports so+// the long-standing "@/actions/job.actions" import path keeps working.++export {+ getJobsList,+ getJobsIterator,+ getJobDetails,+} from "./job/queries";++export { addJob, updateJob, deleteJobById } from "./job/mutations";++export { updateJobStatus, saveJobMatchResult } from "./job/status";++export {+ getStatusList,+ getJobSourceList,+ createLocation,+ createJobSource,+} from "./job/references";diff --git a/src/actions/job/mutations.ts b/src/actions/job/mutations.tsnew file mode 100644index 0000000..00d7d26--- /dev/null+++ b/src/actions/job/mutations.ts@@ -0,0 +1,144 @@+"use server";+import prisma from "@/lib/db";+import { handleError } from "@/lib/utils";+import { createJobRecord } from "@/lib/jobs/createJobRecord";+import { AddJobFormSchema } from "@/models/addJobForm.schema";+import { revalidatePath } from "next/cache";+import { z } from "zod";+import { requireUser } from "../shared";++export const addJob = async (+ data: z.infer<typeof AddJobFormSchema>,+): Promise<any | undefined> => {+ try {+ const user = await requireUser();++ const {+ title,+ company,+ location,+ type,+ workplaceType,+ status,+ source,+ salaryRange,+ dueDate,+ dateApplied,+ jobDescription,+ jobUrl,+ applied,+ resume,+ coverLetter,+ tags,+ } = data;++ const job = await createJobRecord({+ jobTitleId: title,+ companyId: company,+ locationId: location,+ statusId: status,+ jobSourceId: source,+ salaryRange,+ dueDate,+ appliedDate: dateApplied,+ description: jobDescription,+ jobType: type,+ workplaceType,+ userId: user.id,+ jobUrl,+ applied,+ resumeId: resume,+ coverLetterId: coverLetter,+ tagIds: tags ?? [],+ });+ revalidatePath("/dashboard");+ return { success: true, data: job };+ } catch (error) {+ const msg = "Failed to create job. ";+ return handleError(error, msg);+ }+};++export const updateJob = async (+ data: z.infer<typeof AddJobFormSchema>,+): Promise<any | undefined> => {+ try {+ const user = await requireUser();+ if (!data.id) {+ throw new Error("Job id is required");+ }++ const {+ id,+ title,+ company,+ location,+ type,+ workplaceType,+ status,+ source,+ salaryRange,+ dueDate,+ dateApplied,+ jobDescription,+ jobUrl,+ applied,+ resume,+ coverLetter,+ tags,+ } = data;++ const tagIds = tags ?? [];++ const job = await prisma.job.update({+ where: {+ id,+ userId: user.id,+ },+ data: {+ jobTitleId: title,+ companyId: company,+ locationId: location,+ statusId: status,+ jobSourceId: source,+ salaryRange: salaryRange,+ createdAt: new Date(),+ dueDate: dueDate,+ appliedDate: dateApplied,+ description: jobDescription,+ jobType: type,+ workplaceType,+ jobUrl,+ applied,+ resumeId: resume,+ coverLetterId: coverLetter,+ tags: { set: tagIds.map((id) => ({ id })) },+ },+ });+ revalidatePath("/dashboard");+ return { success: true, data: job };+ } catch (error) {+ const msg = "Failed to update job. ";+ return handleError(error, msg);+ }+};++export const deleteJobById = async (+ jobId: string,+): Promise<any | undefined> => {+ try {+ const user = await requireUser();++ const res = await prisma.job.delete({+ where: {+ id: jobId,+ userId: user.id,+ },+ });+ revalidatePath("/dashboard");+ return { res, success: true };+ } catch (error) {+ const msg = "Failed to delete job.";+ return handleError(error, msg);+ }+};diff --git a/src/actions/job/queries.ts b/src/actions/job/queries.tsnew file mode 100644index 0000000..8a50801--- /dev/null+++ b/src/actions/job/queries.ts@@ -0,0 +1,256 @@+"use server";+import prisma from "@/lib/db";+import { handleError } from "@/lib/utils";+import { JOB_TYPES } from "@/models/job.model";+import { APP_CONSTANTS } from "@/lib/constants";+import { requireUser } from "../shared";++const JOB_LIST_SELECT = {+ id: true,+ JobSource: true,+ JobTitle: true,+ jobType: true,+ workplaceType: true,+ Company: true,+ Status: true,+ Location: true,+ dueDate: true,+ appliedDate: true,+ description: false,+ Resume: true,+ CoverLetter: true,+ matchScore: true,+ discoveryStatus: true,+ _count: { select: { Notes: true } },+};++const JOB_EXPORT_SELECT = {+ id: true,+ createdAt: true,+ JobSource: true,+ JobTitle: true,+ jobType: true,+ workplaceType: true,+ Company: true,+ Status: true,+ Location: true,+ dueDate: true,+ applied: true,+ appliedDate: true,+};++const JOB_DETAILS_INCLUDE = {+ JobSource: true,+ JobTitle: true,+ Company: true,+ Status: true,+ Location: true,+ Resume: {+ include: {+ File: true,+ },+ },+ CoverLetter: true,+ tags: true,+};++type JobsListFilters = {+ filter?: string;+ search?: string;+ companyValue?: string;+ appliedOnly?: boolean;+ titleValue?: string;+ locationValue?: string;+ sourceValue?: string;+};++const buildJobsWhereClause = (userId: string, filters: JobsListFilters) => {+ const {+ filter,+ search,+ companyValue,+ appliedOnly,+ titleValue,+ locationValue,+ sourceValue,+ } = filters;++ const filterBy = filter+ ? filter === Object.keys(JOB_TYPES)[1]+ ? {+ jobType: filter,+ }+ : filter === "accepted" || filter === "dismissed"+ ? {+ discoveryStatus: filter,+ }+ : {+ Status: {+ value: filter,+ },+ }+ : {};++ const whereClause: any = {+ userId,+ ...filterBy,+ };++ // Dismissed discovered jobs are kept only for dedup and shouldn't+ // clutter the tracked jobs list unless explicitly filtered for.+ if (filter !== "dismissed") {+ whereClause.AND = [+ {+ OR: [{ discoveryStatus: null }, { discoveryStatus: { not: "dismissed" } }],+ },+ ];+ }++ if (companyValue) {+ whereClause.Company = { value: companyValue };+ }++ if (titleValue) {+ whereClause.JobTitle = { value: titleValue };+ }++ if (locationValue) {+ whereClause.Location = { value: locationValue };+ }++ if (sourceValue) {+ whereClause.JobSource = { value: sourceValue };+ }++ if (appliedOnly) {+ whereClause.applied = true;+ }++ // An explicit facet filter already pins that field, so searching it too+ // would widen the result set back out via OR.+ if (search) {+ const searchConditions: Record<string, any>[] = [];+ if (!titleValue) {+ searchConditions.push({ JobTitle: { label: { contains: search } } });+ }+ if (!companyValue) {+ searchConditions.push({ Company: { label: { contains: search } } });+ }+ if (!locationValue) {+ searchConditions.push({ Location: { label: { contains: search } } });+ }+ if (!sourceValue) {+ searchConditions.push({ JobSource: { label: { contains: search } } });+ }+ searchConditions.push(+ { description: { contains: search } },+ );+ whereClause.OR = searchConditions;+ }++ return whereClause;+};++export const getJobsList = async (+ page: number = 1,+ limit: number = APP_CONSTANTS.RECORDS_PER_PAGE,+ filter?: string,+ search?: string,+ companyValue?: string,+ appliedOnly?: boolean,+ titleValue?: string,+ locationValue?: string,+ sourceValue?: string,+): Promise<any | undefined> => {+ try {+ const user = await requireUser();+ const skip = (page - 1) * limit;++ const whereClause = buildJobsWhereClause(user.id, {+ filter,+ search,+ companyValue,+ appliedOnly,+ titleValue,+ locationValue,+ sourceValue,+ });++ const [data, total] = await Promise.all([+ prisma.job.findMany({+ where: whereClause,+ skip,+ take: limit,+ select: JOB_LIST_SELECT,+ orderBy: {+ createdAt: "desc",+ // appliedDate: "desc",+ },+ }),+ prisma.job.count({+ where: whereClause,+ }),+ ]);+ return { success: true, data, total };+ } catch (error) {+ const msg = "Failed to fetch jobs list. ";+ return handleError(error, msg);+ }+};++export async function* getJobsIterator(filter?: string, pageSize = 200) {+ const user = await requireUser();+ let page = 1;+ let fetchedCount = 0;++ while (true) {+ const skip = (page - 1) * pageSize;+ const filterBy = filter+ ? filter === Object.keys(JOB_TYPES)[1]+ ? { status: filter }+ : { type: filter }+ : {};++ const chunk = await prisma.job.findMany({+ where: {+ userId: user.id,+ ...filterBy,+ },+ select: JOB_EXPORT_SELECT,+ skip,+ take: pageSize,+ orderBy: { createdAt: "desc" },+ });++ if (!chunk.length) {+ break;+ }++ yield chunk;+ fetchedCount += chunk.length;+ page++;+ }+}++export const getJobDetails = async (+ jobId: string,+): Promise<any | undefined> => {+ try {+ if (!jobId) {+ throw new Error("Please provide job id");+ }+ const user = await requireUser();++ const job = await prisma.job.findUnique({+ where: {+ id: jobId,+ userId: user.id,+ },+ include: JOB_DETAILS_INCLUDE,+ });+ return { job, success: true };+ } catch (error) {+ const msg = "Failed to fetch job details. ";+ return handleError(error, msg);+ }+};diff --git a/src/actions/job/references.ts b/src/actions/job/references.tsnew file mode 100644index 0000000..93a8113--- /dev/null+++ b/src/actions/job/references.ts@@ -0,0 +1,92 @@+"use server";+import prisma from "@/lib/db";+import { handleError } from "@/lib/utils";+import { canonicalizeEntityValue } from "@/lib/jobs/canonicalize";+import { requireUser } from "../shared";++// JobStatus is global reference data with no createdBy column, so unlike every+// other list here it is not scoped to the current user.+export const getStatusList = async (): Promise<any | undefined> => {+ try {+ const statuses = await prisma.jobStatus.findMany();+ return statuses;+ } catch (error) {+ const msg = "Failed to fetch status list. ";+ return handleError(error, msg);+ }+};++export const getJobSourceList = async (): Promise<any | undefined> => {+ try {+ const user = await requireUser();+ const list = await prisma.jobSource.findMany({+ where: {+ createdBy: user.id,+ },+ });+ return list;+ } catch (error) {+ const msg = "Failed to fetch job source list. ";+ return handleError(error, msg);+ }+};++export const createLocation = async (+ label: string,+): Promise<any | undefined> => {+ try {+ const user = await requireUser();++ const value = canonicalizeEntityValue(label.trim());++ if (!value) {+ throw new Error("Please provide location name");+ }++ const existing = await prisma.location.findFirst({+ where: { value, createdBy: user.id },+ });+ if (existing) {+ return { data: existing, success: true };+ }++ const location = await prisma.location.create({+ data: { label, value, createdBy: user.id },+ });++ return { data: location, success: true };+ } catch (error) {+ const msg = "Failed to create job location. ";+ return handleError(error, msg);+ }+};++export const createJobSource = async (+ label: string,+): Promise<any | undefined> => {+ try {+ const user = await requireUser();++ const value = canonicalizeEntityValue(label.trim());++ if (!value) {+ throw new Error("Please provide job source name");+ }++ const existing = await prisma.jobSource.findFirst({+ where: { value, createdBy: user.id },+ });+ if (existing) {+ return { data: existing, success: true };+ }++ const jobSource = await prisma.jobSource.create({+ data: { label, value, createdBy: user.id },+ });++ return { data: jobSource, success: true };+ } catch (error) {+ const msg = "Failed to create job source. ";+ return handleError(error, msg);+ }+};diff --git a/src/actions/job/status.ts b/src/actions/job/status.tsnew file mode 100644index 0000000..41e996a--- /dev/null+++ b/src/actions/job/status.ts@@ -0,0 +1,67 @@+"use server";+import prisma from "@/lib/db";+import { handleError } from "@/lib/utils";+import { JobStatus } from "@/models/job.model";+import { revalidatePath } from "next/cache";+import { requireUser } from "../shared";++export const updateJobStatus = async (+ jobId: string,+ status: JobStatus,+): Promise<any | undefined> => {+ try {+ const user = await requireUser();+ const dataToUpdate = () => {+ switch (status.value) {+ case "applied":+ return {+ statusId: status.id,+ applied: true,+ appliedDate: new Date(),+ };+ case "interview":+ return {+ statusId: status.id,+ applied: true,+ };+ default:+ return {+ statusId: status.id,+ };+ }+ };++ const job = await prisma.job.update({+ where: {+ id: jobId,+ userId: user.id,+ },+ data: dataToUpdate(),+ });+ revalidatePath("/dashboard");+ return { job, success: true };+ } catch (error) {+ const msg = "Failed to update job status.";+ return handleError(error, msg);+ }+};++export const saveJobMatchResult = async (+ jobId: string,+ matchScore: number,+ matchData: string,+): Promise<any | undefined> => {+ try {+ const user = await requireUser();++ await prisma.job.update({+ where: { id: jobId, userId: user.id },+ data: { matchScore, matchData },+ });++ return { success: true };+ } catch (error) {+ const msg = "Failed to save match result.";+ return handleError(error, msg);+ }+};diff --git a/src/actions/profile/shared.ts b/src/actions/profile/shared.tsindex 6f126ba..96a0bba 100644--- a/src/actions/profile/shared.ts+++ b/src/actions/profile/shared.ts@@ -1,16 +1,11 @@import prisma from "@/lib/db";-import { getCurrentUser } from "@/utils/user.utils";// Not a "use server" module: it exports selects, so it stays internal to// src/actions/profile/ and is never imported by a client component.-export const requireUser = async () => {- const user = await getCurrentUser();- if (!user) {- throw new Error("Not authenticated");- }- return user;-};+// Re-exported so the existing "./shared" import in each profile module keeps+// working now that requireUser is shared with the other action directories.+export { requireUser } from "../shared";// Canonical IDOR guard for actions that only need to confirm resume ownershipexport const assertResumeOwnership = async (diff --git a/src/actions/shared.ts b/src/actions/shared.tsnew file mode 100644index 0000000..360fb26--- /dev/null+++ b/src/actions/shared.ts@@ -0,0 +1,12 @@+import { getCurrentUser } from "@/utils/user.utils";++// Not a "use server" module: shared across the action directories, so it must+// stay importable without becoming a callable server-action endpoint.++export const requireUser = async () => {+ const user = await getCurrentUser();+ if (!user) {+ throw new Error("Not authenticated");+ }+ return user;+};