Assist_Design/apps/bff/src/modules/catalog/catalog.controller.ts

86 lines
2.8 KiB
TypeScript
Raw Normal View History

2025-08-28 16:57:57 +09:00
import { Controller, Get, Request } from "@nestjs/common";
2025-08-22 17:02:49 +09:00
import { ApiTags, ApiOperation, ApiBearerAuth } from "@nestjs/swagger";
import type {
InternetAddonCatalogItem,
InternetInstallationCatalogItem,
InternetPlanCatalogItem,
SimCatalogProduct,
SimActivationFeeCatalogItem,
VpnCatalogProduct,
} from "@customer-portal/domain";
import { InternetCatalogService } from "./services/internet-catalog.service";
import { SimCatalogService } from "./services/sim-catalog.service";
import { VpnCatalogService } from "./services/vpn-catalog.service";
2025-08-21 15:24:40 +09:00
@ApiTags("catalog")
@Controller("catalog")
2025-08-22 17:02:49 +09:00
@ApiBearerAuth()
export class CatalogController {
2025-08-27 20:01:46 +09:00
constructor(
private internetCatalog: InternetCatalogService,
private simCatalog: SimCatalogService,
private vpnCatalog: VpnCatalogService
) {}
2025-08-28 16:57:57 +09:00
@Get("internet/plans")
2025-08-27 20:01:46 +09:00
@ApiOperation({ summary: "Get Internet plans filtered by customer eligibility" })
async getInternetPlans(
@Request() req: { user: { id: string } }
): Promise<InternetPlanCatalogItem[]> {
2025-08-27 20:01:46 +09:00
const userId = req.user?.id;
if (!userId) {
// Fallback to all plans if no user context
return this.internetCatalog.getPlans();
}
return this.internetCatalog.getPlansForUser(userId);
2025-08-27 10:54:05 +09:00
}
2025-08-28 16:57:57 +09:00
@Get("internet/addons")
2025-08-27 20:01:46 +09:00
@ApiOperation({ summary: "Get Internet add-ons" })
async getInternetAddons(): Promise<InternetAddonCatalogItem[]> {
2025-08-27 20:01:46 +09:00
return this.internetCatalog.getAddons();
2025-08-27 10:54:05 +09:00
}
2025-08-28 16:57:57 +09:00
@Get("internet/installations")
2025-08-27 20:01:46 +09:00
@ApiOperation({ summary: "Get Internet installations" })
async getInternetInstallations(): Promise<InternetInstallationCatalogItem[]> {
2025-08-27 20:01:46 +09:00
return this.internetCatalog.getInstallations();
}
2025-08-28 16:57:57 +09:00
@Get("sim/plans")
2025-08-27 20:01:46 +09:00
@ApiOperation({ summary: "Get SIM plans filtered by user's existing services" })
async getSimPlans(@Request() req: { user: { id: string } }): Promise<SimCatalogProduct[]> {
2025-08-27 20:01:46 +09:00
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);
2025-08-27 20:01:46 +09:00
}
return this.simCatalog.getPlansForUser(userId);
}
2025-08-28 16:57:57 +09:00
@Get("sim/activation-fees")
2025-08-27 20:01:46 +09:00
@ApiOperation({ summary: "Get SIM activation fees" })
async getSimActivationFees(): Promise<SimActivationFeeCatalogItem[]> {
2025-08-27 20:01:46 +09:00
return this.simCatalog.getActivationFees();
}
2025-08-28 16:57:57 +09:00
@Get("sim/addons")
2025-08-27 20:01:46 +09:00
@ApiOperation({ summary: "Get SIM add-ons" })
async getSimAddons(): Promise<SimCatalogProduct[]> {
2025-08-27 20:01:46 +09:00
return this.simCatalog.getAddons();
}
2025-08-28 16:57:57 +09:00
@Get("vpn/plans")
2025-08-27 20:01:46 +09:00
@ApiOperation({ summary: "Get VPN plans" })
async getVpnPlans(): Promise<VpnCatalogProduct[]> {
2025-08-27 20:01:46 +09:00
return this.vpnCatalog.getPlans();
}
2025-08-28 16:57:57 +09:00
@Get("vpn/activation-fees")
2025-08-27 20:01:46 +09:00
@ApiOperation({ summary: "Get VPN activation fees" })
async getVpnActivationFees(): Promise<VpnCatalogProduct[]> {
2025-08-27 20:01:46 +09:00
return this.vpnCatalog.getActivationFees();
2025-08-27 10:54:05 +09:00
}
2025-08-28 16:57:57 +09:00
}