四端上传
This commit is contained in:
1 parent
25bbb5f9c8
commit
c6e2cb4d5b
276 files changed
+17812
-3
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||
import { z } from 'zod';
|
||||
import { CurrentUser, type AuthPrincipal } from '../../common/auth';
|
||||
import { AppError } from '../../common/errors';
|
||||
import { OrdersService } from './orders.service';
|
||||
|
||||
const createSchema = z.object({
|
||||
courseCode: z.string().min(1),
|
||||
quantity: z.coerce.number().int().min(1).max(10).optional(),
|
||||
});
|
||||
|
||||
@Controller('v1/orders')
|
||||
export class OrdersController {
|
||||
constructor(private readonly orders: OrdersService) {}
|
||||
|
||||
@Post()
|
||||
create(@CurrentUser() user: AuthPrincipal, @Body() body: unknown) {
|
||||
const parsed = createSchema.safeParse(body);
|
||||
if (!parsed.success) throw AppError.badRequest('参数错误:缺少 courseCode');
|
||||
return this.orders.create(user.id, parsed.data.courseCode, parsed.data.quantity ?? 1);
|
||||
}
|
||||
|
||||
@Get()
|
||||
list(@CurrentUser() user: AuthPrincipal) {
|
||||
return this.orders.list(user.id);
|
||||
}
|
||||
|
||||
@Get(':outTradeNo')
|
||||
status(@CurrentUser() user: AuthPrincipal, @Param('outTradeNo') outTradeNo: string) {
|
||||
return this.orders.status(user.id, outTradeNo);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user