Skip to content

Commit

Permalink
[merge] merge jhl/checkAttendance
Browse files Browse the repository at this point in the history
  • Loading branch information
OH-GITAEK committed May 28, 2024
2 parents a7c9907 + a917ef9 commit 92db0da
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 21 deletions.
30 changes: 15 additions & 15 deletions api/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ exports.createInitAdmin = async () => {
console.log("Admin user created");
}
} catch (error) {
console.error("Error creating admin user", error);
res.status(500).send('Login error');
}
};

Expand All @@ -124,21 +124,21 @@ exports.updateUserToAdmin = async (req, res) => {
}
};

// 특정 유저의 출석 정보 변경 (관리자 권한)
exports.updateUserAttendance = async (req, res) => {
const { id } = req.params;
const { attendance } = req.body;

exports.checkAttencance = async(req, res) => {
try {
const user = await User.findById(id);
if (!user) {
return res.status(404).json({ message: 'User not found' });
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;
}

user.attendance = attendance;
await user.save();
res.json({ message: 'User attendance status updated' });
} catch (err) {
res.status(500).json({ message: 'Server error' });
});
res.status(200).send({ message: "출석 정보가 확인되었습니다.", attend, absent });
} catch(error) {
res.status(500).send({message: "Error Checking Attendance"});
}
};
43 changes: 42 additions & 1 deletion api/routers/userRouters.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ router.put("/users/:id/admin", authenticateToken, adminMiddleware, userControlle
router.post('/signup/send', emailConfig.sendEmail);
//코드 인증
router.post('/signup/cert', emailConfig.certEmail);

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

/**
Expand Down Expand Up @@ -315,6 +316,46 @@ module.exports = router;
* description: "잘못된 코드 또는 이메일"
* 500:
* description: "서버 오류"
* /api/user/checkAttendance/{id}:
* get:
* summary: Check attendance for a user
* tags: [Users]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: User ID
* responses:
* 200:
* description: Attendance information retrieved successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* attend:
* type: array
* items:
* type: object
* properties:
* _id:
* type: string
* user:
* type: string
* date:
* type: string
* status:
* type: boolean
* absent:
* type: integer
* 404:
* description: Attendance information not found
* 500:
* description: Error checking attendance
*
* components:
* schemas:
Expand Down
8 changes: 4 additions & 4 deletions config/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const app = express();

app.use(cookieParser());

//const SMTPTransport = require('nodemailer/lib/smtp-transport');
// const SMTPTransport = require('nodemailer/lib/smtp-transport');

let transporter = nodemailer.createTransport({
service : "naver",
port: 587,
auth : {
user : process.env.user,
pass : process.env.pass,
user : process.env.USER,
pass : process.env.PASS,
},
tls : {
rejectUnauthorized : false
Expand All @@ -34,7 +34,7 @@ exports.sendEmail = async(req, res)=>{
});

const mailOptions = {
from : "[email protected]",
from : "본인이메일작성",
to: email,
subject: "인증 관련 메일입니다",
text: "인증번호는 " + authNum + " 입니다."
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 92db0da

Please sign in to comment.