feat(settings): add autosave settings API endpoints and persistence
deploy-chabokan / deploy (push) Canceled after 0s

This commit is contained in:
2026-08-19 07:27:07 +03:30
parent fb4a98f83c
commit 30ea3aed84
3 changed files with 72 additions and 0 deletions
+41
View File
@@ -237,6 +237,45 @@ const seedDatabase = async (userId = null) => {
}
}
const getAutoSaveSetting = async () => {
const record = await Setting.findOne({ key: 'general_autosave' }).lean()
if (record && record.extraConfig) {
return {
enabled: record.extraConfig.enabled !== undefined ? record.extraConfig.enabled : true,
intervalSeconds: Number(record.extraConfig.intervalSeconds) || 60,
updatedAt: record.updatedAt,
}
}
return {
enabled: true,
intervalSeconds: 60,
}
}
const updateAutoSaveSetting = async ({ enabled = true, intervalSeconds = 60 }) => {
const validInterval = Math.max(10, Number(intervalSeconds) || 60)
const setting = await Setting.findOneAndUpdate(
{ key: 'general_autosave' },
{
key: 'general_autosave',
category: 'general',
pageKey: 'general',
title: 'تنظیمات ذخیره خودکار (Auto-Save Settings)',
description: 'پیکربندی فعال‌سازی و فاصله زمانی ذخیره خودکار فرم‌ها',
extraConfig: {
enabled: Boolean(enabled),
intervalSeconds: validInterval,
},
},
{ upsert: true, new: true, setDefaultsOnInsert: true }
)
return {
enabled: setting.extraConfig.enabled,
intervalSeconds: setting.extraConfig.intervalSeconds,
updatedAt: setting.updatedAt,
}
}
module.exports = {
DEFAULT_SEARCH_PAGES,
getSearchSettings,
@@ -245,4 +284,6 @@ module.exports = {
bulkUpdateSearchSettings,
getSeedStatus,
seedDatabase,
getAutoSaveSetting,
updateAutoSaveSetting,
}