fix(pre-planting): 修复 authorization-service 响应包装格式解析

authorization-service 全局 TransformInterceptor 将响应包装为
{ success, data: T, timestamp },预种客户端需读取 response.data.data
而非 response.data。此前因解析失败静默 fallback 到系统账户。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-01 02:22:01 -08:00
parent a15a4a97b1
commit e32658fc5e
1 changed files with 23 additions and 13 deletions

View File

@ -19,6 +19,16 @@ interface AreaDistributionItem {
isSystemAccount: boolean; isSystemAccount: boolean;
} }
/**
* authorization-service TransformInterceptor
* { success: boolean, data: T, timestamp: string }
*/
interface WrappedResponse<T> {
success: boolean;
data: T;
timestamp: string;
}
@Injectable() @Injectable()
export class PrePlantingAuthorizationClient { export class PrePlantingAuthorizationClient {
private readonly logger = new Logger(PrePlantingAuthorizationClient.name); private readonly logger = new Logger(PrePlantingAuthorizationClient.name);
@ -41,13 +51,13 @@ export class PrePlantingAuthorizationClient {
): Promise<RewardDistributionResult> { ): Promise<RewardDistributionResult> {
try { try {
const response = await firstValueFrom( const response = await firstValueFrom(
this.httpService.get<{ accountSequence: string }>( this.httpService.get<WrappedResponse<{ accountSequence: string }>>(
`${this.baseUrl}/api/v1/authorization/community-reward-distribution`, `${this.baseUrl}/api/v1/authorization/community-reward-distribution`,
{ params: { accountSequence } }, { params: { accountSequence } },
), ),
); );
return { return {
recipientAccountSequence: response.data.accountSequence, recipientAccountSequence: response.data.data.accountSequence,
isFallback: false, isFallback: false,
}; };
} catch (error) { } catch (error) {
@ -66,7 +76,7 @@ export class PrePlantingAuthorizationClient {
* *
* [2026-02-28] * [2026-02-28]
* 1. treeCount=01 * 1. treeCount=01
* 2. { distributions: [{accountSequence, ...}] } { accountSequence } * 2. { success, data: { distributions: [...] } }
* 3. fallback 使 padEnd(6,'0') 7 9440000 * 3. fallback 使 padEnd(6,'0') 7 9440000
*/ */
async getProvinceAreaDistribution( async getProvinceAreaDistribution(
@ -74,13 +84,13 @@ export class PrePlantingAuthorizationClient {
): Promise<RewardDistributionResult> { ): Promise<RewardDistributionResult> {
try { try {
const response = await firstValueFrom( const response = await firstValueFrom(
this.httpService.get<{ distributions: AreaDistributionItem[] }>( this.httpService.get<WrappedResponse<{ distributions: AreaDistributionItem[] }>>(
`${this.baseUrl}/api/v1/authorization/province-area-reward-distribution`, `${this.baseUrl}/api/v1/authorization/province-area-reward-distribution`,
{ params: { provinceCode, treeCount: 0 } }, { params: { provinceCode, treeCount: 0 } },
), ),
); );
const distributions = response.data.distributions; const distributions = response.data.data.distributions;
if (!distributions || distributions.length === 0) { if (!distributions || distributions.length === 0) {
throw new Error('Empty distributions returned'); throw new Error('Empty distributions returned');
} }
@ -116,13 +126,13 @@ export class PrePlantingAuthorizationClient {
): Promise<RewardDistributionResult> { ): Promise<RewardDistributionResult> {
try { try {
const response = await firstValueFrom( const response = await firstValueFrom(
this.httpService.get<{ accountSequence: string }>( this.httpService.get<WrappedResponse<{ accountSequence: string }>>(
`${this.baseUrl}/api/v1/authorization/province-team-reward-distribution`, `${this.baseUrl}/api/v1/authorization/province-team-reward-distribution`,
{ params: { accountSequence } }, { params: { accountSequence } },
), ),
); );
return { return {
recipientAccountSequence: response.data.accountSequence, recipientAccountSequence: response.data.data.accountSequence,
isFallback: false, isFallback: false,
}; };
} catch (error) { } catch (error) {
@ -139,9 +149,9 @@ export class PrePlantingAuthorizationClient {
/** /**
* *
* *
* [2026-02-28] * [2026-02-28]
* 1. treeCount=01 * 1. treeCount=01
* 2. { distributions: [...] } * 2. { success, data: { distributions: [...] } }
* 3. fallback 使 padEnd(6,'0') 7 8440100 * 3. fallback 使 padEnd(6,'0') 7 8440100
*/ */
async getCityAreaDistribution( async getCityAreaDistribution(
@ -149,13 +159,13 @@ export class PrePlantingAuthorizationClient {
): Promise<RewardDistributionResult> { ): Promise<RewardDistributionResult> {
try { try {
const response = await firstValueFrom( const response = await firstValueFrom(
this.httpService.get<{ distributions: AreaDistributionItem[] }>( this.httpService.get<WrappedResponse<{ distributions: AreaDistributionItem[] }>>(
`${this.baseUrl}/api/v1/authorization/city-area-reward-distribution`, `${this.baseUrl}/api/v1/authorization/city-area-reward-distribution`,
{ params: { cityCode, treeCount: 0 } }, { params: { cityCode, treeCount: 0 } },
), ),
); );
const distributions = response.data.distributions; const distributions = response.data.data.distributions;
if (!distributions || distributions.length === 0) { if (!distributions || distributions.length === 0) {
throw new Error('Empty distributions returned'); throw new Error('Empty distributions returned');
} }
@ -190,13 +200,13 @@ export class PrePlantingAuthorizationClient {
): Promise<RewardDistributionResult> { ): Promise<RewardDistributionResult> {
try { try {
const response = await firstValueFrom( const response = await firstValueFrom(
this.httpService.get<{ accountSequence: string }>( this.httpService.get<WrappedResponse<{ accountSequence: string }>>(
`${this.baseUrl}/api/v1/authorization/city-team-reward-distribution`, `${this.baseUrl}/api/v1/authorization/city-team-reward-distribution`,
{ params: { accountSequence } }, { params: { accountSequence } },
), ),
); );
return { return {
recipientAccountSequence: response.data.accountSequence, recipientAccountSequence: response.data.data.accountSequence,
isFallback: false, isFallback: false,
}; };
} catch (error) { } catch (error) {