Files

49 lines
1.3 KiB
TypeScript

'use server'
import { revalidatePath } from 'next/cache'
import { Category, CategoryCreate } from "@/apps/frontend/types/catalog";
export async function categoryCreate(data: CategoryCreate) {
console.log(data);
const result = await fetch('http://192.168.50.205/api/categories', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
console.log(result);
revalidatePath('/test')
}
export async function categoryUpdate( id: string, data: Partial<CategoryCreate>) {
console.log(data,id);
const result = await fetch(`http://192.168.50.205/api/categories/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
console.log(result);
revalidatePath('/test')
}
export async function categoryFindAll():Promise<Category[]> {
const result = await fetch(`http://192.168.50.205/api/categories`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json();
return data;
}
export async function categoryFindById(id:string):Promise<Category> {
const result = await fetch(`http://192.168.50.205/api/categories/${id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json();
return data;
}