webupdate
This commit is contained in:
@@ -891,12 +891,22 @@ const settingsHandler = (key) => ({
|
||||
sendSuccess(res, { settings });
|
||||
}),
|
||||
post: asyncHandler(async (req, res) => {
|
||||
const settings = req.body;
|
||||
const newSettings = req.body;
|
||||
// Get existing settings first and merge
|
||||
const existingResult = await query(
|
||||
"SELECT settings FROM site_settings WHERE key = $1",
|
||||
[key],
|
||||
);
|
||||
const existingSettings =
|
||||
existingResult.rows.length > 0 ? existingResult.rows[0].settings : {};
|
||||
// Merge new settings with existing (new settings overwrite existing for same keys)
|
||||
const mergedSettings = { ...existingSettings, ...newSettings };
|
||||
|
||||
await query(
|
||||
`INSERT INTO site_settings (key, settings, updatedat)
|
||||
VALUES ($1, $2, NOW())
|
||||
ON CONFLICT (key) DO UPDATE SET settings = $2, updatedat = NOW()`,
|
||||
[key, JSON.stringify(settings)],
|
||||
[key, JSON.stringify(mergedSettings)],
|
||||
);
|
||||
sendSuccess(res, { message: `${key} settings saved successfully` });
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user