This commit is contained in:
NotII
2025-03-24 01:46:11 +00:00
parent 1e395b8684
commit 39c349509c
19 changed files with 477 additions and 427 deletions

View File

@@ -1,22 +1,9 @@
import { fetchData } from '@/lib/data-service';
import { normalizeApiUrl } from './api-utils';
/**
* Interface for shipping method data
*/
interface ShippingMethod {
name: string;
price: number;
_id?: string;
}
/**
* Fetches all shipping methods for the current store
*/
export const fetchShippingMethods = async (authToken: string) => {
try {
const res = await fetchData(
`/api/shipping-options`,
`${process.env.NEXT_PUBLIC_API_URL}/shipping-options`,
{
headers: {
Authorization: `Bearer ${authToken}`,
@@ -36,16 +23,19 @@ export const fetchShippingMethods = async (authToken: string) => {
}
};
/**
* Adds a new shipping method
*/
interface ShippingMethod {
name: string;
price: number;
_id?: string;
}
export const addShippingMethod = async (
authToken: string,
newShipping: Omit<ShippingMethod, "_id">
): Promise<ShippingMethod[]> => {
try {
const res = await fetchData(
`/api/shipping-options`,
`${process.env.NEXT_PUBLIC_API_URL}/shipping-options`,
{
method: "POST",
headers: {
@@ -79,13 +69,10 @@ export const addShippingMethod = async (
}
};
/**
* Deletes a shipping method by ID
*/
export const deleteShippingMethod = async (authToken: string, id: string) => {
try {
const res = await fetchData(
`/api/shipping-options/${id}`,
`${process.env.NEXT_PUBLIC_API_URL}/shipping-options/${id}`,
{
method: "DELETE",
headers: { Authorization: `Bearer ${authToken}` },
@@ -101,17 +88,14 @@ export const deleteShippingMethod = async (authToken: string, id: string) => {
}
};
/**
* Updates an existing shipping method
*/
export const updateShippingMethod = async (
authToken: string,
id: string,
updatedShipping: Partial<ShippingMethod>
updatedShipping: any
) => {
try {
const res = await fetchData(
`/api/shipping-options/${id}`,
`${process.env.NEXT_PUBLIC_API_URL}/shipping-options/${id}`,
{
method: "PUT",
headers: {