Files
shop-admin/src/pages/shipment/servicce/Service.ts
T
hamid zarghami 19a68f7188 admin shipment
2025-10-27 11:53:20 +03:30

60 lines
1.6 KiB
TypeScript

import axios from "../../../config/axios";
import type {
ShipmentResponse,
CreateShipper,
Shipper,
ShipmentByIdResponse,
GetAdminShopResponse,
} from "../types/Types";
export const getShipment = async (
page: number = 1
): Promise<ShipmentResponse> => {
const { data } = await axios.get<ShipmentResponse>(`/shipment?page=${page}`);
return data;
};
export const createShipment = async (data: CreateShipper): Promise<Shipper> => {
const response = await axios.post<Shipper>("/admin/shipment", data);
return response.data;
};
export const deleteShipment = async (id: string): Promise<void> => {
const { data } = await axios.delete(`/admin/shipment/${id}`);
return data;
};
export const getShipmentById = async (id: string): Promise<Shipper> => {
const { data } = await axios.get<ShipmentByIdResponse>(
`/admin/shipment/${id}`
);
return data.results.shipper;
};
export const updateShipment = async (
id: string,
params: CreateShipper
): Promise<Shipper> => {
const { data } = await axios.patch<Shipper>(`/admin/shipment/${id}`, params);
return data;
};
export const removeShipmentFromAdmin = async (id: number): Promise<void> => {
const { data } = await axios.patch(`/admin/shipment/deactivate`, {
shipmentId: id,
});
return data;
};
export const addShipmentToAdmin = async (id: number): Promise<void> => {
const { data } = await axios.patch(`/admin/shipment/activate`, {
shipmentId: id,
});
return data;
};
export const getAdminShop = async (): Promise<GetAdminShopResponse> => {
const { data } = await axios.get<GetAdminShopResponse>(`/admin/shop`);
return data;
};