Skip to content
Snippets Groups Projects
Commit 9f0dcff2 authored by 조대희's avatar 조대희
Browse files

feat/refactor: 모임 삭제, 상세조회 res 수정

parent 983b0b1e
No related branches found
No related tags found
1 merge request!43배포코드 master브랜치로
...@@ -166,6 +166,24 @@ class MeetingController { ...@@ -166,6 +166,24 @@ class MeetingController {
} }
} }
/**
* 번개 모임 삭제
* DELETE /api/meeting/:meetingId
*/
// controllers/meetingController.js
async deleteMeeting(req, res) {
const { meetingId } = req.params;
const userId = req.user.id;
try {
await MeetingService.deleteMeeting(meetingId, userId);
res.status(200).json({ message: '모임이 삭제되었습니다.' });
} catch (err) {
console.error('모임 삭제 오류:', err);
res.status(500).json({ error: err.message || '모임 삭제 실패' });
}
}
} }
module.exports = new MeetingController(); module.exports = new MeetingController();
...@@ -13,8 +13,8 @@ class MeetingDetailResponseDTO { ...@@ -13,8 +13,8 @@ class MeetingDetailResponseDTO {
this.isScheduleConflict = isScheduleConflict; this.isScheduleConflict = isScheduleConflict;
this.participants = meeting.participants.map(participant => ({ this.participants = meeting.participants.map(participant => ({
userId: participant.user_id, userId: participant.user_id,
name: participant.participantUser ? participant.participantUser.name : 'Unknown', name: participant.user ? participant.user.name : 'Unknown',
email: participant.participantUser ? participant.participantUser.email : 'Unknown' email: participant.user ? participant.user.email : 'Unknown'
})); }));
} }
} }
......
...@@ -28,6 +28,7 @@ router.get('/:meetingId', MeetingController.getMeetingDetail); ...@@ -28,6 +28,7 @@ router.get('/:meetingId', MeetingController.getMeetingDetail);
// 번개 모임 탈퇴 // 번개 모임 탈퇴
router.delete('/:meetingId/leave', MeetingController.leaveMeeting); router.delete('/:meetingId/leave', MeetingController.leaveMeeting);
// 번개 모임 삭제
router.delete('/:meetingId', MeetingController.deleteMeeting);
module.exports = router; module.exports = router;
\ No newline at end of file
...@@ -627,6 +627,45 @@ class MeetingService { ...@@ -627,6 +627,45 @@ class MeetingService {
await meeting.decrement('cur_num', { by: 1, transaction }); await meeting.decrement('cur_num', { by: 1, transaction });
}); });
} }
async deleteMeeting(meetingId, userId) {
const meeting = await Meeting.findByPk(meetingId);
if (!meeting) {
throw new Error('모임을 찾을 수 없습니다.');
}
if (meeting.created_by !== userId) {
throw new Error('모임 생성자만 삭제할 수 있습니다.');
}
return await sequelize.transaction(async (transaction) => {
const participants = await MeetingParticipant.findAll({
where: { meeting_id: meetingId },
attributes: ['user_id'],
transaction
});
const participantIds = participants.map(p => p.user_id);
// 모든 참가자의 스케줄 삭제
await Schedule.destroy({
where: {
user_id: { [Op.in]: participantIds },
title: `번개 모임: ${meeting.title}`,
time_idx: {
[Op.between]: [meeting.time_idx_start, meeting.time_idx_end]
}
},
transaction
});
await ChatRooms.deleteOne({ chatRoomId: meeting.chatRoomId });
// 모임 관련 데이터 삭제
await meeting.destroy({ transaction });
});
}
} }
module.exports = new MeetingService(); module.exports = new MeetingService();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment