fix(server): PUT /activities/:id 改部分更新——未传字段保留原值,防止编辑页漏传清空描述

This commit is contained in:
2026-11-15 12:07:46 +08:00
parent 6297388754
commit 322bbdf47d
+14 -1
View File
@@ -1560,9 +1560,22 @@ app.put('/activities/:id', requireActivityAdmin, (req, res) => {
}
const now = new Date().toISOString();
// 部分更新:未传字段保留原值,避免编辑页漏传把描述等字段清空
const merged = {
title: title ?? activity.title,
cover_url: cover_url ?? activity.cover_url,
description: description ?? activity.description,
location: location ?? activity.location,
start_time: start_time ?? activity.start_time,
duration: duration ?? activity.duration,
max_participants: max_participants ?? activity.max_participants,
fee: fee ?? activity.fee,
organizer: organizer ?? activity.organizer,
checkin_enabled: checkin_enabled === undefined ? activity.checkin_enabled : (checkin_enabled ? 1 : 0),
};
db.prepare(`
UPDATE activities SET title = ?, cover_url = ?, description = ?, location = ?, start_time = ?, duration = ?, max_participants = ?, fee = ?, organizer = ?, checkin_enabled = ?, updated_at = ? WHERE id = ?
`).run(title, cover_url || '', description || '', location, start_time, duration || 1, max_participants || 50, fee || 0, organizer || '', checkin_enabled ? 1 : 0, now, id);
`).run(merged.title, merged.cover_url, merged.description, merged.location, merged.start_time, merged.duration, merged.max_participants, merged.fee, merged.organizer, merged.checkin_enabled, now, id);
// 更新标签
if (tags && Array.isArray(tags)) {