31 lines
814 B
TypeScript
31 lines
814 B
TypeScript
|
"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");
|
||
|
}
|