diff --git a/resources/Attendance/AttandanceRoute.js b/resources/Attendance/AttandanceRoute.js index 6fe1f20..e074d26 100644 --- a/resources/Attendance/AttandanceRoute.js +++ b/resources/Attendance/AttandanceRoute.js @@ -1,45 +1,3 @@ -// import express from "express"; -// import { -// markAttendance, -// getAttendanceBySalesCoordinator, -// getTodayAttendance, -// AdmingetAttendanceBySalesCoordinator, -// } from "./AttandanceController.js"; -// import { isAuthenticatedSalesCoOrdinator } from "../../middlewares/SalesCoOrdinatorAuth.js"; -// import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js"; - -// const router = express.Router(); - -// // Place more specific routes first - -// // Route to get today's attendance for admin -// router.get( -// "/attendance/today", -// isAuthenticatedUser, -// authorizeRoles("admin"), -// getTodayAttendance -// ); - -// // Route to mark attendance -// router.post("/attendance", isAuthenticatedSalesCoOrdinator, markAttendance); - -// // Route to get attendance for the logged-in sales coordinator -// router.get( -// "/attendance", -// isAuthenticatedSalesCoOrdinator, -// getAttendanceBySalesCoordinator -// ); - -// // Admin route to get attendance by sales coordinator ID -// router.get( -// "/attendance/:id", -// isAuthenticatedUser, -// authorizeRoles("admin"), -// AdmingetAttendanceBySalesCoordinator -// ); - -// export default router; - import express from "express"; import { markAttendance, diff --git a/resources/Attendance/AttendanceController.js b/resources/Attendance/AttendanceController.js index c016460..0f371e0 100644 --- a/resources/Attendance/AttendanceController.js +++ b/resources/Attendance/AttendanceController.js @@ -1,78 +1,6 @@ import { Attendance } from "./AttendanceModel.js"; // Mark attendance -// export const markAttendance = async (req, res) => { -// try { -// const { date, time, location, notes } = req.body; -// const userId = req.user._id; -// const userType = req.userType; - -// // Parse the input date -// const [year, month, day] = date.split("/"); -// const parsedDate = new Date(Date.UTC(year, month - 1, day)); -// const today = new Date(); -// today.setUTCHours(0, 0, 0, 0); -// // Check if the date in req.body is not today's date -// if (parsedDate.getTime() !== today.getTime()) { -// return res.status(400).json({ -// success: false, -// message: `Leave can only be marked for today's date: ${ -// today.toISOString().split("T")[0] -// }`, -// }); -// } -// // Get the start and end of the day to check if the leave is already marked -// const startOfDay = new Date(parsedDate); -// const endOfDay = new Date(parsedDate); -// endOfDay.setUTCHours(23, 59, 59, 999); - -// // Check if the attendance record exists for today -// const existingAttendance = await Attendance.findOne({ -// userId, -// userType, -// records: { -// $elemMatch: { -// date: { $gte: startOfDay, $lte: endOfDay }, -// }, -// }, -// }); - -// if (existingAttendance) { -// return res.status(400).json({ -// success: false, -// message: "Attendance for today is already marked.", -// }); -// } - -// // Check if attendance record exists for the user -// let attendance = await Attendance.findOne({ userId, userType }); - -// if (!attendance) { -// // Create a new attendance record if it doesn't exist -// attendance = new Attendance({ -// userId, -// userType, -// records: [], -// }); -// } - -// // Add the new attendance record to the array -// attendance.records.push({ date: startOfDay, time, location, notes }); -// await attendance.save(); - -// res.status(201).json({ -// success: true, -// message: "Attendance marked successfully", -// record: { date: today, time, location, notes }, -// }); -// } catch (error) { -// console.error("Error marking attendance:", error); -// res.status(500).json({ -// success: false, -// message: error.message || "Something went wrong", -// }); -// } -// }; export const markAttendance = async (req, res) => { try { const { date, time, location, notes } = req.body;