Skip to content

Commit b3ef736

Browse files
committed
refactor: เพิ่มเงื่อนไขถ้าไม่มีการแก้ไขข้อมูล
1 parent 335354f commit b3ef736

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

server/src/services/events.service.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,29 @@ export async function updateEvent(evt_id: number, evt_icon: string, evt_name: st
104104
throw new Error("Event fields cannot be empty");
105105
}
106106

107+
// ดึงข้อมูลปัจจุบันทั้งหมด
107108
const eventExists = await pool.query(`
108-
SELECT evt_id FROM events
109+
SELECT evt_id, evt_icon, evt_name, evt_description
110+
FROM events
109111
WHERE evt_id = $1
110-
AND evt_is_use = true`,
111-
[evt_id]
112-
)
112+
AND evt_is_use = true
113+
`, [evt_id]);
113114

114115
if (eventExists.rows.length === 0) {
115116
throw new Error("Event not found or inactive");
116117
}
117118

119+
// เอาข้อมูลที่ดึงมาเก็บใส่ตัวแปรแล้วเทียบกับที่รับเข้ามาว่าเหมือนเดิมมั้ย
120+
const currentEvent = eventExists.rows[0];
121+
122+
if (
123+
currentEvent.evt_icon === evt_icon &&
124+
currentEvent.evt_name === evt_name &&
125+
currentEvent.evt_description === evt_des
126+
) {
127+
throw new Error("No changes detected");
128+
}
129+
118130
const { rows } = await pool.query(`
119131
UPDATE events
120132
SET evt_icon = $1,

0 commit comments

Comments
 (0)