fix(pre-planting): 修复推荐链 API 调用的 URL 路径和返回格式解析
1. URL: /referrals/:id/chain → /referral/chain/:id(与正常认种对齐)
2. 返回格式: 正确解析 { ancestors: [{accountSequence, hasPlanted}] }
之前错误期望 { directReferrer: {...} },导致有推荐人也被当成无推荐人
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
545e897c1f
commit
f32748c1d5
|
|
@ -11,6 +11,17 @@ export interface ReferralChainInfo {
|
||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* referral-service /api/v1/referral/chain/:accountSequence 的实际返回格式
|
||||||
|
*/
|
||||||
|
interface ReferralChainApiResponse {
|
||||||
|
ancestors: Array<{
|
||||||
|
userId: string;
|
||||||
|
accountSequence: string;
|
||||||
|
hasPlanted: boolean;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrePlantingReferralClient {
|
export class PrePlantingReferralClient {
|
||||||
private readonly logger = new Logger(PrePlantingReferralClient.name);
|
private readonly logger = new Logger(PrePlantingReferralClient.name);
|
||||||
|
|
@ -27,18 +38,43 @@ export class PrePlantingReferralClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取直接推荐人信息
|
* 获取直接推荐人信息
|
||||||
|
*
|
||||||
|
* [2026-03-01] 修复:
|
||||||
|
* 1. URL 路径修正:/api/v1/referral/chain/:accountSequence(之前错误地用了 /referrals/:accountSequence/chain)
|
||||||
|
* 2. 返回格式修正:referral-service 返回 { ancestors: [{userId, accountSequence, hasPlanted}] },
|
||||||
|
* 之前错误地期望 { directReferrer: {accountSequence, hasPlanted} }
|
||||||
|
* 3. ancestors[0] 即为直推人(直接推荐人)
|
||||||
*/
|
*/
|
||||||
async getReferralChain(accountSequence: string): Promise<ReferralChainInfo> {
|
async getReferralChain(accountSequence: string): Promise<ReferralChainInfo> {
|
||||||
try {
|
try {
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
this.httpService.get<ReferralChainInfo>(
|
this.httpService.get<ReferralChainApiResponse>(
|
||||||
`${this.baseUrl}/api/v1/referrals/${accountSequence}/chain`,
|
`${this.baseUrl}/api/v1/referral/chain/${accountSequence}`,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return response.data;
|
|
||||||
|
const ancestors = response.data.ancestors || [];
|
||||||
|
if (ancestors.length === 0) {
|
||||||
|
this.logger.log(
|
||||||
|
`No referrer found for ${accountSequence} (empty ancestors)`,
|
||||||
|
);
|
||||||
|
return { accountSequence, directReferrer: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
// ancestors[0] 为直推人
|
||||||
|
const directReferrer = ancestors[0];
|
||||||
|
this.logger.log(
|
||||||
|
`Referrer for ${accountSequence}: ${directReferrer.accountSequence} (hasPlanted=${directReferrer.hasPlanted})`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
accountSequence,
|
||||||
|
directReferrer: {
|
||||||
|
accountSequence: directReferrer.accountSequence,
|
||||||
|
hasPlanted: directReferrer.hasPlanted ?? false,
|
||||||
|
},
|
||||||
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// 404 = 用户无推荐关系,属于正常情况(如测试账号、直接注册用户)
|
|
||||||
// 返回空推荐链而非抛错,避免阻断购买流程
|
|
||||||
if (error?.response?.status === 404) {
|
if (error?.response?.status === 404) {
|
||||||
this.logger.warn(
|
this.logger.warn(
|
||||||
`No referral chain found for ${accountSequence}, proceeding without referrer`,
|
`No referral chain found for ${accountSequence}, proceeding without referrer`,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue