From a277b8515fccc50b813d6b087bc22d24808d0fa8 Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Fri, 1 Nov 2024 16:51:02 -0400 Subject: [PATCH] fix (#17441) --- .../app-store/googlecalendar/api/callback.ts | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/app-store/googlecalendar/api/callback.ts b/packages/app-store/googlecalendar/api/callback.ts index cd18e3cd26..020f26fc65 100644 --- a/packages/app-store/googlecalendar/api/callback.ts +++ b/packages/app-store/googlecalendar/api/callback.ts @@ -191,23 +191,19 @@ async function updateProfilePhoto(oAuth2Client: Auth.OAuth2Client, userId: numbe const oauth2 = google.oauth2({ version: "v2", auth: oAuth2Client }); const userDetails = await oauth2.userinfo.get(); if (userDetails.data?.picture) { - // Check if the user has no avatar - const user = await prisma.user.findFirst({ + // Using updateMany here since if the user already has a profile it would throw an error + // because no records were found to update the profile picture + await prisma.user.updateMany({ where: { id: userId, - avatarUrl: null, - }, - select: { id: true }, - }); - - if (user) { - await prisma.user.update({ - where: { id: userId }, - data: { - avatarUrl: userDetails.data.picture, + avatarUrl: { + equals: null, }, - }); - } + }, + data: { + avatarUrl: userDetails.data.picture, + }, + }); } } catch (error) { logger.error("Error updating avatarUrl from google calendar connect", error);