Before branching response
checkout.ts
export async function checkout(cart: Cart) {
if (cart.items.length === 0) {
return { status: "empty", total: 0 };
}
const total = cart.items.reduce((sum, item) => {
return sum + item.price * item.quantity;
}, 0);
return { status: "ready", total };
}
checkout.ts
export async function checkout(cart: Cart) {
const total = cart.items.reduce((sum, item) => {
return sum + item.price * item.quantity;
}, 0);
return {
status: cart.items.length > 0 ? "ready" : "empty",
total,
};
}