Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added department methods #9

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -301,4 +300,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);
}
});
});