54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import api from '../../../services/api';
|
|
import type {
|
|
UnitOfMeasureResponse,
|
|
CreateUnitOfMeasureData,
|
|
UpdateUnitOfMeasureData,
|
|
SingleUnitOfMeasureResponse
|
|
} from '../types/unitOfMeasure';
|
|
|
|
export const unitOfMeasureService = {
|
|
/**
|
|
* Get all units of measure with pagination
|
|
*/
|
|
async getUnits(page = 1, perPage = 10): Promise<UnitOfMeasureResponse> {
|
|
const response = await api.get(`/api/catalogs/units-of-measure`, {
|
|
params: { page, per_page: perPage }
|
|
});
|
|
|
|
console.log('Units of Measure response:', response);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Get a single unit of measure by ID
|
|
*/
|
|
async getUnitById(id: number): Promise<SingleUnitOfMeasureResponse> {
|
|
const response = await api.get(`/api/catalogs/units-of-measure/${id}`);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Create a new unit of measure
|
|
*/
|
|
async createUnit(data: CreateUnitOfMeasureData): Promise<SingleUnitOfMeasureResponse> {
|
|
const response = await api.post(`/api/catalogs/units-of-measure`, data);
|
|
console.log('Create Unit response:', response);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Update an existing unit of measure
|
|
*/
|
|
async updateUnit(id: number, data: UpdateUnitOfMeasureData): Promise<SingleUnitOfMeasureResponse> {
|
|
const response = await api.put(`/api/catalogs/units-of-measure/${id}`, data);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Delete a unit of measure
|
|
*/
|
|
async deleteUnit(id: number): Promise<void> {
|
|
await api.delete(`/api/catalogs/units-of-measure/${id}`);
|
|
}
|
|
};
|