erp-platform/ui/src/services/order.service.ts

83 lines
2.2 KiB
TypeScript
Raw Normal View History

2025-08-11 06:34:44 +00:00
import { InstallmentOptionDto, OrderDto, PaymentMethodDto, ProductDto } from '@/proxy/order/models'
import apiService, { Config } from '@/services/api.service'
import axios from 'axios'
export class OrderService {
apiName = 'Default'
getProductList = async () =>
apiService.fetchData<ProductDto[]>(
{
method: 'GET',
2025-08-20 10:31:56 +00:00
url: '/api/app/public/product-list',
2025-08-11 06:34:44 +00:00
},
{ apiName: this.apiName },
)
getPaymentMethodList = async () =>
apiService.fetchData<PaymentMethodDto[]>(
{
method: 'GET',
2025-08-20 10:31:56 +00:00
url: '/api/app/public/payment-method-list',
2025-08-11 06:34:44 +00:00
},
{ apiName: this.apiName },
)
getInstallmentOptionList = async () =>
apiService.fetchData<InstallmentOptionDto[]>(
{
method: 'GET',
2025-08-20 10:31:56 +00:00
url: '/api/app/public/installment-option-list',
2025-08-11 06:34:44 +00:00
},
{ apiName: this.apiName },
)
// Sipariş oluşturma
createOrder = async (
orderData: OrderDto,
): Promise<{ success: boolean; orderId?: string; error?: string }> => {
try {
const response = await apiService.fetchData<{ orderId?: string; id?: string }>(
{
method: 'POST',
2025-08-20 10:31:56 +00:00
url: `/api/app/public/order`,
2025-08-11 06:34:44 +00:00
data: {
tenant: orderData.tenant,
items: orderData.items,
subtotal: orderData.subtotal,
commission: orderData.commission,
total: orderData.total,
paymentMethod: orderData.paymentMethod,
installments: orderData.installments,
installmentName: orderData.installmentName,
paymentData: orderData.paymentData,
},
},
{ apiName: this.apiName },
)
return {
success: true,
orderId: response.data.orderId || response.data.id,
}
} catch (error) {
console.error('Order creation error:', error)
let errorMessage = 'Sipariş oluşturulurken hata oluştu'
if (axios.isAxiosError(error)) {
if (error.response) {
errorMessage = error.response.data?.message || errorMessage
} else if (error.request) {
errorMessage = 'Sunucuya bağlanılamadı'
}
}
return {
success: false,
error: errorMessage,
}
}
}
}