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(company): add reference-list filter/sort params and a watchlist scope to getCompanyList
Khuram Niaz33f2ccba098b
diff --git a/__tests__/company.actions.spec.ts b/__tests__/company.actions.spec.tsindex dad07b1..d37988e 100644--- a/__tests__/company.actions.spec.ts+++ b/__tests__/company.actions.spec.ts@@ -76,7 +76,7 @@ describe("Company Actions", () => {where: { createdBy: mockUser.id },skip: 0,take: 10,- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});expect(prisma.company.count).toHaveBeenCalledWith({where: { createdBy: mockUser.id },@@ -127,6 +127,11 @@ describe("Company Actions", () => {label: true,value: true,logoUrl: true,+ watched: true,+ watchedAt: true,+ atsProvider: true,+ atsToken: true,+ atsHost: true,_count: {select: {jobsApplied: {@@ -137,7 +142,7 @@ describe("Company Actions", () => {},},},- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});expect(prisma.company.count).toHaveBeenCalledWith({where: { createdBy: mockUser.id },@@ -175,13 +180,25 @@ describe("Company Actions", () => {expect(result).toEqual({ data: mockData, total: mockTotal });expect(prisma.company.findMany).toHaveBeenCalledWith({- where: { createdBy: mockUser.id, label: { contains: "Ama" } },+ where: {+ createdBy: mockUser.id,+ OR: [+ { label: { contains: "Ama" } },+ { atsToken: { contains: "Ama" } },+ ],+ },skip: 0,take: 10,- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});expect(prisma.company.count).toHaveBeenCalledWith({- where: { createdBy: mockUser.id, label: { contains: "Ama" } },+ where: {+ createdBy: mockUser.id,+ OR: [+ { label: { contains: "Ama" } },+ { atsToken: { contains: "Ama" } },+ ],+ },});});@@ -209,7 +226,13 @@ describe("Company Actions", () => {}));expect(result).toEqual({ data: expectedData, total: mockTotal });expect(prisma.company.findMany).toHaveBeenCalledWith({- where: { createdBy: mockUser.id, label: { contains: "Ama" } },+ where: {+ createdBy: mockUser.id,+ OR: [+ { label: { contains: "Ama" } },+ { atsToken: { contains: "Ama" } },+ ],+ },skip: 0,take: 10,select: {@@ -217,6 +240,11 @@ describe("Company Actions", () => {label: true,value: true,logoUrl: true,+ watched: true,+ watchedAt: true,+ atsProvider: true,+ atsToken: true,+ atsHost: true,_count: {select: {jobsApplied: {@@ -227,13 +255,34 @@ describe("Company Actions", () => {},},},- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});expect(prisma.company.count).toHaveBeenCalledWith({- where: { createdBy: mockUser.id, label: { contains: "Ama" } },+ where: {+ createdBy: mockUser.id,+ OR: [+ { label: { contains: "Ama" } },+ { atsToken: { contains: "Ama" } },+ ],+ },});});+ it("filters and sorts by watch state in the watchlist scope", async () => {+ (getCurrentUser as any).mockResolvedValue(mockUser);+ (prisma.company.findMany as any).mockResolvedValue([]);+ (prisma.company.count as any).mockResolvedValue(0);++ await getCompanyList(1, 10, undefined, undefined, "watchlist");++ expect(prisma.company.findMany).toHaveBeenCalledWith(+ expect.objectContaining({+ where: { createdBy: mockUser.id, watched: true },+ orderBy: [{ watchedAt: "desc" }, { label: "asc" }],+ })+ );+ });+it("should not apply a label filter when search is empty", async () => {(getCurrentUser as any).mockResolvedValue(mockUser);(prisma.company.findMany as any).mockResolvedValue([]);@@ -245,7 +294,7 @@ describe("Company Actions", () => {where: { createdBy: mockUser.id },skip: 0,take: 10,- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});});});diff --git a/__tests__/jobLocation.actions.spec.ts b/__tests__/jobLocation.actions.spec.tsindex fc2ed76..3ff8b6e 100644--- a/__tests__/jobLocation.actions.spec.ts+++ b/__tests__/jobLocation.actions.spec.ts@@ -100,7 +100,7 @@ describe("Job Location Actions", () => {where: { createdBy: mockUser.id },skip: 0,take: 10,- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});expect(prisma.location.count).toHaveBeenCalledWith({where: { createdBy: mockUser.id },@@ -139,7 +139,7 @@ describe("Job Location Actions", () => {},},},- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});});@@ -184,13 +184,13 @@ describe("Job Location Actions", () => {expect(result).toEqual({ data: mockData, total: 1 });expect(prisma.location.findMany).toHaveBeenCalledWith({- where: { createdBy: mockUser.id, label: { contains: "New" } },+ where: { createdBy: mockUser.id, OR: [{ label: { contains: "New" } }] },skip: 0,take: 10,- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});expect(prisma.location.count).toHaveBeenCalledWith({- where: { createdBy: mockUser.id, label: { contains: "New" } },+ where: { createdBy: mockUser.id, OR: [{ label: { contains: "New" } }] },});});@@ -205,7 +205,7 @@ describe("Job Location Actions", () => {where: { createdBy: mockUser.id },skip: 0,take: 10,- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});});});diff --git a/__tests__/jobSource.actions.spec.ts b/__tests__/jobSource.actions.spec.tsindex c8742cc..d525dd0 100644--- a/__tests__/jobSource.actions.spec.ts+++ b/__tests__/jobSource.actions.spec.ts@@ -57,7 +57,7 @@ describe("Job Source Actions", () => {where: { createdBy: mockUser.id },skip: 0,take: 10,- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});expect(prisma.jobSource.count).toHaveBeenCalledWith({where: { createdBy: mockUser.id },@@ -95,7 +95,7 @@ describe("Job Source Actions", () => {},},},- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});expect(prisma.job.groupBy).toHaveBeenCalledWith({by: ["jobSourceId"],@@ -143,13 +143,13 @@ describe("Job Source Actions", () => {expect(result).toEqual({ data: mockData, total: 1 });expect(prisma.jobSource.findMany).toHaveBeenCalledWith({- where: { createdBy: mockUser.id, label: { contains: "Link" } },+ where: { createdBy: mockUser.id, OR: [{ label: { contains: "Link" } }] },skip: 0,take: 10,- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});expect(prisma.jobSource.count).toHaveBeenCalledWith({- where: { createdBy: mockUser.id, label: { contains: "Link" } },+ where: { createdBy: mockUser.id, OR: [{ label: { contains: "Link" } }] },});});@@ -164,7 +164,7 @@ describe("Job Source Actions", () => {where: { createdBy: mockUser.id },skip: 0,take: 10,- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});});});diff --git a/__tests__/jobtitle.actions.spec.ts b/__tests__/jobtitle.actions.spec.tsindex 509a3c0..66a3572 100644--- a/__tests__/jobtitle.actions.spec.ts+++ b/__tests__/jobtitle.actions.spec.ts@@ -99,7 +99,7 @@ describe("Job Title Actions", () => {where: { createdBy: mockUser.id },skip: 0,take: 10,- orderBy: { jobs: { _count: "desc" } },+ orderBy: [{ jobs: { _count: "desc" } }, { label: "asc" }],});expect(prisma.jobTitle.count).toHaveBeenCalledWith({where: { createdBy: mockUser.id },@@ -138,7 +138,7 @@ describe("Job Title Actions", () => {},},},- orderBy: { jobs: { _count: "desc" } },+ orderBy: [{ jobs: { _count: "desc" } }, { label: "asc" }],});});@@ -185,13 +185,13 @@ describe("Job Title Actions", () => {expect(result).toEqual({ data: mockData, total: 1 });expect(prisma.jobTitle.findMany).toHaveBeenCalledWith({- where: { createdBy: mockUser.id, label: { contains: "Dev" } },+ where: { createdBy: mockUser.id, OR: [{ label: { contains: "Dev" } }] },skip: 0,take: 10,- orderBy: { jobs: { _count: "desc" } },+ orderBy: [{ jobs: { _count: "desc" } }, { label: "asc" }],});expect(prisma.jobTitle.count).toHaveBeenCalledWith({- where: { createdBy: mockUser.id, label: { contains: "Dev" } },+ where: { createdBy: mockUser.id, OR: [{ label: { contains: "Dev" } }] },});});@@ -206,7 +206,7 @@ describe("Job Title Actions", () => {where: { createdBy: mockUser.id },skip: 0,take: 10,- orderBy: { jobs: { _count: "desc" } },+ orderBy: [{ jobs: { _count: "desc" } }, { label: "asc" }],});});});diff --git a/__tests__/referenceList.spec.ts b/__tests__/referenceList.spec.tsindex 751bde2..1a31703 100644--- a/__tests__/referenceList.spec.ts+++ b/__tests__/referenceList.spec.ts@@ -46,7 +46,7 @@ describe("getReferenceEntityList", () => {where: { createdBy: userId },skip: 0,take: 10,- orderBy: { jobsApplied: { _count: "desc" } },+ orderBy: [{ jobsApplied: { _count: "desc" } }, { label: "asc" }],});expect(model.count).toHaveBeenCalledWith({ where: { createdBy: userId } });expect(prisma.job.groupBy).not.toHaveBeenCalled();@@ -80,7 +80,7 @@ describe("getReferenceEntityList", () => {},},},- orderBy: { jobs: { _count: "desc" } },+ orderBy: [{ jobs: { _count: "desc" } }, { label: "asc" }],});});@@ -206,11 +206,11 @@ describe("getReferenceEntityList", () => {expect(model.findMany).toHaveBeenCalledWith(expect.objectContaining({- where: { createdBy: userId, label: { contains: "Ama" } },+ where: { createdBy: userId, OR: [{ label: { contains: "Ama" } }] },}));expect(model.count).toHaveBeenCalledWith({- where: { createdBy: userId, label: { contains: "Ama" } },+ where: { createdBy: userId, OR: [{ label: { contains: "Ama" } }] },});});@@ -280,4 +280,70 @@ describe("getReferenceEntityList", () => {})).rejects.toThrow("Database error");});++ it("merges extraWhere into the where clause for both findMany and count", async () => {+ const model = makeModel([], 0);++ await getReferenceEntityList({+ model,+ userId,+ fkField: "companyId",+ appliedRelation: "jobsApplied",+ extraWhere: { watched: true },+ page: 1,+ limit: 10,+ });++ const expected = { createdBy: userId, watched: true };+ expect(model.findMany).toHaveBeenCalledWith(+ expect.objectContaining({ where: expected })+ );+ expect(model.count).toHaveBeenCalledWith({ where: expected });+ });++ it("builds an OR clause across every searchField", async () => {+ const model = makeModel([], 0);++ await getReferenceEntityList({+ model,+ userId,+ fkField: "companyId",+ appliedRelation: "jobsApplied",+ searchFields: ["label", "atsToken"],+ search: "acme",+ page: 1,+ limit: 10,+ });++ expect(model.findMany).toHaveBeenCalledWith(+ expect.objectContaining({+ where: {+ createdBy: userId,+ OR: [+ { label: { contains: "acme" } },+ { atsToken: { contains: "acme" } },+ ],+ },+ })+ );+ });++ it("uses the supplied orderBy over the default tiebreak", async () => {+ const model = makeModel([], 0);+ const orderBy = [{ watchedAt: "desc" }, { label: "asc" }];++ await getReferenceEntityList({+ model,+ userId,+ fkField: "companyId",+ appliedRelation: "jobsApplied",+ orderBy,+ page: 1,+ limit: 10,+ });++ expect(model.findMany).toHaveBeenCalledWith(+ expect.objectContaining({ orderBy })+ );+ });});diff --git a/src/actions/company/queries.ts b/src/actions/company/queries.tsindex 2870c4b..7a90511 100644--- a/src/actions/company/queries.ts+++ b/src/actions/company/queries.ts@@ -10,19 +10,38 @@ export const getCompanyList = async (limit: number = APP_CONSTANTS.RECORDS_PER_PAGE,countBy?: string,search?: string,+ scope: "mine" | "watchlist" = "mine",): Promise<any | undefined> => {try {const user = await requireUser();+ const watchlist = scope === "watchlist";+return await getReferenceEntityList({model: prisma.company,userId: user.id,fkField: "companyId",appliedRelation: "jobsApplied",- extraSelect: { logoUrl: true },+ extraSelect: {+ logoUrl: true,+ watched: true,+ watchedAt: true,+ atsProvider: true,+ atsToken: true,+ atsHost: true,+ },extraCounts: [{ key: "jobsRejected", where: { Status: { value: "rejected" } } },],+ // A watched row sits at applied-count 0, so the default sort would bury+ // whatever was just watched; most-recent-first is what the scope is for.+ ...(watchlist+ ? {+ extraWhere: { watched: true },+ orderBy: [{ watchedAt: "desc" }, { label: "asc" }],+ }+ : {}),+ searchFields: ["label", "atsToken"],page,limit,countBy,diff --git a/src/actions/referenceList.ts b/src/actions/referenceList.tsindex 65023e0..9e6bb37 100644--- a/src/actions/referenceList.ts+++ b/src/actions/referenceList.ts@@ -20,6 +20,9 @@ export type ReferenceListParams = {appliedRelation: string;extraSelect?: Record<string, true>;extraCounts?: ReferenceExtraCount[];+ extraWhere?: Record<string, any>;+ searchFields?: string[];+ orderBy?: any;page: number;limit: number;countBy?: string;@@ -33,6 +36,9 @@ export const getReferenceEntityList = async ({appliedRelation,extraSelect,extraCounts,+ extraWhere,+ searchFields,+ orderBy,page,limit,countBy,@@ -42,10 +48,14 @@ export const getReferenceEntityList = async ({const whereClause: any = {createdBy: userId,+ ...extraWhere,};if (search) {- whereClause.label = { contains: search };+ const fields = searchFields ?? ["label"];+ whereClause.OR = fields.map((field) => ({+ [field]: { contains: search },+ }));}// Prisma can only count the applied relation inline, so every other tally@@ -84,11 +94,12 @@ export const getReferenceEntityList = async ({},}: {}),- orderBy: {- [appliedRelation]: {- _count: "desc",- },- },+ // Two keys, not one: the applied-count sort alone has no tiebreak, so+ // equal-count rows page unstably under infinite scroll.+ orderBy: orderBy ?? [+ { [appliedRelation]: { _count: "desc" } },+ { label: "asc" },+ ],}),model.count({where: whereClause,