fix(referral): auto-create profile for legacy users on getMyInfo

Users registered before referral-service was deployed have no profile row.
getMyInfo() now auto-provisions a profile on first access instead of
throwing NotFoundException.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-07 11:36:58 -08:00
parent 13ab4ba1f3
commit 825e619224
1 changed files with 7 additions and 4 deletions

View File

@ -107,13 +107,16 @@ export class ReferralService {
return { referralCode: saved.referralCode };
}
/** 获取我的推荐信息 */
/** 获取我的推荐信息(老用户自动补建档案) */
async getMyInfo(userId: string): Promise<ReferralInfo> {
const profile = await this.profileRepo.findByUserId(userId);
let profile = await this.profileRepo.findByUserId(userId);
if (!profile) {
throw new NotFoundException('推荐档案不存在');
// 推荐服务上线前注册的老用户,按需自动创建推荐档案
this.logger.log(`老用户自动补建推荐档案: userId=${userId}`);
await this.createProfile({ userId, usedCode: null });
profile = await this.profileRepo.findByUserId(userId);
}
return this.toInfo(profile);
return this.toInfo(profile!);
}
/** 验证推荐码是否有效 */