2025-08-28 16:57:57 +09:00
|
|
|
import { Controller, Get, Request } from "@nestjs/common";
|
2025-10-07 17:38:39 +09:00
|
|
|
import type { RequestWithUser } from "@bff/modules/auth/auth.types";
|
2025-09-24 18:00:49 +09:00
|
|
|
import type {
|
2025-09-18 11:22:22 +09:00
|
|
|
InternetAddonCatalogItem,
|
|
|
|
|
InternetInstallationCatalogItem,
|
|
|
|
|
InternetPlanCatalogItem,
|
2025-09-24 18:00:49 +09:00
|
|
|
SimCatalogProduct,
|
2025-09-18 11:22:22 +09:00
|
|
|
SimActivationFeeCatalogItem,
|
2025-09-24 18:00:49 +09:00
|
|
|
VpnCatalogProduct,
|
2025-10-08 10:33:33 +09:00
|
|
|
} from "@customer-portal/domain/catalog";
|
2025-09-24 18:00:49 +09:00
|
|
|
import { InternetCatalogService } from "./services/internet-catalog.service";
|
|
|
|
|
import { SimCatalogService } from "./services/sim-catalog.service";
|
2025-09-18 11:22:22 +09:00
|
|
|
import { VpnCatalogService } from "./services/vpn-catalog.service";
|
2025-08-20 18:02:50 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
@Controller("catalog")
|
2025-08-20 18:02:50 +09:00
|
|
|
export class CatalogController {
|
2025-08-27 20:01:46 +09:00
|
|
|
constructor(
|
|
|
|
|
private internetCatalog: InternetCatalogService,
|
|
|
|
|
private simCatalog: SimCatalogService,
|
|
|
|
|
private vpnCatalog: VpnCatalogService
|
|
|
|
|
) {}
|
2025-08-20 18:02:50 +09:00
|
|
|
|
2025-08-28 16:57:57 +09:00
|
|
|
@Get("internet/plans")
|
2025-10-07 17:38:39 +09:00
|
|
|
async getInternetPlans(@Request() req: RequestWithUser): Promise<{
|
2025-09-29 11:00:56 +09:00
|
|
|
plans: InternetPlanCatalogItem[];
|
|
|
|
|
installations: InternetInstallationCatalogItem[];
|
|
|
|
|
addons: InternetAddonCatalogItem[];
|
|
|
|
|
}> {
|
2025-08-27 20:01:46 +09:00
|
|
|
const userId = req.user?.id;
|
|
|
|
|
if (!userId) {
|
2025-09-29 11:00:56 +09:00
|
|
|
// Fallback to all catalog data if no user context
|
|
|
|
|
return this.internetCatalog.getCatalogData();
|
2025-08-27 20:01:46 +09:00
|
|
|
}
|
2025-10-02 17:19:39 +09:00
|
|
|
|
2025-09-29 11:00:56 +09:00
|
|
|
// 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(),
|
|
|
|
|
]);
|
2025-10-02 17:19:39 +09:00
|
|
|
|
2025-09-29 11:00:56 +09:00
|
|
|
return { plans, installations, addons };
|
2025-08-27 10:54:05 +09:00
|
|
|
}
|
|
|
|
|
|
2025-08-28 16:57:57 +09:00
|
|
|
@Get("internet/addons")
|
2025-09-18 11:22:22 +09:00
|
|
|
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-09-18 11:22:22 +09:00
|
|
|
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-10-07 17:38:39 +09:00
|
|
|
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();
|
2025-09-18 11:22:22 +09:00
|
|
|
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-09-18 11:22:22 +09:00
|
|
|
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-09-24 18:00:49 +09:00
|
|
|
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-09-24 18:00:49 +09:00
|
|
|
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-09-24 18:00:49 +09:00
|
|
|
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
|
|
|
}
|