Zoek functie voor items toegevoegd
This commit is contained in:
@@ -15,6 +15,7 @@ type TranslationKey =
|
||||
| "articles.emptyTitle"
|
||||
| "articles.emptyDescription"
|
||||
| "articles.error"
|
||||
| "articles.search"
|
||||
| "auth.logout"
|
||||
| "login.title"
|
||||
| "login.description"
|
||||
@@ -40,6 +41,7 @@ const translations: Record<Locale, Record<TranslationKey, string>> = {
|
||||
"articles.emptyTitle": "Geen artikelen gevonden",
|
||||
"articles.emptyDescription": "De Service Layer heeft geen artikelen teruggegeven.",
|
||||
"articles.error": "Er is een fout opgetreden bij het ophalen van de artikelen.",
|
||||
"articles.search": "Zoeken",
|
||||
"auth.logout": "Uitloggen",
|
||||
"login.title": "Inloggen",
|
||||
"login.description": "Log in om de artikelen te bekijken.",
|
||||
@@ -64,6 +66,7 @@ const translations: Record<Locale, Record<TranslationKey, string>> = {
|
||||
"articles.emptyTitle": "No items found",
|
||||
"articles.emptyDescription": "The Service Layer returned no items.",
|
||||
"articles.error": "An error occurred while retrieving the items.",
|
||||
"articles.search": "Search",
|
||||
"auth.logout": "Log out",
|
||||
"login.title": "Sign in",
|
||||
"login.description": "Sign in to view the items.",
|
||||
@@ -88,6 +91,7 @@ const translations: Record<Locale, Record<TranslationKey, string>> = {
|
||||
"articles.emptyTitle": "搵唔到貨品",
|
||||
"articles.emptyDescription": "Service Layer 冇返回任何貨品。",
|
||||
"articles.error": "取得貨品時發生錯誤。",
|
||||
"articles.search": "搜尋",
|
||||
"auth.logout": "登出",
|
||||
"login.title": "登入",
|
||||
"login.description": "登入後查看貨品。",
|
||||
|
||||
+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