'use server' import { Location, LocationCreate, LocationTreeNode, LocationUpdate } from "../types/inventory"; import { endpoints } from '../_config/endpoints'; import { revalidateTag, revalidatePath } from "next/cache" export async function locationCreate(data: LocationCreate) { console.log(`${endpoints.apiServer}${endpoints.location}`); const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data), }) const respData = await result.json(); revalidateTag("location", "default"); return respData; console.log(data) } export async function locationUpdate(id: string, data: LocationUpdate) { const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}/${id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data), }) const respData = await result.json(); revalidateTag("location", "default"); return respData; } export async function locationFindAll(): Promise { const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}`, { method: 'GET', headers: { 'Content-Type': 'application/json' } }) const data = await result.json(); return data; } export async function locationTree(): Promise { const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.treeView.url}`, { next: { tags: ["location"] }, method: 'GET', headers: { 'Content-Type': 'application/json' } }) const data = await result.json(); return data; } export async function locationFindById(id: string): Promise { const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}/${id}`, { method: 'GET', headers: { 'Content-Type': 'application/json' } }) const respData = await result.json(); return respData; }