tema 675f7d5cfd Remove cached profile fields migration and update CSRF middleware for new public auth endpoints
- Deleted migration file that removed cached profile fields from the users table, centralizing profile data retrieval from WHMCS.
- Updated CsrfMiddleware to include new public authentication endpoints for password reset, setting password, and WHMCS account linking.
- Enhanced error handling in password and WHMCS linking workflows to provide clearer feedback on missing mappings and improve user experience.
- Adjusted user creation and update methods in UsersFacade to handle cases where WHMCS mappings are not yet available, ensuring smoother account setup.
2025-11-21 17:12:34 +09:00

73 lines
2.3 KiB
TypeScript

import { Injectable, Inject } from "@nestjs/common";
import { Logger } from "nestjs-pino";
import { FreebitOrchestratorService } from "@bff/integrations/freebit/services/freebit-orchestrator.service";
import { SimValidationService } from "./sim-validation.service";
import { getErrorMessage } from "@bff/core/utils/error.util";
import type { SimDetails } from "@bff/integrations/freebit/interfaces/freebit.types";
@Injectable()
export class SimDetailsService {
constructor(
private readonly freebitService: FreebitOrchestratorService,
private readonly simValidation: SimValidationService,
@Inject(Logger) private readonly logger: Logger
) {}
/**
* Get SIM details for a subscription
*/
async getSimDetails(userId: string, subscriptionId: number): Promise<SimDetails> {
try {
const { account } = await this.simValidation.validateSimSubscription(userId, subscriptionId);
const simDetails = await this.freebitService.getSimDetails(account);
this.logger.log(`Retrieved SIM details for subscription ${subscriptionId}`, {
userId,
subscriptionId,
account,
status: simDetails.status,
});
return simDetails;
} catch (error) {
const sanitizedError = getErrorMessage(error);
this.logger.error(`Failed to get SIM details for subscription ${subscriptionId}`, {
error: sanitizedError,
userId,
subscriptionId,
});
throw error;
}
}
/**
* Get SIM details directly from Freebit without subscription validation
* Used for debugging purposes
*/
async getSimDetailsDirectly(account: string): Promise<SimDetails> {
try {
this.logger.log(`[DEBUG] Querying Freebit for account: ${account}`);
const simDetails = await this.freebitService.getSimDetails(account);
this.logger.log(`[DEBUG] Retrieved SIM details from Freebit`, {
account,
planCode: simDetails.planCode,
planName: simDetails.planName,
status: simDetails.status,
simType: simDetails.simType,
});
return simDetails;
} catch (error) {
const sanitizedError = getErrorMessage(error);
this.logger.error(`[DEBUG] Failed to get SIM details for account ${account}`, {
error: sanitizedError,
account,
});
throw error;
}
}
}