-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastián
committed
Jan 16, 2025
1 parent
0146c1d
commit 9f89590
Showing
5 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const { connectToDatabase } = require('../db/dbConfig'); | ||
|
||
// Route to get employee_id from email | ||
router.get('/:email', async (req, res) => { | ||
const { email } = req.params; | ||
try { | ||
const pool = await connectToDatabase(); | ||
const result = await pool.request() | ||
.input('email', email) | ||
.query(` | ||
SELECT employee_id | ||
FROM roster | ||
WHERE email_surgical = @email | ||
`); | ||
|
||
if (result.recordset.length === 0) { | ||
console.log(`No employee found for email: ${email}`); | ||
return res.status(404).json({ message: 'No employee found with this email' }); | ||
} | ||
|
||
res.json(result.recordset[0]); // Return the first matching record | ||
} catch (err) { | ||
console.error(`Error fetching employee ID for email ${email}:`, err); | ||
res.status(500).json({ message: 'Server error', error: err.message }); | ||
} | ||
}); | ||
|
||
// Export the router | ||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const { connectToDatabase } = require('../db/dbConfig'); | ||
|
||
// Route to fetch all employees under a specific leader | ||
router.get('/:leader_email', async (req, res) => { | ||
const { leader_email } = req.params; | ||
|
||
try { | ||
const pool = await connectToDatabase(); | ||
|
||
// Query using a recursive CTE to get hierarchical employees | ||
const result = await pool.request() | ||
.input('leader_email', leader_email) | ||
.query(` | ||
WITH RecursiveEmployees AS ( | ||
SELECT * | ||
FROM dbo.roster | ||
WHERE leader_email = @leader_email | ||
UNION ALL | ||
SELECT r.* | ||
FROM dbo.roster r | ||
INNER JOIN RecursiveEmployees re | ||
ON r.leader_email = re.email_surgical | ||
) | ||
SELECT * | ||
FROM RecursiveEmployees | ||
ORDER BY name ASC; | ||
`); | ||
|
||
if (result.recordset.length === 0) { | ||
console.log(`No employees found under leader email: ${leader_email}`); | ||
return res.status(404).json({ message: 'No employees found under this leader' }); | ||
} | ||
|
||
res.json(result.recordset); // Return hierarchical records | ||
} catch (err) { | ||
console.error(`Error fetching employees under leader email ${leader_email}:`, err); | ||
res.status(500).json({ message: 'Server error', error: err.message }); | ||
} | ||
}); | ||
|
||
module.exports = router; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const { connectToDatabase } = require('../db/dbConfig'); | ||
|
||
|
||
router.get('/:employee_id', async (req, res) => { | ||
const { employee_id } = req.params; | ||
try { | ||
const pool = await connectToDatabase(); | ||
const result = await pool.request() | ||
|
||
.input('employee_id', employee_id) | ||
.query(` | ||
SELECT * | ||
FROM vacations | ||
WHERE employee_id = @employee_id | ||
`); | ||
|
||
if (result.recordset.length === 0) { | ||
// Log if no records are found | ||
console.log(`No vacation data found for employee ID: ${employee_id}`); | ||
return res.status(404).json({ message: 'No vacation data found for this employee' }); | ||
} | ||
|
||
res.json(result.recordset[0]); // Return the first matching record | ||
} catch (err) { | ||
// Log detailed error for debugging | ||
console.error(`Error fetching vacation data for employee ID ${employee_id}:`, err); | ||
res.status(500).json({ message: 'Server error', error: err.message }); | ||
} | ||
}); | ||
|
||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters