MED-103: add booking functionality
This commit is contained in:
65
app/home/(user)/_lib/server/actions.ts
Normal file
65
app/home/(user)/_lib/server/actions.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
'use server';
|
||||
|
||||
import { StoreProductVariant } from '@medusajs/types';
|
||||
|
||||
import {
|
||||
bookAppointment,
|
||||
createInitialReservation,
|
||||
} from '~/lib/services/connected-online.service';
|
||||
import { handleAddToCart } from '~/lib/services/medusaCart.service';
|
||||
|
||||
import { updateLineItem } from '../../../../../packages/features/medusa-storefront/src/lib/data';
|
||||
|
||||
export async function bookTimeAction(
|
||||
serviceId: number,
|
||||
clinicId: number,
|
||||
appointmentUserId: number,
|
||||
syncUserId: number,
|
||||
startTime: Date,
|
||||
comments?: string,
|
||||
) {
|
||||
return bookAppointment(
|
||||
serviceId,
|
||||
clinicId,
|
||||
appointmentUserId,
|
||||
syncUserId,
|
||||
startTime,
|
||||
comments,
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
startTime,
|
||||
addedItem.id,
|
||||
locationId,
|
||||
comments,
|
||||
);
|
||||
|
||||
await updateLineItem({
|
||||
lineId: addedItem.id,
|
||||
quantity: addedItem.quantity,
|
||||
metadata: { connectedOnlineReservationId: reservation.id },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user