Refactor FreebitOperationsService to enforce API constraints on voice features and network type changes

- Updated logic to prevent simultaneous updates of voice features and network type, ensuring compliance with Freebit API requirements.
- Introduced error handling to guide users on proper sequencing of operations using SimManagementQueueService.
- Improved code clarity by removing outdated comments and consolidating operation handling.
This commit is contained in:
barsa 2025-11-26 16:51:54 +09:00
parent bccfec940f
commit b7f6c204e2

View File

@ -446,50 +446,18 @@ export class FreebitOperationsService {
const hasVoiceFeatures = Object.values(voiceFeatures).some(value => typeof value === "boolean");
const hasNetworkTypeChange = typeof features.networkType === "string";
// Execute in sequence with 30-minute delays as per Freebit API requirements
// Freebit API requires voice features and network type changes to be 30 minutes apart.
// This service handles single operations only - callers must coordinate sequencing via
// SimManagementQueueService for deferred network type changes after voice updates.
if (hasVoiceFeatures && hasNetworkTypeChange) {
// Both voice features and network type change requested
this.logger.log(`Updating both voice features and network type with required 30-minute delay`, {
account,
hasVoiceFeatures,
hasNetworkTypeChange,
});
throw new BadRequestException(
"Cannot update voice features and network type simultaneously. " +
"Voice and network type changes must be 30 minutes apart per Freebit API requirements. " +
"Use SimManagementQueueService to schedule the network type change after voice updates."
);
}
// Step 1: Update voice features immediately (PA05-06)
await this.updateVoiceFeatures(account, voiceFeatures);
this.logger.log(`Voice features updated, scheduling network type change in 30 minutes`, {
account,
networkType: features.networkType,
});
// Step 2: Schedule network type change 30 minutes later (PA05-38)
// Note: This uses setTimeout which is not ideal for production
// Consider using a job queue like Bull or agenda for production
setTimeout(async () => {
try {
await this.updateNetworkType(account, features.networkType!);
this.logger.log(`Network type change completed after 30-minute delay`, {
account,
networkType: features.networkType,
});
} catch (error) {
this.logger.error(`Failed to update network type after 30-minute delay`, {
account,
networkType: features.networkType,
error: getErrorMessage(error),
});
}
}, 30 * 60 * 1000); // 30 minutes
this.logger.log(`Voice features updated immediately, network type scheduled for 30 minutes`, {
account,
voiceMailEnabled: features.voiceMailEnabled,
callWaitingEnabled: features.callWaitingEnabled,
internationalRoamingEnabled: features.internationalRoamingEnabled,
networkType: features.networkType,
});
} else if (hasVoiceFeatures) {
if (hasVoiceFeatures) {
// Only voice features (PA05-06)
await this.updateVoiceFeatures(account, voiceFeatures);
this.logger.log(`Voice features updated successfully`, {