69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import axiosClient from '../axios/axios';
|
|
import {
|
|
Package,
|
|
PackageCreate,
|
|
PackageUpdate,
|
|
PaginatedResponse,
|
|
PaginationParams,
|
|
} from '@/types';
|
|
|
|
const PACKAGES_ENDPOINT = 'biz/api/v1/packages';
|
|
|
|
/**
|
|
* Package Service
|
|
*/
|
|
export const packageService = {
|
|
/**
|
|
* Fetch all packages
|
|
*/
|
|
getPackages: async (params?: PaginationParams): Promise<PaginatedResponse<Package>> => {
|
|
const skip = params?.skip ?? 0;
|
|
const limit = params?.limit ?? 100;
|
|
const response = await axiosClient.get<PaginatedResponse<Package>>(PACKAGES_ENDPOINT, {
|
|
params: { skip, limit },
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Fetch packages filtered by project ID
|
|
*/
|
|
getPackagesByProject: async (
|
|
projectId: string,
|
|
params?: PaginationParams,
|
|
): Promise<PaginatedResponse<Package>> => {
|
|
const skip = params?.skip ?? 0;
|
|
const limit = params?.limit ?? 100;
|
|
const response = await axiosClient.get<PaginatedResponse<Package>>(PACKAGES_ENDPOINT, {
|
|
params: { project_id: projectId, skip, limit },
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Create a new package
|
|
*/
|
|
createPackage: async (data: PackageCreate): Promise<Package> => {
|
|
const response = await axiosClient.post<Package>(PACKAGES_ENDPOINT, data);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Update an existing package
|
|
*/
|
|
updatePackage: async (packageId: string, data: PackageUpdate): Promise<Package> => {
|
|
const response = await axiosClient.put<Package>(`${PACKAGES_ENDPOINT}/${packageId}`, data);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Delete a package
|
|
*/
|
|
deletePackage: async (packageId: string): Promise<{ message: string }> => {
|
|
const response = await axiosClient.delete<{ message: string }>(
|
|
`${PACKAGES_ENDPOINT}/${packageId}`,
|
|
);
|
|
return response.data;
|
|
},
|
|
};
|