44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
'use server';
|
|
|
|
import { updateLineItem } from '@lib/data/cart';
|
|
import { StoreProductVariant } from '@medusajs/types';
|
|
|
|
import { handleAddToCart } from '~/lib/services/medusaCart.service';
|
|
import { createInitialReservation } from '~/lib/services/reservation.service';
|
|
|
|
export async function createInitialReservationAction(
|
|
selectedVariant: Pick<StoreProductVariant, 'id'>,
|
|
countryCode: string,
|
|
serviceId: number,
|
|
clinicId: number,
|
|
appointmentUserId: number,
|
|
syncUserId: number,
|
|
startTime: Date,
|
|
locationId: number | null,
|
|
comments?: string,
|
|
) {
|
|
const { addedItem } = await handleAddToCart({
|
|
selectedVariant,
|
|
countryCode,
|
|
});
|
|
|
|
if (addedItem) {
|
|
const reservation = await createInitialReservation({
|
|
serviceId,
|
|
clinicId,
|
|
appointmentUserId,
|
|
syncUserID: syncUserId,
|
|
startTime,
|
|
medusaLineItemId: addedItem.id,
|
|
locationId,
|
|
comments,
|
|
});
|
|
|
|
await updateLineItem({
|
|
lineId: addedItem.id,
|
|
quantity: addedItem.quantity,
|
|
metadata: { connectedOnlineReservationId: reservation.id },
|
|
});
|
|
}
|
|
}
|