43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { Controller, Post, Get, Body, Param, Query, UseGuards, Req } from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth, ApiBody } from '@nestjs/swagger';
|
|
import { IsNumber, IsString, IsOptional, IsIn } from 'class-validator';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
import { OrdersService } from './orders.service';
|
|
|
|
class CreateOrderDto {
|
|
@IsNumber()
|
|
amount: number;
|
|
|
|
@IsString()
|
|
@IsIn(['MONTHLY', 'YEARLY', 'COURSE'])
|
|
planType: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
payChannel?: string;
|
|
}
|
|
|
|
@ApiTags('订单')
|
|
@Controller('orders')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@ApiBearerAuth()
|
|
export class OrdersController {
|
|
constructor(private ordersService: OrdersService) {}
|
|
|
|
@Post('create')
|
|
@ApiBody({ type: CreateOrderDto })
|
|
async create(@Req() req: any, @Body() body: CreateOrderDto) {
|
|
return this.ordersService.create(req.user.userId, body);
|
|
}
|
|
|
|
@Get()
|
|
async findByUser(@Req() req: any, @Query() query: { page?: number; pageSize?: number }) {
|
|
return this.ordersService.findByUser(req.user.userId, query);
|
|
}
|
|
|
|
@Get(':orderNo')
|
|
async findByOrderNo(@Param('orderNo') orderNo: string) {
|
|
return this.ordersService.findByOrderNo(orderNo);
|
|
}
|
|
}
|