simple-kiosk-app/app/order/action.ts

31 lines
814 B
TypeScript
Raw Permalink Normal View History

2024-04-20 19:58:18 +09:00
"use server";
import { Order } from "@/hooks/useOrder";
import { saveOrder, Payment, cancelOrder, completeOrder } from "@/lib/db";
import { revalidatePath } from "next/cache";
export async function saveOrderApi(orders: Order[], payment: Payment){
console.log(orders, "주문");
// db에 주문 저장
const id = await saveOrder(orders, payment);
// cache revaildation
revalidatePath("/", "page");
return {
id,
completed : false,
orders: orders,
};
}
export async function cancelOrderApi(uid: string){
await cancelOrder(uid);
revalidatePath("/", "page");
}
export async function completeOrderApi(uid: string, completed: boolean = true){
await completeOrder(uid, completed);
revalidatePath("/", "page");
revalidatePath("/stat", "page");
}