Skip to content

Commit

Permalink
fix: remove cancelled job option and optimize job proposals query (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedSobhy01 authored Dec 22, 2024
1 parent 86bab59 commit d7c2771
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 0 additions & 1 deletion client/src/pages/Admin/Jobs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ const Jobs = () => {
<option value="in_progress">In Progress</option>
<option value="completed">Completed</option>
<option value="closed">Closed</option>
<option value="cancelled">Cancelled</option>
</select>
</div>

Expand Down
23 changes: 16 additions & 7 deletions server/src/controllers/adminControllers/jobController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,29 @@ export async function getJobs(req: Request, res: Response): Promise<void> {

const jobsQuery = await db.query(queryString, queryParams);

const jobPrposalsQuery = await db.query(
`
let jobPrposalsQuery = { rows: [] };

if (jobsQuery.rows.length !== 0)
jobPrposalsQuery = await db.query(
`
SELECT job_id, COUNT(*) AS proposals_count
FROM proposals
WHERE job_id IN (${jobsQuery.rows.map((job) => job.id).join(',')})
GROUP BY job_id
`,
);

const jobProposalsMap = jobPrposalsQuery.rows.reduce(
(
acc: { [key: string]: number },
row: { job_id: string; proposals_count: number },
) => {
acc[row.job_id] = row.proposals_count;
return acc;
},
{},
);

const jobProposalsMap = jobPrposalsQuery.rows.reduce((acc, row) => {
acc[row.job_id] = row.proposals_count;
return acc;
}, {});

const jobs = jobsQuery.rows.map((job) => {
return {
id: job.id,
Expand Down

0 comments on commit d7c2771

Please sign in to comment.