umstellung auf claud
This commit is contained in:
1 parent
79c5f0c5cd
commit
5bb4e063da
171 files changed
+5471
-1333
No files matched your search
@@ -0,0 +1,53 @@
|
||||
'use server';
|
||||
|
||||
import { BACKEND_URL } from '@/_config/backend';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import type { UnitMaterialSettings, MaterialSensor } from '@/types/anlagen/materialfluss';
|
||||
|
||||
export interface UnitMaterialData {
|
||||
anlageId: string;
|
||||
version: number;
|
||||
settings: UnitMaterialSettings;
|
||||
sensors: MaterialSensor[];
|
||||
}
|
||||
|
||||
// Ohne Daten wird gelesen (GET), mit Daten gespeichert (PUT).
|
||||
async function request(id: string, data?: UnitMaterialData): Promise<UnitMaterialData> {
|
||||
const requestUrl = `${BACKEND_URL}/rk2/units/${encodeURIComponent(id)}/materialfluss`;
|
||||
const method = data ? 'PUT' : 'GET';
|
||||
|
||||
const body = data
|
||||
? JSON.stringify({
|
||||
anlageId: data.anlageId,
|
||||
version: data.version,
|
||||
settings: data.settings,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
const response = await fetch(requestUrl, {
|
||||
method,
|
||||
cache: 'no-store',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body,
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(result.message ?? 'Unit-Materialfluss konnte nicht gespeichert werden.');
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function api_unitMaterial(id: string) {
|
||||
return request(id);
|
||||
}
|
||||
|
||||
export async function api_saveUnitMaterial(id: string, data: UnitMaterialData) {
|
||||
const result = await request(id, data);
|
||||
|
||||
revalidatePath('/ablaeufe');
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user