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.

Add questions field column to tags table

Khuram Niaza6a3c4567fe8
diff --git a/__tests__/tag.actions.spec.ts b/__tests__/tag.actions.spec.ts
index 0c792f6..75853ae 100644
--- a/__tests__/tag.actions.spec.ts
+++ b/__tests__/tag.actions.spec.ts
@@ -20,6 +20,9 @@ jest.mock("@prisma/client", () => {
job: {
count: jest.fn(),
},
+ question: {
+ count: jest.fn(),
+ },
};
return { PrismaClient: jest.fn(() => mPrismaClient) };
});
@@ -86,7 +89,7 @@ describe("Tag Actions", () => {
describe("getTagList", () => {
it("should return paginated tag list with counts", async () => {
(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
- const mockData = [{ ...mockTag, _count: { jobs: 3 } }];
+ const mockData = [{ ...mockTag, _count: { jobs: 3, questions: 2 } }];
(prisma.tag.findMany as jest.Mock).mockResolvedValue(mockData);
(prisma.tag.count as jest.Mock).mockResolvedValue(1);
@@ -198,9 +201,10 @@ describe("Tag Actions", () => {
// deleteTagById
describe("deleteTagById", () => {
- it("should delete a tag that has no linked jobs", async () => {
+ it("should delete a tag that has no linked jobs or questions", async () => {
(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
(prisma.job.count as jest.Mock).mockResolvedValue(0);
+ (prisma.question.count as jest.Mock).mockResolvedValue(0);
(prisma.tag.delete as jest.Mock).mockResolvedValue(mockTag);
const result = await deleteTagById("tag-1");
@@ -211,9 +215,10 @@ describe("Tag Actions", () => {
});
});
- it("should return error when tag is linked to one or more jobs", async () => {
+ it("should return error when tag is linked to jobs only", async () => {
(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
(prisma.job.count as jest.Mock).mockResolvedValue(3);
+ (prisma.question.count as jest.Mock).mockResolvedValue(0);
const result = await deleteTagById("tag-1");
@@ -225,6 +230,36 @@ describe("Tag Actions", () => {
expect(prisma.tag.delete).not.toHaveBeenCalled();
});
+ it("should return error when tag is linked to questions only", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+ (prisma.question.count as jest.Mock).mockResolvedValue(5);
+
+ const result = await deleteTagById("tag-1");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "Skill tag cannot be deleted because it is linked to 5 question(s).",
+ });
+ expect(prisma.tag.delete).not.toHaveBeenCalled();
+ });
+
+ it("should return error when tag is linked to both jobs and questions", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.job.count as jest.Mock).mockResolvedValue(2);
+ (prisma.question.count as jest.Mock).mockResolvedValue(4);
+
+ const result = await deleteTagById("tag-1");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "Skill tag cannot be deleted because it is linked to 2 job(s) and 4 question(s).",
+ });
+ expect(prisma.tag.delete).not.toHaveBeenCalled();
+ });
+
it("should return error for unauthenticated user", async () => {
(getCurrentUser as jest.Mock).mockResolvedValue(null);
@@ -232,12 +267,14 @@ describe("Tag Actions", () => {
expect(result).toEqual({ success: false, message: "Not authenticated" });
expect(prisma.job.count).not.toHaveBeenCalled();
+ expect(prisma.question.count).not.toHaveBeenCalled();
expect(prisma.tag.delete).not.toHaveBeenCalled();
});
it("should handle database errors during deletion", async () => {
(getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
(prisma.job.count as jest.Mock).mockResolvedValue(0);
+ (prisma.question.count as jest.Mock).mockResolvedValue(0);
(prisma.tag.delete as jest.Mock).mockRejectedValue(new Error("DB error"));
const result = await deleteTagById("tag-1");
diff --git a/src/actions/tag.actions.ts b/src/actions/tag.actions.ts
index 49acfd4..9a7fdf8 100644
--- a/src/actions/tag.actions.ts
+++ b/src/actions/tag.actions.ts
@@ -41,7 +41,7 @@ export const getTagList = async (
id: true,
label: true,
value: true,
- _count: { select: { jobs: true } },
+ _count: { select: { jobs: true, questions: true } },
},
orderBy: { label: "asc" },
}),
@@ -91,13 +91,21 @@ export const deleteTagById = async (
throw new Error("Not authenticated");
}
- const jobs = await prisma.job.count({
- where: { tags: { some: { id: tagId } } },
- });
+ const [jobs, questions] = await Promise.all([
+ prisma.job.count({ where: { tags: { some: { id: tagId } } } }),
+ prisma.question.count({ where: { tags: { some: { id: tagId } } } }),
+ ]);
+
+ if (jobs > 0 || questions > 0) {
+ const links = [
+ jobs > 0 ? `${jobs} job(s)` : "",
+ questions > 0 ? `${questions} question(s)` : "",
+ ]
+ .filter(Boolean)
+ .join(" and ");
- if (jobs > 0) {
throw new Error(
- `Skill tag cannot be deleted because it is linked to ${jobs} job(s).`,
+ `Skill tag cannot be deleted because it is linked to ${links}.`,
);
}
diff --git a/src/components/admin/TagsContainer.tsx b/src/components/admin/TagsContainer.tsx
index 2b948cf..0d24e23 100644
--- a/src/components/admin/TagsContainer.tsx
+++ b/src/components/admin/TagsContainer.tsx
@@ -50,7 +50,7 @@ function TagsContainer() {
<div className="col-span-3">
<Card>
<CardHeader className="flex-row justify-between items-center">
- <CardTitle>Skills</CardTitle>
+ <CardTitle>Skills/Tags</CardTitle>
<div className="flex items-center">
<div className="ml-auto flex items-center gap-2">
<AddTag reloadTags={reloadTags} />
diff --git a/src/components/admin/TagsTable.tsx b/src/components/admin/TagsTable.tsx
index 34bd295..c42919c 100644
--- a/src/components/admin/TagsTable.tsx
+++ b/src/components/admin/TagsTable.tsx
@@ -35,11 +35,21 @@ function TagsTable({ tags, reloadTags }: TagsTableProps) {
});
const onDeleteTag = (tag: Tag) => {
- if ((tag._count?.jobs ?? 0) > 0) {
+ const jobCount = tag._count?.jobs ?? 0;
+ const questionCount = tag._count?.questions ?? 0;
+
+ if (jobCount > 0 || questionCount > 0) {
+ const links = [
+ jobCount > 0 ? `${jobCount} job(s)` : "",
+ questionCount > 0 ? `${questionCount} question(s)` : "",
+ ]
+ .filter(Boolean)
+ .join(" and ");
+
setAlert({
openState: true,
title: "Skill is in use!",
- description: `This skill is linked to ${tag._count?.jobs} job(s) and cannot be deleted.`,
+ description: `This skill is linked to ${links} and cannot be deleted.`,
deleteAction: false,
});
} else {
@@ -77,6 +87,7 @@ function TagsTable({ tags, reloadTags }: TagsTableProps) {
<TableHead>Skill Label</TableHead>
<TableHead className="hidden sm:table-cell">Value</TableHead>
<TableHead># Jobs</TableHead>
+ <TableHead># Questions</TableHead>
<TableHead>Actions</TableHead>
</TableRow>
</TableHeader>
@@ -90,6 +101,9 @@ function TagsTable({ tags, reloadTags }: TagsTableProps) {
<TableCell className="font-medium">
{tag._count?.jobs ?? 0}
</TableCell>
+ <TableCell className="font-medium">
+ {tag._count?.questions ?? 0}
+ </TableCell>
<TableCell>
<DropdownMenu>
<DropdownMenuTrigger asChild>
diff --git a/src/models/job.model.ts b/src/models/job.model.ts
index 44350fd..22e65b4 100644
--- a/src/models/job.model.ts
+++ b/src/models/job.model.ts
@@ -24,6 +24,7 @@ export interface Tag {
createdBy: string;
_count?: {
jobs: number;
+ questions: number;
};
}