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

82 lines
2.8 KiB
TypeScript
Raw Normal View History

2025-08-27 10:54:05 +09:00
import { Controller, Get, UseGuards, Request } from "@nestjs/common";
2025-08-22 17:02:49 +09:00
import { ApiTags, ApiOperation, ApiBearerAuth } from "@nestjs/swagger";
import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard";
2025-08-27 20:01:46 +09:00
import { InternetCatalogService } from "./services/internet-catalog.service";
import { SimCatalogService } from "./services/sim-catalog.service";
import { VpnCatalogService } from "./services/vpn-catalog.service";
import {
InternetPlan, InternetAddon, InternetInstallation,
SimPlan, SimActivationFee, SimAddon,
VpnPlan, VpnActivationFee
} from "../shared/types/catalog.types";
2025-08-21 15:24:40 +09:00
@ApiTags("catalog")
@Controller("catalog")
2025-08-22 17:02:49 +09:00
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
export class CatalogController {
2025-08-27 20:01:46 +09:00
constructor(
private internetCatalog: InternetCatalogService,
private simCatalog: SimCatalogService,
private vpnCatalog: VpnCatalogService
) {}
2025-08-27 20:01:46 +09:00
@Get('internet/plans')
@ApiOperation({ summary: "Get Internet plans filtered by customer eligibility" })
async getInternetPlans(@Request() req: any): Promise<InternetPlan[]> {
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
}
@Get('internet/addons')
2025-08-27 20:01:46 +09:00
@ApiOperation({ summary: "Get Internet add-ons" })
async getInternetAddons(): Promise<InternetAddon[]> {
return this.internetCatalog.getAddons();
2025-08-27 10:54:05 +09:00
}
@Get('internet/installations')
2025-08-27 20:01:46 +09:00
@ApiOperation({ summary: "Get Internet installations" })
async getInternetInstallations(): Promise<InternetInstallation[]> {
return this.internetCatalog.getInstallations();
}
@Get('sim/plans')
@ApiOperation({ summary: "Get SIM plans filtered by user's existing services" })
async getSimPlans(@Request() req: any): Promise<SimPlan[]> {
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.hasFamilyDiscount);
}
return this.simCatalog.getPlansForUser(userId);
}
@Get('sim/activation-fees')
@ApiOperation({ summary: "Get SIM activation fees" })
async getSimActivationFees(): Promise<SimActivationFee[]> {
return this.simCatalog.getActivationFees();
}
@Get('sim/addons')
@ApiOperation({ summary: "Get SIM add-ons" })
async getSimAddons(): Promise<SimAddon[]> {
return this.simCatalog.getAddons();
}
@Get('vpn/plans')
@ApiOperation({ summary: "Get VPN plans" })
async getVpnPlans(): Promise<VpnPlan[]> {
return this.vpnCatalog.getPlans();
}
@Get('vpn/activation-fees')
@ApiOperation({ summary: "Get VPN activation fees" })
async getVpnActivationFees(): Promise<VpnActivationFee[]> {
return this.vpnCatalog.getActivationFees();
2025-08-27 10:54:05 +09:00
}
2025-08-27 20:01:46 +09:00
}