- Introduced new SIM management queue and processor to handle SIM-related tasks efficiently. - Added SIM activation fee handling in the checkout service, ensuring proper validation and inclusion in cart calculations. - Enhanced the SimCatalogService to retrieve and filter activation fees based on SKU, improving order validation. - Updated the checkout process to automatically add default activation fees when none are specified, improving user experience. - Refactored the ActivationForm component to display activation fees clearly during the SIM configuration process. - Improved error handling and logging across various services to provide better insights during operations. - Updated tests to cover new features and ensure reliability in the checkout and SIM management workflows.
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { getErrorMessage } from "@bff/core/utils/error.util";
|
|
import { SimNotificationService } from "./sim-notification.service";
|
|
import type { SimNotificationContext } from "../interfaces/sim-base.interface";
|
|
|
|
interface RunOptions<T> {
|
|
baseContext: SimNotificationContext;
|
|
enrichSuccess?: (result: T) => Partial<SimNotificationContext>;
|
|
enrichError?: (error: unknown) => Partial<SimNotificationContext>;
|
|
}
|
|
|
|
@Injectable()
|
|
export class SimActionRunnerService {
|
|
constructor(private readonly simNotification: SimNotificationService) {}
|
|
|
|
async run<T>(
|
|
action: string,
|
|
options: RunOptions<T>,
|
|
handler: () => Promise<T>
|
|
): Promise<T> {
|
|
try {
|
|
const result = await handler();
|
|
const successContext = {
|
|
...options.baseContext,
|
|
...(options.enrichSuccess ? options.enrichSuccess(result) : {}),
|
|
};
|
|
await this.simNotification.notifySimAction(action, "SUCCESS", successContext);
|
|
return result;
|
|
} catch (error) {
|
|
const errorContext = {
|
|
...options.baseContext,
|
|
error: getErrorMessage(error),
|
|
...(options.enrichError ? options.enrichError(error) : {}),
|
|
};
|
|
await this.simNotification.notifySimAction(action, "ERROR", errorContext);
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|