import { Controller, Get, Request } from "@nestjs/common"; import type { RequestWithUser } from "@bff/modules/auth/auth.types"; import type { InternetAddonCatalogItem, InternetInstallationCatalogItem, InternetPlanCatalogItem, SimCatalogProduct, SimActivationFeeCatalogItem, VpnCatalogProduct, } from "@customer-portal/domain/catalog"; import { InternetCatalogService } from "./services/internet-catalog.service"; import { SimCatalogService } from "./services/sim-catalog.service"; import { VpnCatalogService } from "./services/vpn-catalog.service"; @Controller("catalog") export class CatalogController { constructor( private internetCatalog: InternetCatalogService, private simCatalog: SimCatalogService, private vpnCatalog: VpnCatalogService ) {} @Get("internet/plans") async getInternetPlans(@Request() req: RequestWithUser): Promise<{ plans: InternetPlanCatalogItem[]; installations: InternetInstallationCatalogItem[]; addons: InternetAddonCatalogItem[]; }> { const userId = req.user?.id; if (!userId) { // Fallback to all catalog data if no user context return this.internetCatalog.getCatalogData(); } // Get user-specific plans but all installations and addons const [plans, installations, addons] = await Promise.all([ this.internetCatalog.getPlansForUser(userId), this.internetCatalog.getInstallations(), this.internetCatalog.getAddons(), ]); return { plans, installations, addons }; } @Get("internet/addons") async getInternetAddons(): Promise { return this.internetCatalog.getAddons(); } @Get("internet/installations") async getInternetInstallations(): Promise { return this.internetCatalog.getInstallations(); } @Get("sim/plans") async getSimPlans(@Request() req: RequestWithUser): Promise { const userId = req.user?.id; if (!userId) { // Fallback to all regular plans if no user context const allPlans = await this.simCatalog.getPlans(); return allPlans.filter(plan => !plan.simHasFamilyDiscount); } return this.simCatalog.getPlansForUser(userId); } @Get("sim/activation-fees") async getSimActivationFees(): Promise { return this.simCatalog.getActivationFees(); } @Get("sim/addons") async getSimAddons(): Promise { return this.simCatalog.getAddons(); } @Get("vpn/plans") async getVpnPlans(): Promise { return this.vpnCatalog.getPlans(); } @Get("vpn/activation-fees") async getVpnActivationFees(): Promise { return this.vpnCatalog.getActivationFees(); } }