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.

feat: Enhance job-related actions and tables to include total job counts

Khuram Niaz03b428e2435c
diff --git a/src/actions/company.actions.ts b/src/actions/company.actions.ts
index ca3b078..e582f8e 100644
--- a/src/actions/company.actions.ts
+++ b/src/actions/company.actions.ts
@@ -20,7 +20,7 @@ export const getCompanyList = async (
}
const skip = (page - 1) * limit;
- const [data, total, rejectedCounts] = await Promise.all([
+ const [data, total, rejectedCounts, totalCounts] = await Promise.all([
prisma.company.findMany({
where: {
createdBy: user.id,
@@ -67,6 +67,15 @@ export const getCompanyList = async (
_count: { id: true },
})
: Promise.resolve([]),
+ countBy
+ ? prisma.job.groupBy({
+ by: ["companyId"],
+ where: {
+ userId: user.id,
+ },
+ _count: { id: true },
+ })
+ : Promise.resolve([]),
]);
const rejectedMap = new Map(
@@ -75,12 +84,19 @@ export const getCompanyList = async (
),
);
+ const totalMap = new Map(
+ (totalCounts as { companyId: string; _count: { id: number } }[]).map(
+ (r) => [r.companyId, r._count.id],
+ ),
+ );
+
const dataWithRejected = countBy
? (data as any[]).map((company) => ({
...company,
_count: {
...(company._count ?? {}),
jobsRejected: rejectedMap.get(company.id) ?? 0,
+ jobsTotal: totalMap.get(company.id) ?? 0,
},
}))
: data;
@@ -281,6 +297,7 @@ export const deleteCompanyById = async (
const jobs = await prisma.job.count({
where: {
companyId,
+ userId: user.id,
},
});
diff --git a/src/actions/jobLocation.actions.ts b/src/actions/jobLocation.actions.ts
index 74eb40f..656a8fe 100644
--- a/src/actions/jobLocation.actions.ts
+++ b/src/actions/jobLocation.actions.ts
@@ -35,7 +35,7 @@ export const getJobLocationsList = async (
}
const skip = (page - 1) * limit;
- const [data, total] = await Promise.all([
+ const [data, total, totalCounts] = await Promise.all([
prisma.location.findMany({
where: {
createdBy: user.id,
@@ -71,8 +71,34 @@ export const getJobLocationsList = async (
createdBy: user.id,
},
}),
+ countBy
+ ? prisma.job.groupBy({
+ by: ["locationId"],
+ where: {
+ userId: user.id,
+ },
+ _count: { id: true },
+ })
+ : Promise.resolve([]),
]);
- return { data, total };
+
+ const totalMap = new Map(
+ (totalCounts as { locationId: string; _count: { id: number } }[]).map(
+ (r) => [r.locationId, r._count.id],
+ ),
+ );
+
+ const dataWithTotal = countBy
+ ? (data as any[]).map((location) => ({
+ ...location,
+ _count: {
+ ...(location._count ?? {}),
+ jobsTotal: totalMap.get(location.id) ?? 0,
+ },
+ }))
+ : data;
+
+ return { data: dataWithTotal, total };
} catch (error) {
const msg = "Failed to fetch job location list. ";
return handleError(error, msg);
@@ -114,6 +140,7 @@ export const deleteJobLocationById = async (
const jobs = await prisma.job.count({
where: {
locationId,
+ userId: user.id,
},
});
diff --git a/src/actions/jobSource.actions.ts b/src/actions/jobSource.actions.ts
index eaccd8f..732d44d 100644
--- a/src/actions/jobSource.actions.ts
+++ b/src/actions/jobSource.actions.ts
@@ -17,7 +17,7 @@ export const getJobSourceList = async (
}
const skip = (page - 1) * limit;
- const [data, total] = await Promise.all([
+ const [data, total, totalCounts] = await Promise.all([
prisma.jobSource.findMany({
where: {
createdBy: user.id,
@@ -53,8 +53,34 @@ export const getJobSourceList = async (
createdBy: user.id,
},
}),
+ countBy
+ ? prisma.job.groupBy({
+ by: ["jobSourceId"],
+ where: {
+ userId: user.id,
+ },
+ _count: { id: true },
+ })
+ : Promise.resolve([]),
]);
- return { data, total };
+
+ const totalMap = new Map(
+ (totalCounts as { jobSourceId: string; _count: { id: number } }[]).map(
+ (r) => [r.jobSourceId, r._count.id],
+ ),
+ );
+
+ const dataWithTotal = countBy
+ ? (data as any[]).map((source) => ({
+ ...source,
+ _count: {
+ ...(source._count ?? {}),
+ jobsTotal: totalMap.get(source.id) ?? 0,
+ },
+ }))
+ : data;
+
+ return { data: dataWithTotal, total };
} catch (error) {
const msg = "Failed to fetch job source list. ";
return handleError(error, msg);
@@ -74,6 +100,7 @@ export const deleteJobSourceById = async (
const jobs = await prisma.job.count({
where: {
jobSourceId,
+ userId: user.id,
},
});
diff --git a/src/actions/jobtitle.actions.ts b/src/actions/jobtitle.actions.ts
index 3242826..913f692 100644
--- a/src/actions/jobtitle.actions.ts
+++ b/src/actions/jobtitle.actions.ts
@@ -35,7 +35,7 @@ export const getJobTitleList = async (
}
const skip = (page - 1) * limit;
- const [data, total] = await Promise.all([
+ const [data, total, totalCounts] = await Promise.all([
prisma.jobTitle.findMany({
where: {
createdBy: user.id,
@@ -71,8 +71,34 @@ export const getJobTitleList = async (
createdBy: user.id,
},
}),
+ countBy
+ ? prisma.job.groupBy({
+ by: ["jobTitleId"],
+ where: {
+ userId: user.id,
+ },
+ _count: { id: true },
+ })
+ : Promise.resolve([]),
]);
- return { data, total };
+
+ const totalMap = new Map(
+ (totalCounts as { jobTitleId: string; _count: { id: number } }[]).map(
+ (r) => [r.jobTitleId, r._count.id],
+ ),
+ );
+
+ const dataWithTotal = countBy
+ ? (data as any[]).map((title) => ({
+ ...title,
+ _count: {
+ ...(title._count ?? {}),
+ jobsTotal: totalMap.get(title.id) ?? 0,
+ },
+ }))
+ : data;
+
+ return { data: dataWithTotal, total };
} catch (error) {
const msg = "Failed to fetch job title list. ";
return handleError(error, msg);
@@ -127,6 +153,7 @@ export const deleteJobTitleById = async (
const jobs = await prisma.job.count({
where: {
jobTitleId,
+ userId: user.id,
},
});
diff --git a/src/components/admin/CompaniesTable.tsx b/src/components/admin/CompaniesTable.tsx
index 05dc52f..57f3cce 100644
--- a/src/components/admin/CompaniesTable.tsx
+++ b/src/components/admin/CompaniesTable.tsx
@@ -41,12 +41,14 @@ function CompaniesTable({
});
const onDeleteCompany = (company: Company) => {
- if (company._count?.jobsApplied! > 0) {
+ const totalJobs = company._count?.jobsTotal ?? 0;
+ if (totalJobs > 0) {
setAlert({
openState: true,
- title: "Applied jobs exist!",
- description:
- "Associated jobs applied must be 0 to be able to delete this company",
+ title: "Associated jobs exist!",
+ description: `This company has ${totalJobs} associated job${
+ totalJobs === 1 ? "" : "s"
+ } (applied or not). Remove or reassign them before deleting this company.`,
deleteAction: false,
});
} else {
@@ -87,6 +89,7 @@ function CompaniesTable({
</TableHead>
<TableHead>Company Name</TableHead>
<TableHead className="hidden sm:table-cell">Value</TableHead>
+ <TableHead>Total Jobs</TableHead>
<TableHead>Jobs Applied</TableHead>
<TableHead>Rejected</TableHead>
<TableHead>Actions</TableHead>
@@ -111,6 +114,18 @@ function CompaniesTable({
<TableCell className="font-medium hidden sm:table-cell">
{company.value}
</TableCell>
+ <TableCell className="font-medium">
+ {company._count?.jobsTotal ? (
+ <Link
+ href={`/dashboard/myjobs?company=${encodeURIComponent(company.value)}`}
+ className="text-primary underline-offset-4 hover:underline"
+ >
+ {company._count.jobsTotal}
+ </Link>
+ ) : (
+ (company._count?.jobsTotal ?? 0)
+ )}
+ </TableCell>
<TableCell className="font-medium">
{company._count?.jobsApplied ? (
<Link
diff --git a/src/components/admin/JobLocationsTable.tsx b/src/components/admin/JobLocationsTable.tsx
index 8de7afb..83cf803 100644
--- a/src/components/admin/JobLocationsTable.tsx
+++ b/src/components/admin/JobLocationsTable.tsx
@@ -39,12 +39,14 @@ function JobLocationsTable({
deleteAction: false,
});
const onDeleteJobLocation = (location: JobLocation) => {
- if (location._count?.jobsApplied! > 0) {
+ const totalJobs = location._count?.jobsTotal ?? 0;
+ if (totalJobs > 0) {
setAlert({
openState: true,
- title: "Applied jobs exist!",
- description:
- "Associated jobs applied must be 0 to be able to delete this job location",
+ title: "Associated jobs exist!",
+ description: `This location has ${totalJobs} associated job${
+ totalJobs === 1 ? "" : "s"
+ } (applied or not). Remove or reassign them before deleting this location.`,
deleteAction: false,
});
} else {
@@ -80,6 +82,7 @@ function JobLocationsTable({
<TableRow>
<TableHead>Location</TableHead>
<TableHead className="hidden sm:table-cell">Value</TableHead>
+ <TableHead>Total Jobs</TableHead>
<TableHead>Jobs Applied</TableHead>
<TableHead>Actions</TableHead>
<TableHead>
@@ -95,6 +98,18 @@ function JobLocationsTable({
<TableCell className="font-medium hidden sm:table-cell">
{location.value}
</TableCell>
+ <TableCell className="font-medium">
+ {location._count?.jobsTotal ? (
+ <Link
+ href={`/dashboard/myjobs?location=${encodeURIComponent(location.value)}`}
+ className="text-primary underline-offset-4 hover:underline"
+ >
+ {location._count.jobsTotal}
+ </Link>
+ ) : (
+ (location._count?.jobsTotal ?? 0)
+ )}
+ </TableCell>
<TableCell className="font-medium">
{location._count?.jobsApplied ? (
<Link
diff --git a/src/components/admin/JobSourcesTable.tsx b/src/components/admin/JobSourcesTable.tsx
index 4506806..8694646 100644
--- a/src/components/admin/JobSourcesTable.tsx
+++ b/src/components/admin/JobSourcesTable.tsx
@@ -40,12 +40,14 @@ function JobSourcesTable({
});
const onDeleteJobSource = (source: JobSource) => {
- if (source._count?.jobsApplied! > 0) {
+ const totalJobs = source._count?.jobsTotal ?? 0;
+ if (totalJobs > 0) {
setAlert({
openState: true,
- title: "Applied jobs exist!",
- description:
- "Associated jobs applied must be 0 to be able to delete this job source",
+ title: "Associated jobs exist!",
+ description: `This source has ${totalJobs} associated job${
+ totalJobs === 1 ? "" : "s"
+ } (applied or not). Remove or reassign them before deleting this source.`,
deleteAction: false,
});
} else {
@@ -83,6 +85,7 @@ function JobSourcesTable({
<TableRow>
<TableHead>Source</TableHead>
<TableHead className="hidden sm:table-cell">Value</TableHead>
+ <TableHead>Total Jobs</TableHead>
<TableHead>Jobs Applied</TableHead>
<TableHead>Actions</TableHead>
<TableHead>
@@ -98,6 +101,18 @@ function JobSourcesTable({
<TableCell className="font-medium hidden sm:table-cell">
{source.value}
</TableCell>
+ <TableCell className="font-medium">
+ {source._count?.jobsTotal ? (
+ <Link
+ href={`/dashboard/myjobs?source=${encodeURIComponent(source.value)}`}
+ className="text-primary underline-offset-4 hover:underline"
+ >
+ {source._count.jobsTotal}
+ </Link>
+ ) : (
+ (source._count?.jobsTotal ?? 0)
+ )}
+ </TableCell>
<TableCell className="font-medium">
{source._count?.jobsApplied ? (
<Link
diff --git a/src/components/admin/JobTitlesTable.tsx b/src/components/admin/JobTitlesTable.tsx
index 21caf50..de68bb9 100644
--- a/src/components/admin/JobTitlesTable.tsx
+++ b/src/components/admin/JobTitlesTable.tsx
@@ -37,12 +37,14 @@ function JobTitlesTable({ jobTitles, reloadJobTitles }: JobTitlesTableProps) {
});
const onDeleteJobTitle = (title: JobTitle) => {
- if (title._count?.jobs! > 0) {
+ const totalJobs = title._count?.jobsTotal ?? 0;
+ if (totalJobs > 0) {
setAlert({
openState: true,
- title: "Applied jobs exist!",
- description:
- "Associated jobs applied must be 0 to be able to delete this job title",
+ title: "Associated jobs exist!",
+ description: `This job title has ${totalJobs} associated job${
+ totalJobs === 1 ? "" : "s"
+ } (applied or not). Remove or reassign them before deleting this job title.`,
deleteAction: false,
});
} else {
@@ -79,6 +81,7 @@ function JobTitlesTable({ jobTitles, reloadJobTitles }: JobTitlesTableProps) {
<TableRow>
<TableHead>Job Title</TableHead>
<TableHead className="hidden sm:table-cell">Value</TableHead>
+ <TableHead>Total Jobs</TableHead>
<TableHead>Jobs Applied</TableHead>
<TableHead>Actions</TableHead>
<TableHead>
@@ -94,6 +97,18 @@ function JobTitlesTable({ jobTitles, reloadJobTitles }: JobTitlesTableProps) {
<TableCell className="font-medium hidden sm:table-cell">
{title.value}
</TableCell>
+ <TableCell className="font-medium">
+ {title._count?.jobsTotal ? (
+ <Link
+ href={`/dashboard/myjobs?title=${encodeURIComponent(title.value)}`}
+ className="text-primary underline-offset-4 hover:underline"
+ >
+ {title._count.jobsTotal}
+ </Link>
+ ) : (
+ (title._count?.jobsTotal ?? 0)
+ )}
+ </TableCell>
<TableCell className="font-medium">
{title._count?.jobs ? (
<Link
diff --git a/src/models/job.model.ts b/src/models/job.model.ts
index 1402145..f6a27fa 100644
--- a/src/models/job.model.ts
+++ b/src/models/job.model.ts
@@ -66,6 +66,7 @@ export interface JobTitle {
createdBy: string;
_count?: {
jobs: number;
+ jobsTotal?: number;
};
}
@@ -78,6 +79,7 @@ export interface Company {
_count?: {
jobsApplied: number;
jobsRejected?: number;
+ jobsTotal?: number;
};
}
@@ -94,6 +96,7 @@ export interface JobSource {
createdBy: string;
_count?: {
jobsApplied: number;
+ jobsTotal?: number;
};
}
@@ -106,6 +109,7 @@ export interface JobLocation {
createdBy: string;
_count?: {
jobsApplied: number;
+ jobsTotal?: number;
};
}