MED-103: add booking functionality

This commit is contained in:
Helena
2025-09-17 18:11:13 +03:00
parent 7c92b787ce
commit 22f7fa134b
44 changed files with 1923 additions and 479 deletions

View File

@@ -10,6 +10,7 @@ import { z } from 'zod';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { requireUserInServerComponent } from '../server/require-user-in-server-component';
import { cancelReservation } from './connected-online.service';
const env = () =>
z
@@ -26,8 +27,10 @@ const env = () =>
.min(1),
})
.parse({
medusaBackendPublicUrl: process.env.MEDUSA_BACKEND_PUBLIC_URL!,
siteUrl: process.env.NEXT_PUBLIC_SITE_URL!,
medusaBackendPublicUrl:
'http://weebhook.site:3000' /* process.env.MEDUSA_BACKEND_PUBLIC_URL! */,
siteUrl:
'http://weebhook.site:3000' /* process.env.NEXT_PUBLIC_SITE_URL! */,
});
export async function handleAddToCart({
@@ -44,7 +47,7 @@ export async function handleAddToCart({
}
const quantity = 1;
const cart = await addToCart({
const { newCart, addedItem } = await addToCart({
variantId: selectedVariant.id,
quantity,
countryCode,
@@ -54,18 +57,19 @@ export async function handleAddToCart({
variant_id: selectedVariant.id,
operation: 'ADD_TO_CART',
account_id: account.id,
cart_id: cart.id,
cart_id: newCart.id,
changed_by: user.id,
});
if (error) {
throw new Error('Error logging cart entry: ' + error.message);
}
return cart;
return { cart: newCart, addedItem };
}
export async function handleDeleteCartItem({ lineId }: { lineId: string }) {
await deleteLineItem(lineId);
await cancelReservation(lineId);
const supabase = getSupabaseServerClient();
const cartId = await getCartId();