삭제처리 수정

This commit is contained in:
2025-10-23 00:50:52 +09:00
parent 4a3a24e327
commit 76f5b572e8
3 changed files with 153 additions and 11 deletions
+50 -5
View File
@@ -687,7 +687,7 @@ exports.updateEvent = async (req, res) => {
}
};
// 이벤트 삭제 (소프트 삭제)
// 이벤트 삭제 (소프트 삭제: 숨김 처리)
exports.deleteEvent = async (req, res) => {
try {
const eventId = req.params.id;
@@ -716,9 +716,9 @@ exports.deleteEvent = async (req, res) => {
return res.status(404).json({ message: '이벤트를 찾을 수 없습니다.' });
}
// 참가자 정보도 함께 삭제 처리
// 참가자 소프트 삭제(취소 상태로 표시)
await EventParticipant.update(
{ status: '취소' },
{ status: 'canceled' },
{
where: {
eventId,
@@ -727,10 +727,11 @@ exports.deleteEvent = async (req, res) => {
}
);
await event.update({ status: '삭제' });
// 이벤트 숨김 처리(표준 상태값 사용)
await event.update({ status: 'deleted' });
res.json({
message: '이벤트가 삭제되었습니다.',
message: '이벤트가 숨김(소프트 삭제)되었습니다.',
event: {
id: event.id,
title: event.title,
@@ -744,6 +745,50 @@ exports.deleteEvent = async (req, res) => {
}
};
// 이벤트 완전 삭제 (하드 삭제): 팀배정, 점수, 참가자, 팀, 이벤트 순서로 물리 삭제
exports.deleteEventPermanently = async (req, res) => {
try {
const eventId = Number(req.params.id);
const { clubId } = req.body || {};
const cid = Number(clubId);
if (!eventId || !cid) {
return res.status(400).json({ message: '이벤트 ID와 클럽 ID가 필요합니다.' });
}
await sequelize.transaction(async (t) => {
const event = await Event.findOne({ where: { id: eventId, clubId: cid }, transaction: t });
if (!event) {
throw new Error('이벤트를 찾을 수 없습니다.');
}
// 팀멤버 삭제
const teams = await EventTeam.findAll({ where: { eventId }, transaction: t });
const teamIds = teams.map((tm) => tm.id);
if (teamIds.length > 0) {
await EventTeamMember.destroy({ where: { eventTeamId: teamIds }, transaction: t });
}
// 점수 삭제
await EventScore.destroy({ where: { eventId }, transaction: t });
// 참가자 삭제
await EventParticipant.destroy({ where: { eventId }, transaction: t });
// 팀 삭제
await EventTeam.destroy({ where: { eventId }, transaction: t });
// 이벤트 삭제
await Event.destroy({ where: { id: eventId, clubId: cid }, transaction: t });
});
res.json({ message: '이벤트 및 관련 데이터가 완전히 삭제되었습니다.' });
} catch (error) {
console.error('이벤트 완전 삭제 오류:', error);
res.status(500).json({ message: '이벤트 완전 삭제 중 오류가 발생했습니다.' });
}
};
// 이벤트 점수 조회
exports.getEventScores = async (req, res) => {
try {