Files
dukang/server/dukang-api/src/modules/trade/trade.controller.ts
T
2026-06-30 10:33:56 +08:00

79 lines
2.3 KiB
TypeScript

import { Body, Controller, Get, Param, Post, Put, Query, UseGuards } from '@nestjs/common';
import { TradeService } from './trade.service';
import { JwtAuthGuard, AuthUser } from '../../common/guards/jwt-auth.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
@Controller('trade/orders')
@UseGuards(JwtAuthGuard)
export class TradeController {
constructor(private readonly tradeService: TradeService) {}
@Post('preview')
preview(@CurrentUser() user: AuthUser, @Body() body: Record<string, unknown>) {
return this.tradeService.preview(user.actorId, body as never);
}
@Post()
create(@CurrentUser() user: AuthUser, @Body() body: Record<string, unknown>) {
return this.tradeService.createOrder(user.actorId, body as never);
}
@Get()
list(
@CurrentUser() user: AuthUser,
@Query('tab') tab = 'all',
@Query('page') page = '1',
@Query('pageSize') pageSize = '20',
) {
return this.tradeService.listOrders(user.actorId, tab, Number(page), Number(pageSize));
}
@Get(':id')
detail(@CurrentUser() user: AuthUser, @Param('id') id: string) {
return this.tradeService.getOrder(user.actorId, BigInt(id));
}
@Post(':id/pay')
pay(@CurrentUser() user: AuthUser, @Param('id') id: string) {
return this.tradeService.payOrder(user.actorId, BigInt(id));
}
@Put(':id/address')
updateAddress(
@CurrentUser() user: AuthUser,
@Param('id') id: string,
@Body() body: Record<string, unknown>,
) {
return this.tradeService.updateAddress(user.actorId, BigInt(id), body);
}
}
@Controller('partner/orders')
@UseGuards(JwtAuthGuard)
export class PartnerOrderController {
constructor(private readonly tradeService: TradeService) {}
@Get()
list(
@CurrentUser() user: AuthUser,
@Query('page') page = '1',
@Query('pageSize') pageSize = '20',
) {
return this.tradeService.listPartnerOrders(user.actorId, Number(page), Number(pageSize));
}
@Get(':id')
detail(@CurrentUser() user: AuthUser, @Param('id') id: string) {
return this.tradeService.getPartnerOrder(user.actorId, BigInt(id));
}
@Post(':id/mock-advance-delivery')
mockAdvance(
@CurrentUser() user: AuthUser,
@Param('id') id: string,
@Body() body: { targetStatus: string },
) {
return this.tradeService.advanceDelivery(user.actorId, BigInt(id), body.targetStatus);
}
}