erp-platform/ui/src/services/order.service.ts
2025-08-20 13:31:56 +03:00

82 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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',
url: '/api/app/public/product-list',
},
{ apiName: this.apiName },
)
getPaymentMethodList = async () =>
apiService.fetchData<PaymentMethodDto[]>(
{
method: 'GET',
url: '/api/app/public/payment-method-list',
},
{ apiName: this.apiName },
)
getInstallmentOptionList = async () =>
apiService.fetchData<InstallmentOptionDto[]>(
{
method: 'GET',
url: '/api/app/public/installment-option-list',
},
{ 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',
url: `/api/app/public/order`,
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,
}
}
}
}