Assist_Design/apps/bff/src/orders/orders.controller.ts
T. Narantuya 98f998db51 Refactor code for improved readability and maintainability
- Simplified import statements in auth.controller.ts and consolidated DTO imports.
- Streamlined accountStatus method in AuthController for better clarity.
- Refactored error handling in AuthService for existing mapping checks and password validation.
- Cleaned up whitespace and formatting across various files for consistency.
- Enhanced logging configuration in logging.module.ts to reduce noise and improve clarity.
- Updated frontend components for better formatting and readability in ProfilePage and SignupPage.
2025-09-02 16:09:17 +09:00

64 lines
2.1 KiB
TypeScript

import { Body, Controller, Get, Param, Post, Request } from "@nestjs/common";
import { OrderOrchestrator } from "./services/order-orchestrator.service";
import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse, ApiTags } from "@nestjs/swagger";
import type { RequestWithUser } from "../auth/auth.types";
import { Logger } from "nestjs-pino";
import * as OrderDto from "./dto/order.dto";
@ApiTags("orders")
@Controller("orders")
export class OrdersController {
constructor(
private orderOrchestrator: OrderOrchestrator,
private readonly logger: Logger
) {}
@ApiBearerAuth()
@Post()
@ApiOperation({ summary: "Create Salesforce Order" })
@ApiResponse({ status: 201, description: "Order created successfully" })
@ApiResponse({ status: 400, description: "Invalid request data" })
async create(@Request() req: RequestWithUser, @Body() body: OrderDto.CreateOrderDto) {
this.logger.log(
{
userId: req.user?.id,
orderType: body.orderType,
skuCount: body.skus?.length || 0,
},
"Order creation request received"
);
try {
return await this.orderOrchestrator.createOrder(req.user.id, body);
} catch (error) {
this.logger.error(
{
error: error instanceof Error ? error.message : String(error),
userId: req.user?.id,
orderType: body.orderType,
},
"Order creation failed"
);
throw error;
}
}
@ApiBearerAuth()
@Get("user")
@ApiOperation({ summary: "Get user's orders" })
async getUserOrders(@Request() req: RequestWithUser) {
return this.orderOrchestrator.getOrdersForUser(req.user.id);
}
@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.orderOrchestrator.getOrder(sfOrderId);
}
// Note: Order provisioning has been moved to SalesforceProvisioningController
// This controller now focuses only on customer-facing order operations
}