60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
"use server";
|
|
|
|
import { Sites } from "@/_config/sites";
|
|
import { Group, Peripherie, PeripherieFilterOptionen, PeripherieUpdate } from "@/types/rk";
|
|
import { revalidatePath } from "next/cache";
|
|
|
|
|
|
|
|
export async function PeripherieFindApi(filter?: PeripherieFilterOptionen): Promise<Peripherie[]> {
|
|
let filterStr = '';
|
|
if (filter && (filter.adrByte || filter.elementId || filter.groupId)) {
|
|
filterStr = '?'
|
|
if (filter.adrByte) filterStr += 'adrByte=' + filter.adrByte;
|
|
if (filter.groupId) filterStr += 'groupId=' + filter.groupId;
|
|
if (filter.elementId) filterStr += 'elementId=' + filter.elementId;
|
|
}
|
|
console.log(`http://localhost:3000/peripherie` + filterStr)
|
|
const result = await fetch(`http://localhost:3000/peripherie` + filterStr, {
|
|
method: 'GET',
|
|
headers: { 'Content-Type': 'application/json' }
|
|
});
|
|
|
|
const data = await result.json();
|
|
|
|
return data;
|
|
}
|
|
|
|
export async function GetEA_Differences(): Promise<Peripherie[]> {
|
|
|
|
const result = await fetch(`http://localhost:3000/peripherie/differences`, {
|
|
method: 'GET',
|
|
headers: { 'Content-Type': 'application/json' }
|
|
});
|
|
|
|
const data = await result.json();
|
|
|
|
return data;
|
|
}
|
|
|
|
export async function api_peripherieUpdate(id: string, data: PeripherieUpdate): Promise<ActionResult<Peripherie>> {
|
|
|
|
const result = await fetch(`http://localhost:3000/peripherie/${id}`, {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(data),
|
|
})
|
|
|
|
const resultData = await result.json();
|
|
|
|
if (!result.ok) {
|
|
return {
|
|
success: false,
|
|
errors: resultData.message, // kommt aus NestJS
|
|
};
|
|
}
|
|
|
|
revalidatePath(Sites.peripheries.url);
|
|
return { success: true, data: resultData };
|
|
|
|
} |