Skip to content

Commit

Permalink
Merge branch 'jhl/checkAttendance' of https://github.com/Pironeer-APP…
Browse files Browse the repository at this point in the history
  • Loading branch information
chan000518 committed May 28, 2024
2 parents 6f205fb + a917ef9 commit c874311
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions api/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,22 @@ exports.updateUserAttendance = async (req, res) => {
res.status(500).json({ message: 'Server error' });
}
};

exports.checkAttencance = async(req, res) => {
try {
var absent = 0;
const user = await User.findById(req.params.id);
const attend = await Attend.find({ user: user });
if (!attend) {
return res.status(404).send({ message: "출석 정보가 없습니다." });
}
attend.forEach(attendance => {
if (attendance.status == false) {
absent = absent +1;
}
});
res.status(200).send({ message: "출석 정보가 확인되었습니다.", attend, absent });
} catch(error) {
res.status(500).send({message: "Error Checking Attendance"});
}
};
3 changes: 2 additions & 1 deletion api/routers/userRouters.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ router.get("/users/:id", authenticateToken, userController.getUserById);
router.put("/users/:id", authenticateToken, userController.updateUser);
// 유저 삭제
router.delete('/users/:id', authenticateToken, userController.deleteUser);

// 출석 정보 확인 edited by 진혁
router.get('/checkAttendance/:id', authenticateToken, userController.checkAttencance);
module.exports = router;

/**
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"keywords": [],
"author": "",
Expand Down

0 comments on commit c874311

Please sign in to comment.