F4 WEB: add Inventory function API client
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { apiRequest } from './api';
|
||||
|
||||
export interface InventoryFunction {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
isActive: boolean;
|
||||
sortOrder: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface InventoryFunctionAssignment {
|
||||
id: string;
|
||||
assetId: string;
|
||||
functionId: string;
|
||||
functionCode: string;
|
||||
functionName: string;
|
||||
validFrom: string;
|
||||
validUntil: string | null;
|
||||
reason: string | null;
|
||||
changedBy: string | null;
|
||||
changedByUsername: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface InventoryFunctionHistory {
|
||||
asset: {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
typeCode: string;
|
||||
typeName: string;
|
||||
familyCode: string | null;
|
||||
familyName: string | null;
|
||||
};
|
||||
currentFunction: InventoryFunctionAssignment | null;
|
||||
history: InventoryFunctionAssignment[];
|
||||
}
|
||||
|
||||
export async function listInventoryFunctions(includeInactive = false) {
|
||||
const query = includeInactive ? '?includeInactive=true' : '';
|
||||
return (await apiRequest<{ data: InventoryFunction[] }>(`/inventory-functions${query}`)).data;
|
||||
}
|
||||
|
||||
export function getInventoryFunctionHistory(assetId: string) {
|
||||
return apiRequest<InventoryFunctionHistory>(`/assets/${assetId}/function-history`);
|
||||
}
|
||||
|
||||
export function changeInventoryFunction(
|
||||
assetId: string,
|
||||
input: { functionId: string; effectiveAt?: string; reason?: string | null },
|
||||
) {
|
||||
return apiRequest<InventoryFunctionHistory>(`/assets/${assetId}/function`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function createInventoryFunction(input: {
|
||||
code: string;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
sortOrder?: number;
|
||||
}) {
|
||||
return apiRequest<InventoryFunction>('/inventory-functions', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function updateInventoryFunction(
|
||||
id: string,
|
||||
input: {
|
||||
name?: string;
|
||||
description?: string | null;
|
||||
isActive?: boolean;
|
||||
sortOrder?: number;
|
||||
},
|
||||
) {
|
||||
return apiRequest<InventoryFunction>(`/inventory-functions/${id}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user