From 2d5184a0ee3329d50251c1136395186ee91f72a0 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Fri, 13 Feb 2026 00:28:06 +0100 Subject: [PATCH] Fix: update avatar pic to be the same as pinned profile pic --- backend/api/src/update-profile.ts | 5 +++-- backend/api/tests/unit/update-profile.unit.test.ts | 12 ++++++------ backend/supabase/user_events.sql | 3 +++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/api/src/update-profile.ts b/backend/api/src/update-profile.ts index e58e2d0c..7a3d78c0 100644 --- a/backend/api/src/update-profile.ts +++ b/backend/api/src/update-profile.ts @@ -29,8 +29,9 @@ export const updateProfile: APIHandler<'update-profile'> = async ( log('Updating profile', { userId: auth.uid, parsedBody }) await removePinnedUrlFromPhotoUrls(parsedBody) - if (parsedBody.avatar_url) { - await updateUser(pg, auth.uid, { avatarUrl: parsedBody.avatar_url }) + + if (parsedBody.pinned_url) { + await updateUser(pg, auth.uid, {avatarUrl: parsedBody.pinned_url}) } const { data, error } = await tryCatch( diff --git a/backend/api/tests/unit/update-profile.unit.test.ts b/backend/api/tests/unit/update-profile.unit.test.ts index 4807942c..988262fd 100644 --- a/backend/api/tests/unit/update-profile.unit.test.ts +++ b/backend/api/tests/unit/update-profile.unit.test.ts @@ -4,13 +4,13 @@ jest.mock("common/util/try-catch"); jest.mock("shared/profiles/parse-photos"); jest.mock("shared/supabase/users"); -import { updateProfile } from "api/update-profile"; -import { AuthedUser } from "api/helpers/endpoint"; +import {updateProfile} from "api/update-profile"; +import {AuthedUser} from "api/helpers/endpoint"; import * as supabaseInit from "shared/supabase/init"; import * as supabaseUtils from "shared/supabase/utils"; import * as supabaseUsers from "shared/supabase/users"; -import { tryCatch } from "common/util/try-catch"; -import { removePinnedUrlFromPhotoUrls } from "shared/profiles/parse-photos"; +import {tryCatch} from "common/util/try-catch"; +import {removePinnedUrlFromPhotoUrls} from "shared/profiles/parse-photos"; describe('updateProfiles', () => { let mockPg: any; @@ -30,7 +30,7 @@ describe('updateProfiles', () => { describe('when given valid input', () => { it('should update an existing profile when provided the user id', async () => { const mockProps = { - avatar_url: "mockAvatarUrl" + pinned_url: "mockAvatarUrl" }; const mockAuth = { uid: '321' } as AuthedUser; const mockReq = {} as any; @@ -54,7 +54,7 @@ describe('updateProfiles', () => { expect(supabaseUsers.updateUser).toBeCalledWith( expect.any(Object), mockAuth.uid, - {avatarUrl: mockProps.avatar_url} + {avatarUrl: mockProps.pinned_url} ); expect(supabaseUtils.update).toBeCalledTimes(1); expect(supabaseUtils.update).toBeCalledWith( diff --git a/backend/supabase/user_events.sql b/backend/supabase/user_events.sql index ad4ccf6b..8140d1c5 100644 --- a/backend/supabase/user_events.sql +++ b/backend/supabase/user_events.sql @@ -9,6 +9,9 @@ CREATE TABLE IF NOT EXISTS user_events ( user_id TEXT ); +alter table user_events + add constraint user_events_user_id_fkey foreign key (user_id) references users (id) ON DELETE set null; + -- Row Level Security ALTER TABLE user_events ENABLE ROW LEVEL SECURITY;