From c162ccced9d919993c4a89125c5ab4195480438a Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 11 Dec 2025 03:33:10 -0800 Subject: [PATCH] fix(reward): correct response parsing for authorization-service API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The authorization-service uses TransformInterceptor which wraps all API responses in a standard format: { success, data, timestamp } Before this fix, the AuthorizationServiceClient was reading: data.accountSequence (undefined - wrong level) After this fix, it correctly reads: result.data.accountSequence This ensures that COMMUNITY_RIGHT is allocated to the correct authorized community user (e.g., accountSequence=6) instead of falling back to HEADQUARTERS (accountSequence=1). Changes in reward-service: - Added AuthorizationServiceResponse interface - Added NearestAuthorizationResult interface - Updated findNearestAuthorizedProvince() to parse wrapped response - Updated findNearestAuthorizedCity() to parse wrapped response - Updated findNearestCommunity() to parse wrapped response - Added debug logging for findNearestCommunity 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../authorization-service.client.ts | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/backend/services/reward-service/src/infrastructure/external/authorization-service/authorization-service.client.ts b/backend/services/reward-service/src/infrastructure/external/authorization-service/authorization-service.client.ts index 1c61c068..cf56df35 100644 --- a/backend/services/reward-service/src/infrastructure/external/authorization-service/authorization-service.client.ts +++ b/backend/services/reward-service/src/infrastructure/external/authorization-service/authorization-service.client.ts @@ -2,6 +2,17 @@ import { Injectable, Logger } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { IAuthorizationServiceClient } from '../../../domain/services/reward-calculation.service'; +// authorization-service 返回格式(经过 TransformInterceptor 包装) +interface AuthorizationServiceResponse { + success: boolean; + data: T; + timestamp: string; +} + +interface NearestAuthorizationResult { + accountSequence: number | null; +} + @Injectable() export class AuthorizationServiceClient implements IAuthorizationServiceClient { private readonly logger = new Logger(AuthorizationServiceClient.name); @@ -22,8 +33,10 @@ export class AuthorizationServiceClient implements IAuthorizationServiceClient { return null; } - const data = await response.json(); - return data.accountSequence ? BigInt(data.accountSequence) : null; + // authorization-service 返回格式: { success, data: { accountSequence }, timestamp } + const result: AuthorizationServiceResponse = await response.json(); + const accountSeq = result.data?.accountSequence; + return accountSeq ? BigInt(accountSeq) : null; } catch (error) { this.logger.error(`Error finding nearest authorized province:`, error); return null; @@ -41,8 +54,10 @@ export class AuthorizationServiceClient implements IAuthorizationServiceClient { return null; } - const data = await response.json(); - return data.accountSequence ? BigInt(data.accountSequence) : null; + // authorization-service 返回格式: { success, data: { accountSequence }, timestamp } + const result: AuthorizationServiceResponse = await response.json(); + const accountSeq = result.data?.accountSequence; + return accountSeq ? BigInt(accountSeq) : null; } catch (error) { this.logger.error(`Error finding nearest authorized city:`, error); return null; @@ -60,8 +75,11 @@ export class AuthorizationServiceClient implements IAuthorizationServiceClient { return null; } - const data = await response.json(); - return data.accountSequence ? BigInt(data.accountSequence) : null; + // authorization-service 返回格式: { success, data: { accountSequence }, timestamp } + const result: AuthorizationServiceResponse = await response.json(); + const accountSeq = result.data?.accountSequence; + this.logger.debug(`findNearestCommunity for userId=${userId}: result=${accountSeq}`); + return accountSeq ? BigInt(accountSeq) : null; } catch (error) { this.logger.error(`Error finding nearest community:`, error); return null;