65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import axiosClient from '../axios/axios';
|
|
import {
|
|
Chainage,
|
|
ChainageCreate,
|
|
ChainageUpdate,
|
|
PaginatedResponse,
|
|
PaginationParams,
|
|
} from '@/types';
|
|
|
|
/**
|
|
* Chainage Service
|
|
*/
|
|
export const chainageService = {
|
|
/**
|
|
* Fetch all chainages
|
|
*/
|
|
getChainages: async (params?: PaginationParams): Promise<PaginatedResponse<Chainage>> => {
|
|
const skip = params?.skip ?? 0;
|
|
const limit = params?.limit ?? 100;
|
|
const response = await axiosClient.get<PaginatedResponse<Chainage>>(`/chainages/`, {
|
|
params: { skip, limit },
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Fetch chainages filtered by package ID
|
|
*/
|
|
getChainagesByPackage: async (
|
|
packageId: string,
|
|
params?: PaginationParams,
|
|
): Promise<PaginatedResponse<Chainage>> => {
|
|
const skip = params?.skip ?? 0;
|
|
const limit = params?.limit ?? 100;
|
|
const response = await axiosClient.get<PaginatedResponse<Chainage>>(`/chainages/`, {
|
|
params: { package_id: packageId, skip, limit },
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Create a new chainage
|
|
*/
|
|
createChainage: async (data: ChainageCreate): Promise<Chainage> => {
|
|
const response = await axiosClient.post<Chainage>('/chainages/', data);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Update an existing chainage
|
|
*/
|
|
updateChainage: async (chainageId: string, data: ChainageUpdate): Promise<Chainage> => {
|
|
const response = await axiosClient.put<Chainage>(`/chainages/${chainageId}`, data);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Delete a chainage
|
|
*/
|
|
deleteChainage: async (chainageId: string): Promise<{ message: string }> => {
|
|
const response = await axiosClient.delete<{ message: string }>(`/chainages/${chainageId}`);
|
|
return response.data;
|
|
},
|
|
};
|