From 7f986fdb2da732436cd40348927b6f76bfc9e00f Mon Sep 17 00:00:00 2001 From: whyour Date: Fri, 21 Jan 2022 22:27:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/user.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/back/services/user.ts b/back/services/user.ts index a50793a5..33ee3f83 100644 --- a/back/services/user.ts +++ b/back/services/user.ts @@ -313,8 +313,16 @@ export default class UserService { } private async updateAuthDb(payload: AuthInfo): Promise { - await AuthModel.upsert({ ...payload }); - const doc = await this.getDb({ type: payload.type }); + let doc = await AuthModel.findOne({ type: payload.type }); + if (doc) { + const updateResult = await AuthModel.update(payload, { + where: { id: doc.id }, + returning: true, + }); + doc = updateResult[1][0]; + } else { + doc = await AuthModel.create(payload, { returning: true }); + } return doc; }