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
Add multi user support to admin data
Khuram Niaz4f4cb4ef7123
diff --git a/__tests__/company.actions.spec.ts b/__tests__/company.actions.spec.tsindex cf62d27..bdf4ce3 100644--- a/__tests__/company.actions.spec.ts+++ b/__tests__/company.actions.spec.ts@@ -19,6 +19,7 @@ jest.mock("@prisma/client", () => {findMany: jest.fn(),count: jest.fn(),findUnique: jest.fn(),+ findFirst: jest.fn(),create: jest.fn(),update: jest.fn(),delete: jest.fn(),@@ -200,7 +201,7 @@ describe("Company Actions", () => {it("should create a new company successfully", async () => {(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);- (prisma.company.findUnique as jest.Mock).mockResolvedValue(null);+ (prisma.company.findFirst as jest.Mock).mockResolvedValue(null);const mockCompany = {id: "company-id",label: "New Company",@@ -215,8 +216,8 @@ describe("Company Actions", () => {const result = await addCompany(validData);expect(result).toEqual({ success: true, data: mockCompany });- expect(prisma.company.findUnique).toHaveBeenCalledWith({- where: { value: "new company" },+ expect(prisma.company.findFirst).toHaveBeenCalledWith({+ where: { value: "new company", createdBy: mockUser.id },});expect(prisma.company.create).toHaveBeenCalledWith({data: {@@ -235,7 +236,7 @@ describe("Company Actions", () => {const result = await addCompany(validData);expect(result).toEqual({ success: false, message: "Not authenticated" });- expect(prisma.company.findUnique).not.toHaveBeenCalled();+ expect(prisma.company.findFirst).not.toHaveBeenCalled();expect(prisma.company.create).not.toHaveBeenCalled();});@@ -247,7 +248,7 @@ describe("Company Actions", () => {value: "new company",createdBy: mockUser.id,};- (prisma.company.findUnique as jest.Mock).mockResolvedValue(+ (prisma.company.findFirst as jest.Mock).mockResolvedValue(mockExistingCompany,);@@ -257,23 +258,23 @@ describe("Company Actions", () => {success: false,message: "Company already exists!",});- expect(prisma.company.findUnique).toHaveBeenCalledWith({- where: { value: "new company" },+ expect(prisma.company.findFirst).toHaveBeenCalledWith({+ where: { value: "new company", createdBy: mockUser.id },});expect(prisma.company.create).not.toHaveBeenCalled();});it("should handle unexpected errors", async () => {(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);- (prisma.company.findUnique as jest.Mock).mockRejectedValue(+ (prisma.company.findFirst as jest.Mock).mockRejectedValue(new Error("Unexpected error"),);const result = await addCompany(validData);expect(result).toEqual({ success: false, message: "Unexpected error" });- expect(prisma.company.findUnique).toHaveBeenCalledWith({- where: { value: "new company" },+ expect(prisma.company.findFirst).toHaveBeenCalledWith({+ where: { value: "new company", createdBy: mockUser.id },});expect(prisma.company.create).not.toHaveBeenCalled();});@@ -293,7 +294,7 @@ describe("Company Actions", () => {message: "Invalid logo URL. Only http and https protocols are allowed.",});- expect(prisma.company.findUnique).not.toHaveBeenCalled();+ expect(prisma.company.findFirst).not.toHaveBeenCalled();expect(prisma.company.create).not.toHaveBeenCalled();});@@ -317,7 +318,7 @@ describe("Company Actions", () => {it("should allow empty logo URL", async () => {(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);- (prisma.company.findUnique as jest.Mock).mockResolvedValue(null);+ (prisma.company.findFirst as jest.Mock).mockResolvedValue(null);const mockCompany = {id: "company-id",label: "New Company",@@ -339,7 +340,7 @@ describe("Company Actions", () => {it("should allow https URLs", async () => {(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);- (prisma.company.findUnique as jest.Mock).mockResolvedValue(null);+ (prisma.company.findFirst as jest.Mock).mockResolvedValue(null);const mockCompany = {id: "company-id",label: "New Company",@@ -371,7 +372,7 @@ describe("Company Actions", () => {it("should update a company successfully", async () => {(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);- (prisma.company.findUnique as jest.Mock).mockResolvedValue(null);+ (prisma.company.findFirst as jest.Mock).mockResolvedValue(null);const mockUpdatedCompany = {id: "company-id",@@ -386,8 +387,8 @@ describe("Company Actions", () => {expect(result).toEqual({ success: true, data: mockUpdatedCompany });- expect(prisma.company.findUnique).toHaveBeenCalledWith({- where: { value: "updated company" },+ expect(prisma.company.findFirst).toHaveBeenCalledWith({+ where: { value: "updated company", createdBy: mockUser.id },});expect(prisma.company.update).toHaveBeenCalledWith({@@ -407,14 +408,14 @@ describe("Company Actions", () => {expect(result).toEqual({ success: false, message: "Not authenticated" });- expect(prisma.company.findUnique).not.toHaveBeenCalled();+ expect(prisma.company.findFirst).not.toHaveBeenCalled();expect(prisma.company.update).not.toHaveBeenCalled();});it("should return error if company already exists", async () => {(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);- (prisma.company.findUnique as jest.Mock).mockResolvedValue({+ (prisma.company.findFirst as jest.Mock).mockResolvedValue({id: "existing-company-id",});@@ -440,7 +441,7 @@ describe("Company Actions", () => {message: "Id is not provided or no user privilages",});- expect(prisma.company.findUnique).not.toHaveBeenCalled();+ expect(prisma.company.findFirst).not.toHaveBeenCalled();expect(prisma.company.update).not.toHaveBeenCalled();});@@ -459,7 +460,7 @@ describe("Company Actions", () => {message: "Invalid logo URL. Only http and https protocols are allowed.",});- expect(prisma.company.findUnique).not.toHaveBeenCalled();+ expect(prisma.company.findFirst).not.toHaveBeenCalled();expect(prisma.company.update).not.toHaveBeenCalled();});@@ -484,7 +485,7 @@ describe("Company Actions", () => {it("should allow empty logo URL", async () => {(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);- (prisma.company.findUnique as jest.Mock).mockResolvedValue(null);+ (prisma.company.findFirst as jest.Mock).mockResolvedValue(null);const mockUpdatedCompany = {id: "company-id",diff --git a/__tests__/job.actions.spec.ts b/__tests__/job.actions.spec.tsindex 8d0e542..2e36441 100644--- a/__tests__/job.actions.spec.ts+++ b/__tests__/job.actions.spec.ts@@ -36,6 +36,7 @@ jest.mock("@prisma/client", () => {},location: {findMany: jest.fn(),+ findFirst: jest.fn(),create: jest.fn(),update: jest.fn(),},@@ -417,7 +418,7 @@ describe("jobActions", () => {createdBy: mockUser.id,};(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);-+ (prisma.location.findFirst as jest.Mock).mockResolvedValue(null);(prisma.location.create as jest.Mock).mockResolvedValue(mockLocation);const result = await createLocation(label);@@ -435,7 +436,7 @@ describe("jobActions", () => {});it("should handle unexpected errors", async () => {(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);-+ (prisma.location.findFirst as jest.Mock).mockResolvedValue(null);(prisma.location.create as jest.Mock).mockRejectedValue(new Error("Unexpected error"));diff --git a/__tests__/jobtitle.actions.spec.ts b/__tests__/jobtitle.actions.spec.tsindex 9775510..939f290 100644--- a/__tests__/jobtitle.actions.spec.ts+++ b/__tests__/jobtitle.actions.spec.ts@@ -183,7 +183,7 @@ describe("Job Title Actions", () => {expect(result).toEqual(mockTitle);expect(prisma.jobTitle.upsert).toHaveBeenCalledWith({- where: { value: "senior developer", createdBy: mockUser.id },+ where: { value_createdBy: { value: "senior developer", createdBy: mockUser.id } },update: { label: "Senior Developer" },create: {label: "Senior Developer",diff --git a/package.json b/package.jsonindex c92194c..7bf6736 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "jobsync",- "version": "0.2.3",+ "version": "0.2.4","private": true,"scripts": {"dev": "next dev --turbopack -p 3000",diff --git a/prisma/migrations/20260216_multi_user_unique_constraints/migration.sql b/prisma/migrations/20260216_multi_user_unique_constraints/migration.sqlnew file mode 100644index 0000000..a95f2cd--- /dev/null+++ b/prisma/migrations/20260216_multi_user_unique_constraints/migration.sql@@ -0,0 +1,23 @@+-- DropIndex+DROP INDEX "ActivityType_value_key";++-- DropIndex+DROP INDEX "Company_value_key";++-- DropIndex+DROP INDEX "JobSource_value_key";++-- DropIndex+DROP INDEX "JobTitle_value_key";++-- CreateIndex+CREATE UNIQUE INDEX "ActivityType_value_createdBy_key" ON "ActivityType"("value", "createdBy");++-- CreateIndex+CREATE UNIQUE INDEX "Company_value_createdBy_key" ON "Company"("value", "createdBy");++-- CreateIndex+CREATE UNIQUE INDEX "JobSource_value_createdBy_key" ON "JobSource"("value", "createdBy");++-- CreateIndex+CREATE UNIQUE INDEX "JobTitle_value_createdBy_key" ON "JobTitle"("value", "createdBy");diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 0dfe535..a523204 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -176,11 +176,13 @@ model Contact {model JobTitle {id String @id @default(uuid())label String- value String @unique //TODO: Change and Apply unique constraint on index with value and userid+ value Stringjobs Job[]createdBy String // userIduser User @relation(fields: [createdBy], references: [id])workExperiences WorkExperience[]++ @@unique([value, createdBy])}model JobStatus {@@ -206,21 +208,25 @@ model Location {model Company {id String @id @default(uuid())label String- value String @unique+ value StringjobsApplied Job[]logoUrl String? // field is optionalcreatedBy String // userIduser User @relation(fields: [createdBy], references: [id])workExperiences WorkExperience[]++ @@unique([value, createdBy])}model JobSource {id String @id @default(uuid())label String- value String @unique+ value StringjobsApplied Job[]createdBy String // userIduser User @relation(fields: [createdBy], references: [id])++ @@unique([value, createdBy])}model Interview {@@ -272,7 +278,7 @@ model Job {model ActivityType {id String @id @default(uuid())label String- value String @unique+ value Stringdescription String?createdBy String // userIduser User @relation(fields: [createdBy], references: [id])@@ -281,6 +287,8 @@ model ActivityType {Activities Activity[]Tasks Task[]++ @@unique([value, createdBy])}model Activity {diff --git a/src/actions/activity.actions.ts b/src/actions/activity.actions.tsindex ddd55f9..7f4033a 100644--- a/src/actions/activity.actions.ts+++ b/src/actions/activity.actions.ts@@ -40,7 +40,7 @@ export const createActivityType = async (const value = label.trim().toLowerCase();const upsertedActivityType = await prisma.activityType.upsert({- where: { value, createdBy: user.id },+ where: { value_createdBy: { value, createdBy: user.id } },update: { label },create: { label, value, createdBy: user.id },});diff --git a/src/actions/auth.actions.ts b/src/actions/auth.actions.tsindex afb1d7b..70a5d3f 100644--- a/src/actions/auth.actions.ts+++ b/src/actions/auth.actions.ts@@ -5,6 +5,7 @@ import { delay } from "@/utils/delay";import prisma from "@/lib/db";import bcrypt from "bcryptjs";import { SignupFormSchema } from "@/models/signupForm.schema";+import { JOB_SOURCES } from "@/lib/constants";export async function signup(formData: {name: string;@@ -28,10 +29,18 @@ export async function signup(formData: {const hashedPassword = await bcrypt.hash(password, 10);- await prisma.user.create({+ const newUser = await prisma.user.create({data: { name, email, password: hashedPassword },});+ await prisma.jobSource.createMany({+ data: JOB_SOURCES.map((source) => ({+ label: source.label,+ value: source.value,+ createdBy: newUser.id,+ })),+ });+return { success: true };}diff --git a/src/actions/company.actions.ts b/src/actions/company.actions.tsindex 5d139b0..b0ace96 100644--- a/src/actions/company.actions.ts+++ b/src/actions/company.actions.ts@@ -120,9 +120,10 @@ export const addCompany = async (const value = company.trim().toLowerCase();- const companyExists = await prisma.company.findUnique({+ const companyExists = await prisma.company.findFirst({where: {value,+ createdBy: user.id,},});@@ -171,9 +172,10 @@ export const updateCompany = async (const value = company.trim().toLowerCase();- const companyExists = await prisma.company.findUnique({+ const companyExists = await prisma.company.findFirst({where: {value,+ createdBy: user.id,},});diff --git a/src/actions/job.actions.ts b/src/actions/job.actions.tsindex d49553e..cff295a 100644--- a/src/actions/job.actions.ts+++ b/src/actions/job.actions.ts@@ -213,6 +213,13 @@ export const createLocation = async (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 },});@@ -240,6 +247,13 @@ export const createJobSource = async (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 },});diff --git a/src/actions/jobtitle.actions.ts b/src/actions/jobtitle.actions.tsindex ea2480a..3242826 100644--- a/src/actions/jobtitle.actions.ts+++ b/src/actions/jobtitle.actions.ts@@ -92,7 +92,7 @@ export const createJobTitle = async (const value = label.trim().toLowerCase();const upsertedTitle = await prisma.jobTitle.upsert({- where: { value, createdBy: user.id },+ where: { value_createdBy: { value, createdBy: user.id } },update: { label },create: { label, value, createdBy: user.id },});diff --git a/src/components/ComboBox.tsx b/src/components/ComboBox.tsxindex b645aff..7ab7f0d 100644--- a/src/components/ComboBox.tsx+++ b/src/components/ComboBox.tsx@@ -75,6 +75,7 @@ export function Combobox({ options, field, creatable }: ComboboxProps) {});}response = sourceRes.data;+ if (!sourceRes.success) return;break;case "activityType":response = await createActivityType(label);diff --git a/src/lib/constants.ts b/src/lib/constants.tsindex ffc4d2d..98f938d 100644--- a/src/lib/constants.ts+++ b/src/lib/constants.ts@@ -21,6 +21,18 @@ export const SCHEDULER_CONSTANTS = {CRON_EXPRESSION: "0 * * * *", // Every hour at minute 0} as const;+export const JOB_SOURCES = [+ { label: "Indeed", value: "indeed" },+ { label: "Linkedin", value: "linkedin" },+ { label: "Monster", value: "monster" },+ { label: "Glassdoor", value: "glassdoor" },+ { label: "Company Career page", value: "careerpage" },+ { label: "Google", value: "google" },+ { label: "ZipRecruiter", value: "ziprecruiter" },+ { label: "Job Street", value: "jobstreet" },+ { label: "Other", value: "other" },+] as const;+export const SIDEBAR_LINKS = [{icon: LayoutDashboard,diff --git a/src/lib/scraper/mapper.ts b/src/lib/scraper/mapper.tsindex 02af946..3c820e9 100644--- a/src/lib/scraper/mapper.ts+++ b/src/lib/scraper/mapper.ts@@ -67,7 +67,7 @@ async function findOrCreateJobTitle(const normalized = normalizeForSearch(title);let existing = await db.jobTitle.findFirst({- where: { value: normalized },+ where: { value: normalized, createdBy: userId },});if (!existing) {@@ -75,6 +75,7 @@ async function findOrCreateJobTitle(if (keywords.length > 0) {existing = await db.jobTitle.findFirst({where: {+ createdBy: userId,OR: keywords.map((keyword) => ({value: { contains: keyword },})),@@ -146,7 +147,7 @@ async function findOrCreateCompany(const normalized = normalizeForSearch(company);let existing = await db.company.findFirst({- where: { value: normalized },+ where: { value: normalized, createdBy: userId },});if (!existing) {@@ -154,6 +155,7 @@ async function findOrCreateCompany(if (companyKeywords.length > 0) {existing = await db.company.findFirst({where: {+ createdBy: userId,OR: companyKeywords.map((keyword) => ({label: { contains: keyword },})),@@ -183,7 +185,7 @@ async function getOrCreateJobSource(const normalized = sourceBoard.toLowerCase();let jobSource = await db.jobSource.findFirst({- where: { value: normalized },+ where: { value: normalized, createdBy: userId },});if (!jobSource) {diff --git a/src/lib/seed.ts b/src/lib/seed.tsindex f111cdb..c986ad5 100644--- a/src/lib/seed.ts+++ b/src/lib/seed.ts@@ -1,4 +1,5 @@import prisma from "@/lib/db";+import { JOB_SOURCES } from "@/lib/constants";import bcrypt from "bcryptjs";@@ -12,18 +13,6 @@ const STATUS_DATA = [{ label: "Archived", value: "archived" },];-const JOB_SOURCES = [- { label: "Indeed", value: "indeed" },- { label: "Linkedin", value: "linkedin" },- { label: "Monster", value: "monster" },- { label: "Glassdoor", value: "glassdoor" },- { label: "Company Career page", value: "careerpage" },- { label: "Google", value: "google" },- { label: "ZipRecruiter", value: "ziprecruiter" },- { label: "Job Street", value: "jobstreet" },- { label: "Other", value: "other" },-];-async function seedUser() {const email = process.env.USER_EMAIL;if (!email || email.trim() === "") {@@ -69,17 +58,20 @@ async function seedStatuses() {}async function seedJobSources(userId: string) {- const existing = await prisma.jobSource.findUnique({- where: { value: "indeed" },+ const existing = await prisma.jobSource.findFirst({+ where: { value: "indeed", createdBy: userId },});if (existing) return;for (const source of JOB_SOURCES) {- await prisma.jobSource.upsert({- where: { value: source.value },- update: {},- create: { label: source.label, value: source.value, createdBy: userId },+ const found = await prisma.jobSource.findFirst({+ where: { value: source.value, createdBy: userId },});+ if (!found) {+ await prisma.jobSource.create({+ data: { label: source.label, value: source.value, createdBy: userId },+ });+ }}console.log("[seed] Job sources seeded");}