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
+19
View File
@@ -58,3 +58,22 @@ exports.seedDatabase = catchAsync(async (req, res, next) => {
data: result,
})
})
exports.getAutoSaveSetting = catchAsync(async (req, res, next) => {
const result = await settingService.getAutoSaveSetting()
res.status(200).json({
status: 'success',
data: result,
})
})
exports.updateAutoSaveSetting = catchAsync(async (req, res, next) => {
const { enabled, intervalSeconds } = req.body
const result = await settingService.updateAutoSaveSetting({ enabled, intervalSeconds })
res.status(200).json({
status: 'success',
data: result,
})
})
+12
View File
@@ -43,4 +43,16 @@ router.post(
settingController.seedDatabase
)
router.get(
'/autosave',
perm.requires('admindashboard', 'viewdashboard', 'getallpermissions'),
settingController.getAutoSaveSetting
)
router.put(
'/autosave',
perm.requires('admindashboard', 'viewdashboard', 'getallpermissions'),
settingController.updateAutoSaveSetting
)
module.exports = router
+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,
}