fix: 🐛 修复系统配置页保存配置的bug

This commit is contained in:
Stev_Wang
2025-12-23 10:44:39 +08:00
parent 18b65d4635
commit a670270d87
5 changed files with 41 additions and 19 deletions

View File

@@ -69,11 +69,25 @@ export class ConfigService {
*/
async update(key: string, value: string, description?: string) {
try {
// 更新数据库
await this.configRepository.upsert(
{ key, value, description },
['key']
)
// 先查找记录是否存在
const existingConfig = await this.configRepository.findOne({ where: { key } })
if (existingConfig) {
// 记录存在,更新它
existingConfig.value = value
if (description !== undefined) {
existingConfig.description = description
}
await this.configRepository.save(existingConfig)
} else {
// 记录不存在,创建新记录
const newConfig = this.configRepository.create({
key,
value,
description
})
await this.configRepository.save(newConfig)
}
// 更新缓存
this.configCache[key] = value