fix: 🐛 修复系统配置页保存配置的bug
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user