2025-08-23 17:24:37 +09:00
|
|
|
import { Body, Controller, Get, Param, Post, UseGuards, Request } from "@nestjs/common";
|
2025-08-21 15:24:40 +09:00
|
|
|
import { OrdersService } from "./orders.service";
|
2025-08-23 17:24:37 +09:00
|
|
|
import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse, ApiTags } from "@nestjs/swagger";
|
|
|
|
|
import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard";
|
|
|
|
|
import { RequestWithUser } from "../auth/auth.types";
|
|
|
|
|
|
|
|
|
|
interface CreateOrderBody {
|
|
|
|
|
orderType: "Internet" | "eSIM" | "SIM" | "VPN" | "Other";
|
2025-08-23 18:02:05 +09:00
|
|
|
selections: Record<string, unknown>;
|
2025-08-23 17:24:37 +09:00
|
|
|
}
|
2025-08-20 18:02:50 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
@ApiTags("orders")
|
|
|
|
|
@Controller("orders")
|
2025-08-20 18:02:50 +09:00
|
|
|
export class OrdersController {
|
|
|
|
|
constructor(private ordersService: OrdersService) {}
|
|
|
|
|
|
2025-08-23 17:24:37 +09:00
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@Post()
|
|
|
|
|
@ApiOperation({ summary: "Create Salesforce Order (one service per order)" })
|
|
|
|
|
@ApiResponse({ status: 201 })
|
|
|
|
|
async create(@Request() req: RequestWithUser, @Body() body: CreateOrderBody) {
|
|
|
|
|
return this.ordersService.create(req.user.userId, 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) {
|
|
|
|
|
return this.ordersService.get(req.user.userId, 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) {
|
|
|
|
|
return this.ordersService.provision(req.user.userId, sfOrderId);
|
|
|
|
|
}
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|