|
|
@@ -0,0 +1,60 @@
|
|
|
+import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
|
|
|
+import { authMiddleware } from '@d8d/auth-module-mt';
|
|
|
+import { AppDataSource } from '@d8d/shared-utils';
|
|
|
+import { AuthContext } from '@d8d/shared-types';
|
|
|
+import { OrderMtService } from '../../services';
|
|
|
+import { CreateOrderRequestDto, CreateOrderResponseDto } from '../../schemas/create-order.schema';
|
|
|
+
|
|
|
+const createOrderRoute = createRoute({
|
|
|
+ method: 'post',
|
|
|
+ path: '/create-order',
|
|
|
+ middleware: [authMiddleware],
|
|
|
+ request: {
|
|
|
+ body: {
|
|
|
+ content: {
|
|
|
+ 'application/json': {
|
|
|
+ schema: CreateOrderRequestDto
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ responses: {
|
|
|
+ 200: {
|
|
|
+ description: '订单创建成功',
|
|
|
+ content: {
|
|
|
+ 'application/json': {
|
|
|
+ schema: CreateOrderResponseDto
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 400: {
|
|
|
+ description: '请求参数错误'
|
|
|
+ },
|
|
|
+ 500: {
|
|
|
+ description: '服务器内部错误'
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+const createOrderRoutes = new OpenAPIHono<AuthContext>()
|
|
|
+ // 创建订单路由
|
|
|
+ .openapi( createOrderRoute, async (c) => {
|
|
|
+ const data = c.req.valid('json');
|
|
|
+ const user = c.get('user');
|
|
|
+
|
|
|
+ try {
|
|
|
+ const orderService = new OrderMtService(AppDataSource);
|
|
|
+ const result = await orderService.createOrder(data, user.id, user.tenantId);
|
|
|
+
|
|
|
+ return c.json(result, 201);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('创建订单失败:', error);
|
|
|
+ return c.json(
|
|
|
+ { error: error instanceof Error ? error.message : '创建订单失败' },
|
|
|
+ 500
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+export default createOrderRoutes;
|