import { Body, Controller, Post } from '@nestjs/common'; import { IsDateString, IsIn, IsNumber, IsString } from 'class-validator'; import { OrdersService } from './orders.service'; import { PaymentMethod } from './midtrans.service';
class CreateOrderDto { @IsString() customerName!: string; @IsString() customerPhone!: string; @IsString() vehicleName!: string; @IsDateString() startDate!: string; @IsDateString() endDate!: string; @IsNumber() total!: number; @IsIn(['qris', 'va', 'ewallet', 'dana']) paymentMethod!: PaymentMethod; }
@Controller('orders') export class OrdersController { constructor(private orders: OrdersService) {} @Post() create(@Body() body: CreateOrderDto) { const { paymentMethod, ...order } = body; return this.orders.create(order, paymentMethod); } @Post('webhook/midtrans') webhook(@Body() body: { order_id: string; transaction_status: string; status_code: string; gross_amount: string; signature_key: string }) { return this.orders.webhook(body); } }

