Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions backend/src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,27 @@ export class UserService {

async create(data: Partial<User>) {
const newEntity = this.userRepository.create(data);
const savedUser = await this.userRepository.save(newEntity);

// Return with only selected fields to match old behavior
return this.findById(savedUser.id);

try {
const savedUser = await this.userRepository.save(newEntity);
// Return with only selected fields to match old behavior
return this.findById(savedUser.id);
} catch (error: any) {
// Handle unique constraint violations from database
if (error.code === '23505') {
// PostgreSQL unique constraint violation
// Determine which column caused the conflict
if (error.detail?.includes('email')) {
throw new ConflictException('Email already exists');
} else if (error.detail?.includes('walletAddress')) {
throw new ConflictException('This wallet address is already linked to another account');
} else if (error.detail?.includes('publicKey')) {
throw new ConflictException('This public key is already linked to another account');
}
throw new ConflictException('This record already exists');
}
throw error;
}
}

/**
Expand Down
Loading