From 84240f57a702096f8bdb95cc239a7ffeb478cf9a Mon Sep 17 00:00:00 2001 From: Jaybe Date: Thu, 16 Oct 2025 11:11:56 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B0=B8=EA=B0=80=EB=B9=84=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/controllers/eventController.js | 40 ++++++++++++++++++-------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/backend/controllers/eventController.js b/backend/controllers/eventController.js index 42a4234..cd28c2c 100644 --- a/backend/controllers/eventController.js +++ b/backend/controllers/eventController.js @@ -199,11 +199,20 @@ exports.createEvent = async (req, res) => { const accessPassword = req.body.accessPassword || null; // 금액 통합: 문자열("20000.00") 또는 숫자를 허용, 0은 유효값(무료), 빈값은 null 처리 - let feeRaw = fee ?? entryFee ?? participantFee; + const hasFeeField = Object.prototype.hasOwnProperty.call(req.body, 'participantFee') + || Object.prototype.hasOwnProperty.call(req.body, 'entryFee') + || Object.prototype.hasOwnProperty.call(req.body, 'fee'); let feeParsed = null; - if (feeRaw !== undefined && feeRaw !== null && `${feeRaw}`.trim() !== '') { - const num = parseFloat(`${feeRaw}`); - feeParsed = Number.isFinite(num) ? num : null; + if (hasFeeField) { + const feeRaw = fee ?? entryFee ?? participantFee; + if (feeRaw === undefined || feeRaw === null || `${feeRaw}`.trim() === '') { + feeParsed = null; // 명시적 빈값 => null 저장 + } else { + const num = parseFloat(`${feeRaw}`); + feeParsed = Number.isFinite(num) ? num : null; + } + } else { + feeParsed = null; // 생성 시 미제공이면 null 유지 } const event = await Event.create({ @@ -215,7 +224,7 @@ exports.createEvent = async (req, res) => { location, maxParticipants: maxParticipants || 0, eventType: eventType || 'regular', - participantFee: feeParsed ?? 0, + participantFee: feeParsed, // allowNull=true이므로 null 저장 허용 gameCount: gameCount || 3, laneCount: laneCount || 1, status: status || 'active', @@ -609,12 +618,19 @@ exports.updateEvent = async (req, res) => { if(endDate == 'Invalid Date') { endDate = null; } - // 금액 통합: 문자열("20000.00") 또는 숫자를 허용, 0은 유효값(무료) - let feeRaw = fee ?? entryFee ?? participantFee; - let feeParsed = null; - if (feeRaw !== undefined && feeRaw !== null && `${feeRaw}`.trim() !== '') { - const num = parseFloat(`${feeRaw}`); - feeParsed = Number.isFinite(num) ? num : null; + // 금액 통합: 문자열("20000.00") 또는 숫자를 허용, 0은 유효값(무료), 빈값은 null 처리 + const hasFeeField = Object.prototype.hasOwnProperty.call(req.body, 'participantFee') + || Object.prototype.hasOwnProperty.call(req.body, 'entryFee') + || Object.prototype.hasOwnProperty.call(req.body, 'fee'); + let feeParsed = undefined; // 업데이트에서 undefined면 필드 미변경 + if (hasFeeField) { + const feeRaw = fee ?? entryFee ?? participantFee; + if (feeRaw === undefined || feeRaw === null || `${feeRaw}`.trim() === '') { + feeParsed = null; // 명시적 빈값 => null로 클리어 + } else { + const num = parseFloat(`${feeRaw}`); + feeParsed = Number.isFinite(num) ? num : null; + } } const updateData = { @@ -625,7 +641,7 @@ exports.updateEvent = async (req, res) => { location, maxParticipants: maxParticipants || event.maxParticipants, eventType: eventType || event.eventType || 'regular', - participantFee: feeParsed !== null ? feeParsed : event.participantFee, + ...(feeParsed !== undefined ? { participantFee: feeParsed } : {}), gameCount: gameCount || event.gameCount, laneCount: laneCount || event.laneCount, status: status || event.status || 'active',