From 42a02cbb60343b7b6c717d47466d0ebb27b2e2f1 Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Fri, 1 Nov 2024 16:21:42 -0400 Subject: [PATCH] fix: update profile photo logic in google cal integration (#17438) --- .../app-store/googlecalendar/api/callback.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/app-store/googlecalendar/api/callback.ts b/packages/app-store/googlecalendar/api/callback.ts index 798e609146..cd18e3cd26 100644 --- a/packages/app-store/googlecalendar/api/callback.ts +++ b/packages/app-store/googlecalendar/api/callback.ts @@ -191,13 +191,23 @@ 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) { - // 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 }, - data: { - avatarUrl: userDetails.data.picture, + // Check if the user has no avatar + const user = await prisma.user.findFirst({ + where: { + id: userId, + avatarUrl: null, }, + select: { id: true }, }); + + if (user) { + await prisma.user.update({ + where: { id: userId }, + data: { + avatarUrl: userDetails.data.picture, + }, + }); + } } } catch (error) { logger.error("Error updating avatarUrl from google calendar connect", error);