From f3cd0bcbe6c8050d641f60d7e794c63ca8820219 Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Fri, 9 Jan 2026 08:43:51 +1100 Subject: [PATCH] Fix for storing country at registration --- src/api/user/user.service.spec.ts | 22 ++++++++++++++++++++++ src/api/user/user.service.ts | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/src/api/user/user.service.spec.ts b/src/api/user/user.service.spec.ts index 9e576d9..f568128 100644 --- a/src/api/user/user.service.spec.ts +++ b/src/api/user/user.service.spec.ts @@ -1145,6 +1145,28 @@ describe('UserService', () => { expect(result).toEqual(mockCreatedUser); }); + it('should store isoAlpha3Code for home and competition country codes', async () => { + const dto: CreateUserBodyDto = { + param: { + ...createUserDto.param, + handle: 'countryuser', + email: 'countryuser@example.com', + country: { code: 'US', isoAlpha3Code: 'USA' }, + }, + }; + + await service.registerUser(dto); + + expect(mockMemberPrisma.member.create).toHaveBeenCalledWith( + expect.objectContaining({ + data: expect.objectContaining({ + homeCountryCode: 'USA', + competitionCountryCode: 'USA', + }), + }), + ); + }); + it('should throw BadRequestException for missing handle, email, or password', async () => { await expect( service.registerUser({ diff --git a/src/api/user/user.service.ts b/src/api/user/user.service.ts index 615c655..5b67311 100644 --- a/src/api/user/user.service.ts +++ b/src/api/user/user.service.ts @@ -999,12 +999,19 @@ export class UserService { // Create the member record outside of the interactive transaction // to avoid cross-client work while a Prisma transaction is open try { + const isoAlpha3Code = CommonUtils.validateString( + userParams.country?.isoAlpha3Code, + ) + ? userParams.country?.isoAlpha3Code + : null; await this.memberPrisma.member.create({ data: { userId: Number(nextUserId), handle: userParams.handle, handleLower: userParams.handle.toLowerCase(), email: userParams.email, + homeCountryCode: isoAlpha3Code, + competitionCountryCode: isoAlpha3Code, tracks: [], createdBy: String(nextUserId), firstName: userParams.firstName ?? null,