This commit is contained in:
Jurgis Sakalauskas
2025-10-13 18:10:52 +03:00
parent ff18d0daeb
commit 7bc38e9a6e
7 changed files with 253 additions and 76 deletions
+53
View File
@@ -88,6 +88,7 @@ export interface ImportedItemData {
model: string | null;
note: string | null;
attributes: Record<string, unknown>;
sourceUrl?: string | null;
}
export const createItem = async (
@@ -131,3 +132,55 @@ export const importItemFromUrl = async (
return response.data;
};
export interface UpdateItemPayload {
manufacturer?: string | null;
model?: string;
status?: ItemStatus;
note?: string | null;
attributes?: Record<string, unknown>;
sourceUrl?: string | null;
sourceUrlId?: string | null;
}
export const updateItem = async (
itemId: string,
payload: UpdateItemPayload
): Promise<Item> => {
const body: Record<string, unknown> = {};
if ('manufacturer' in payload) {
body.manufacturer = payload.manufacturer ?? null;
}
if ('model' in payload) {
body.model = payload.model;
}
if ('status' in payload) {
body.status = payload.status;
}
if ('note' in payload) {
body.note = payload.note ?? null;
}
if ('attributes' in payload) {
body.attributes = payload.attributes ?? {};
}
if ('sourceUrl' in payload) {
body.sourceUrl = payload.sourceUrl ?? null;
}
if ('sourceUrlId' in payload) {
body.sourceUrlId = payload.sourceUrlId ?? null;
}
const response = await apiFetch<SingleItemResponse>(`/items/${itemId}`, {
method: 'PATCH',
body
});
return response.data;
};