Zoek functie voor items toegevoegd

This commit is contained in:
LogJurgenR
2026-08-19 17:15:28 +02:00
parent 686339325e
commit 16cee03332
5 changed files with 174 additions and 80 deletions
+22 -1
View File
@@ -1,7 +1,9 @@
"use server";
import { executeHttpRequest } from "@sap-cloud-sdk/http-client";
type Item = {
export type Item = {
ItemCode: string;
ItemName: string;
};
@@ -22,3 +24,22 @@ export async function getItems(): Promise<{ items: Item[]; error: string }> {
};
}
}
export async function searchItems(query: string): Promise<{ items: Item[]; error: string }> {
const escapedQuery = query.replaceAll("'", "''");
try {
const response = await executeHttpRequest(
{ destinationName: "SAP4SL" },
{ method: "GET", url: `/b1s/v2/Items?$filter=contains(ItemName,'${escapedQuery}')` },
);
return { items: response.data.value || [], error: "" };
} catch (error) {
console.error(error);
return {
items: [],
error: "items_request_failed",
};
}
}