From cecc5aeb15bfbfaee9a27df3594e5e1e215aea27 Mon Sep 17 00:00:00 2001 From: whyour Date: Wed, 1 Jan 2025 21:33:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=20SystemConfig=20=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/loaders/initData.ts | 12 +++++++++--- back/services/system.ts | 7 ++++--- back/services/user.ts | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index 4b852882..7f258f6e 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -26,9 +26,15 @@ export default async () => { const openService = Container.get(OpenService); // 初始化增加系统配置 - await SystemModel.upsert({ type: AuthDataType.systemConfig }); - await SystemModel.upsert({ type: AuthDataType.notification }); - await SystemModel.upsert({ type: AuthDataType.authConfig }); + await SystemModel.findOrCreate({ + where: { type: AuthDataType.systemConfig }, + }); + await SystemModel.findOrCreate({ + where: { type: AuthDataType.notification }, + }); + await SystemModel.findOrCreate({ + where: { type: AuthDataType.authConfig }, + }); const authConfig = await SystemModel.findOne({ where: { type: AuthDataType.authConfig }, }); diff --git a/back/services/system.ts b/back/services/system.ts index cc7aacba..afd2555b 100644 --- a/back/services/system.ts +++ b/back/services/system.ts @@ -54,13 +54,14 @@ export default class SystemService { } private async updateAuthDb(payload: SystemInfo): Promise { - await SystemModel.upsert({ ...payload }); - const doc = await this.getDb({ type: payload.type }); + const { id, ...others } = payload; + await SystemModel.update(others, { where: { id } }); + const doc = await this.getDb({ id }); return doc; } public async getDb(query: any): Promise { - const doc = await SystemModel.findOne({ where: { ...query } }); + const doc = await SystemModel.findOne({ where: query }); if (!doc) { throw new Error(`System ${JSON.stringify(query)} not found`); } diff --git a/back/services/user.ts b/back/services/user.ts index 5a951c2b..00cf1127 100644 --- a/back/services/user.ts +++ b/back/services/user.ts @@ -334,7 +334,7 @@ export default class UserService { } private async updateAuthDb(payload: SystemInfo): Promise { - let doc = await SystemModel.findOne({ type: payload.type }); + let doc = await SystemModel.findOne({ where: { type: payload.type } }); if (doc) { const updateResult = await SystemModel.update(payload, { where: { id: doc.id },