65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
'use server'
|
|
|
|
import { Sites } from "@/_config/sites";
|
|
import { VisuElement, VisuElementCreate, VisuElementUpdate } from "@/types/visu/visuElements.types";
|
|
import { revalidatePath } from "next/cache";
|
|
|
|
export async function api_VisuElementsAll(): Promise<VisuElement[]> {
|
|
|
|
|
|
|
|
const result = await fetch(`http://localhost:3000/visu-elements`, {
|
|
method: 'GET',
|
|
headers: { 'Content-Type': 'application/json' }
|
|
});
|
|
|
|
const data = await result.json() as VisuElement[];
|
|
|
|
return data;
|
|
}
|
|
export async function api_VisuElementCreate(data: VisuElementCreate): Promise<ActionResult<VisuElement>> {
|
|
|
|
|
|
const result = await fetch(`http://localhost:3000/visu-elements/`, {
|
|
method: 'POST',
|
|
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.visu.url);
|
|
return { success: true };
|
|
|
|
}
|
|
|
|
export async function api_VisuElementUpdate(id: string, data: VisuElementUpdate): Promise<ActionResult<VisuElement>> {
|
|
|
|
|
|
const result = await fetch(`http://localhost:3000/visu-elements/${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.visu.url);
|
|
return { success: true };
|
|
|
|
}
|