Skip to content

Commit

Permalink
Merge pull request #9 from Hossain2024/backend_methods
Browse files Browse the repository at this point in the history
Added department methods
  • Loading branch information
Hossain2024 authored Mar 6, 2025
2 parents 9ad0a10 + b695a95 commit f6dd3f3
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion EmployeeManagementBackend/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const express = require('express')
const mysql = require('mysql2')
const cors = require('cors')
Expand Down Expand Up @@ -312,4 +311,29 @@ app.get('/leave-requests', (req, res) => {
}
});
});

/**
* get project and nubmer of emplyees for a particualr project
*/
app.get('/departments', (req, res) => {
const query = `
SELECT
d.Dept_Name,
d.Dept_Description,
d.Num_Of_Employees,
COUNT(p.ProjectID) AS TotalProjects,
GROUP_CONCAT(p.Name SEPARATOR ', ') AS ProjectNames
FROM Department d
LEFT JOIN Project p ON d.DepartmentID = p.DepartmentID
GROUP BY d.DepartmentID;
`;

db.query(query, (err, results) => {
if (err) {
res.status(500).json({ error: 'Failed to fetch departments and projects' });
} else {
res.json(results);
}
});
});

0 comments on commit f6dd3f3

Please sign in to comment.