Zoek functie voor items toegevoegd
This commit is contained in:
+22
-1
@@ -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",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user