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

82 lines
2.2 KiB
TypeScript
Raw Normal View History

2026-02-24 20:44:16 +00:00
import { InstallmentOptionDto, OrderDto, PaymentMethodDto, ProductDto } from '@/proxy/order/models'
2026-07-06 09:44:26 +00:00
import apiService from '@/services/api.service'
2026-02-24 20:44:16 +00:00
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,
paymentMethodId: orderData.paymentMethodId,
installment: orderData.installment,
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,
}
}
}
}