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

60 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-08-27 10:54:05 +09:00
import { Body, Controller, Get, Param, Post, UseGuards, Request, BadRequestException } from "@nestjs/common";
2025-08-21 15:24:40 +09:00
import { OrdersService } from "./orders.service";
import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse, ApiTags } from "@nestjs/swagger";
import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard";
import { RequestWithUser } from "../auth/auth.types";
2025-08-27 10:54:05 +09:00
import { Logger } from "nestjs-pino";
import { IsString, IsObject, IsIn, IsNotEmpty } from "class-validator";
2025-08-27 10:54:05 +09:00
class CreateOrderBody {
@IsString()
@IsNotEmpty()
@IsIn(["Internet", "eSIM", "SIM", "VPN", "Other"])
orderType: "Internet" | "eSIM" | "SIM" | "VPN" | "Other";
2025-08-27 10:54:05 +09:00
@IsObject()
2025-08-23 18:02:05 +09:00
selections: Record<string, unknown>;
}
2025-08-21 15:24:40 +09:00
@ApiTags("orders")
@Controller("orders")
export class OrdersController {
2025-08-27 10:54:05 +09:00
constructor(
private ordersService: OrdersService,
private readonly logger: Logger
) {}
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@Post()
@ApiOperation({ summary: "Create Salesforce Order (one service per order)" })
@ApiResponse({ status: 201 })
async create(@Request() req: RequestWithUser, @Body() body: CreateOrderBody) {
2025-08-27 10:54:05 +09:00
this.logger.log({
body,
userId: req.user?.id,
orderType: body?.orderType
}, "Order creation request received");
return this.ordersService.create(req.user.id, body);
}
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@Get(":sfOrderId")
@ApiOperation({ summary: "Get order summary/status" })
@ApiParam({ name: "sfOrderId", type: String })
async get(@Request() req: RequestWithUser, @Param("sfOrderId") sfOrderId: string) {
2025-08-27 10:54:05 +09:00
return this.ordersService.get(req.user.id, sfOrderId);
}
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@Post(":sfOrderId/provision")
@ApiOperation({ summary: "Trigger provisioning for an approved order" })
@ApiParam({ name: "sfOrderId", type: String })
async provision(@Request() req: RequestWithUser, @Param("sfOrderId") sfOrderId: string) {
2025-08-27 10:54:05 +09:00
return this.ordersService.provision(req.user.id, sfOrderId);
}
}