Skip to content

Commit

Permalink
userCheckAttendance
Browse files Browse the repository at this point in the history
  • Loading branch information
kmer1024 committed May 25, 2024
1 parent a986136 commit a917ef9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
20 changes: 20 additions & 0 deletions api/controllers/userController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const User = require('../models/user');
const Attend = require('../models/attend');
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');

Expand Down Expand Up @@ -80,3 +81,22 @@ exports.login = async (req, res) => {
res.status(500).send('Login 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 @@ -15,7 +15,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 a917ef9

Please sign in to comment.