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

86 lines
2.7 KiB
TypeScript
Raw Normal View History

2025-08-28 16:57:57 +09:00
import { Controller, Get, Request } from "@nestjs/common";
import type { RequestWithUser } from "@bff/modules/auth/auth.types";
import {
parseInternetCatalog,
type InternetAddonCatalogItem,
type InternetInstallationCatalogItem,
type InternetPlanCatalogItem,
type SimActivationFeeCatalogItem,
type SimCatalogProduct,
type 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";
2025-08-21 15:24:40 +09:00
@Controller("catalog")
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")
async getInternetPlans(@Request() req: RequestWithUser): Promise<{
plans: InternetPlanCatalogItem[];
installations: InternetInstallationCatalogItem[];
addons: InternetAddonCatalogItem[];
}> {
2025-08-27 20:01:46 +09:00
const userId = req.user?.id;
if (!userId) {
const catalog = await this.internetCatalog.getCatalogData();
return parseInternetCatalog(catalog);
2025-08-27 20:01:46 +09:00
}
const [plans, installations, addons] = await Promise.all([
this.internetCatalog.getPlansForUser(userId),
this.internetCatalog.getInstallations(),
this.internetCatalog.getAddons(),
]);
return parseInternetCatalog({ plans, installations, addons });
2025-08-27 10:54:05 +09:00
}
2025-08-28 16:57:57 +09:00
@Get("internet/addons")
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")
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")
async getSimPlans(@Request() req: RequestWithUser): 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")
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")
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")
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")
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
}