54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
'use server'
|
|
|
|
import { Sites } from "@/_config/sites";
|
|
import { Anlage } from "@/types/rk";
|
|
import { revalidatePath } from "next/cache";
|
|
|
|
export async function api_anlagen_getAll(): Promise<Anlage[]> {
|
|
|
|
const result = await fetch(`http://localhost:3000/anlage`, {
|
|
method: 'GET',
|
|
headers: { 'Content-Type': 'application/json' }
|
|
});
|
|
|
|
const data = await result.json();
|
|
|
|
return data;
|
|
}
|
|
|
|
export async function api_anlage_getSelected(): Promise<Anlage> {
|
|
|
|
const result = await fetch(`http://localhost:3000/anlage/selected`, {
|
|
method: 'GET',
|
|
headers: { 'Content-Type': 'application/json' }
|
|
});
|
|
|
|
const data = await result.json();
|
|
|
|
return data;
|
|
}
|
|
|
|
export async function api_anlage_setSelected(id: string): Promise<Anlage> {
|
|
console.log(`http://localhost:3000/anlage/selected/${id}`);
|
|
|
|
const result = await fetch(`http://localhost:3000/anlage/selected/${id}`, {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' }
|
|
});
|
|
|
|
const data = await result.json();
|
|
|
|
|
|
console.log(result.status, result.statusText);
|
|
|
|
if (!result.ok) {
|
|
const error = await result.text();
|
|
throw new Error(`API Fehler ${result.status}: ${error}`);
|
|
}
|
|
|
|
revalidatePath(Sites.anlagen.url);
|
|
return data;
|
|
|
|
}
|
|
|