Skip to content

Commit

Permalink
#5 [feat] create updateUserAttendance function
Browse files Browse the repository at this point in the history
  • Loading branch information
OH-GITAEK committed May 28, 2024
1 parent 1037e77 commit 851ee9e
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 60 deletions.
30 changes: 30 additions & 0 deletions api/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,33 @@ exports.checkAttencance = async(req, res) => {
res.status(500).send({message: "Error Checking Attendance"});
}
};

exports.updateUserAttendance = async (req, res) => {
try {
const { userId, sessionId, attendIdx, status } = req.body;

// 해당하는 유저의 원하는 날의 세션 찾기
const attendance = await Attend.findOne({ user: userId, session: sessionId });

if (!attendance) {
return res.status(404).json({ message: 'Attendance record not found' });
}

// 해당 인덱스의 출석 찾기
const attendTime = attendance.attendList.find(time => time.attendIdx === attendIdx);

if (!attendTime) {
return res.status(404).json({ message: 'Attendance entry not found' });
}

// 상태 업데이트하기
attendTime.status = status;

// DB에 업데이트
await attendance.save();

res.status(200).json({ message: 'Attendance updated successfully', attendance });
} catch (error) {
res.status(500).json({ message: 'Server error', error });
}
};
148 changes: 88 additions & 60 deletions api/routers/userRouters.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ router.delete("/users/:id", authenticateToken, userController.deleteUser);
// 유저 -> 관리자
router.put("/users/:id/admin", authenticateToken, adminMiddleware, userController.updateUserToAdmin);
// 특정 유저의 출석 정보 변경
// router.put("/users/:id/attendance", authenticateToken, adminMiddleware, userController.updateUserAttendance);
router.put("/users/:id/attendance", authenticateToken, adminMiddleware, userController.updateUserAttendance);

//인증 이메일 전송
router.post('/signup/send', emailConfig.sendEmail);
Expand All @@ -40,8 +40,8 @@ module.exports = router;
* description: 관리자 관련 작업
*/


/**
*
* @swagger
* paths:
* /api/user/signup:
Expand Down Expand Up @@ -207,7 +207,7 @@ module.exports = router;
* description: "사용자를 찾을 수 없음"
* 500:
* description: "서버 오류"
* /api/user/users/{id}/admin:
* /api/user/users/{id}/admin:
* put:
* summary: "유저를 관리자 권한으로 업데이트"
* tags: [Admin]
Expand Down Expand Up @@ -238,90 +238,117 @@ module.exports = router;
* description: "서버 오류"
* /api/user/users/{id}/attendance:
* put:
* summary: "유저의 출석 정보를 업데이트"
* summary: Update attendance status for a specific user and session
* tags: [Admin]
* security:
* - BearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: "업데이트할 사용자의 ID"
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* attendance:
* userId:
* type: string
* description: The ID of the user
* example: "664c8a6f2fb638f06aef242f"
* sessionId:
* type: string
* description: The ID of the session
* example: "6655b4c0e76a7861f29d527f"
* attendIdx:
* type: number
* description: The index of the specific attendance entry within the session
* example: 1
* status:
* type: boolean
* description: The new status value (true or false)
* example: true
* responses:
* 200:
* description: "사용자 출석 정보 업데이트 성공"
* description: Attendance updated successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: Attendance updated successfully
* attendance:
* type: object
* description: The updated attendance document
* 404:
* description: "사용자를 찾을 수 없음"
* description: Attendance record not found
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: Attendance record not found
* 500:
* description: "서버 오류"
*
* /api/user/signup/send:
* post:
* description: Server error
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: Server error
* error:
* type: string
* example: error details
* /api/user/signup/send:
* post:
* summary: "인증 이메일 전송"
* description: "사용자가 회원가입 시 입력한 이메일 주소로 인증 이메일을 전송합니다."
* tags: [Users]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - email
* properties:
* email:
* type: string
* description: "인증 이메일을 받을 사용자의 이메일 주소"
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - email
* properties:
* email:
* type: string
* description: "인증 이메일을 받을 사용자의 이메일 주소"
* responses:
* 200:
* description: "이메일 전송 성공"
* 400:
* description: "이메일 형식 오류 또는 필수 정보"
* 500:
* description: "서버 오류"
*
*
* /api/user/signup/cert:
* post:
* 200:
* description: "이메일 전송 성공"
* 400:
* description: "이메일 형식 오류 또는 필수 정보"
* 500:
* description: "서버 오류"
* /api/user/signup/cert:
* post:
* summary: "이메일로 받은 코드 인증"
* description: "사용자가 이메일로 받은 인증 코드를 제출하여 인증 절차를 완료합니다."
* tags: [Users]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - code
* properties:
* code:
* type: string
* description: "이용자가 입력한 코드"
* responses:
* 200:
* description: "코드 인증 성공"
* 400:
* description: "잘못된 코드 또는 이메일"
* 500:
* description: "서버 오류"
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - code
* properties:
* code:
* type: string
* description: "이용자가 입력한 코드"
* /api/user/checkAttendance/{id}:
* get:
* summary: Check attendance for a user
* tags: [Users]
* security:
* - BearerAuth: []
* - BearerAuth: []
* parameters:
* - in: path
* name: id
Expand Down Expand Up @@ -358,7 +385,6 @@ module.exports = router;
* description: Attendance information not found
* 500:
* description: Error checking attendance
*
* components:
* schemas:
* User:
Expand All @@ -376,4 +402,6 @@ module.exports = router;
* password:
* type: string
* description: "유저의 비밀번호"
*/
*
*
* */

0 comments on commit 851ee9e

Please sign in to comment.