fix(reward): correct response parsing for authorization-service API
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<T> 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 <noreply@anthropic.com>
This commit is contained in:
parent
7320900289
commit
c162ccced9
|
|
@ -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<T> {
|
||||
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<NearestAuthorizationResult> = 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<NearestAuthorizationResult> = 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<NearestAuthorizationResult> = 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue