This commit is contained in:
ROSHAN GARG 2024-08-01 16:47:51 +05:30
commit 7d01e8c255
2 changed files with 7 additions and 6 deletions

View File

@ -6,7 +6,8 @@ export const markAttendance = async (req, res) => {
const { date, time, location, notes } = req.body; const { date, time, location, notes } = req.body;
const userId = req.user._id; const userId = req.user._id;
const userType = req.userType; const userType = req.userType;
// console.log(req.user);
// console.log(req.body);
// Parse the input date // Parse the input date
const [year, month, day] = date.split("/"); const [year, month, day] = date.split("/");
const parsedDate = new Date(Date.UTC(year, month - 1, day)); const parsedDate = new Date(Date.UTC(year, month - 1, day));
@ -32,7 +33,7 @@ export const markAttendance = async (req, res) => {
const existingAttendance = await Attendance.findOne({ const existingAttendance = await Attendance.findOne({
userId, userId,
userType, userType,
'records.date': { "records.date": {
$gte: startOfDay, $gte: startOfDay,
$lte: endOfDay, $lte: endOfDay,
}, },
@ -75,7 +76,6 @@ export const markAttendance = async (req, res) => {
} }
}; };
// Get attendance by user ID // Get attendance by user ID
export const getAttendanceByUser = async (req, res) => { export const getAttendanceByUser = async (req, res) => {
try { try {
@ -116,7 +116,7 @@ export const AdmingetAttendanceByUser = async (req, res) => {
const attendanceDoc = await Attendance.findOne({ const attendanceDoc = await Attendance.findOne({
userId: id, userId: id,
}).populate("userId", "name email"); }).populate("userId", "name email");
// console.log(attendanceDoc);
if (!attendanceDoc) { if (!attendanceDoc) {
return res.status(404).json({ return res.status(404).json({
success: false, success: false,
@ -131,6 +131,7 @@ export const AdmingetAttendanceByUser = async (req, res) => {
res.status(200).json({ res.status(200).json({
success: true, success: true,
user: attendanceDoc.userId, user: attendanceDoc.userId,
userType: attendanceDoc.userType,
attendance: paginatedRecords, attendance: paginatedRecords,
total_data: totalData, total_data: totalData,
}); });

View File

@ -191,7 +191,7 @@ export const getAllTerritoryManager = async (req, res) => {
} }
const total = await TerritoryManager.countDocuments(filter); const total = await TerritoryManager.countDocuments(filter);
const salesCoOrinators = await TerritoryManager.find(filter) const territoryManager = await TerritoryManager.find(filter)
.limit(PAGE_SIZE) .limit(PAGE_SIZE)
.skip(PAGE_SIZE * page) .skip(PAGE_SIZE * page)
.sort({ createdAt: -1 }); .sort({ createdAt: -1 });
@ -200,7 +200,7 @@ export const getAllTerritoryManager = async (req, res) => {
success: true, success: true,
total_data: total, total_data: total,
total_pages: Math.ceil(total / PAGE_SIZE), total_pages: Math.ceil(total / PAGE_SIZE),
salesCoOrinators, territoryManager,
}); });
} catch (error) { } catch (error) {
res.status(500).json({ res.status(500).json({