feat(MED-105): update order details redirect and shown page
This commit is contained in:
@@ -3,6 +3,8 @@ import type { Tables } from '@kit/supabase/database';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import type { StoreOrder } from '@medusajs/types';
|
||||
|
||||
export type AnalysisOrder = Tables<{ schema: 'medreport' }, 'analysis_orders'>;
|
||||
|
||||
export async function createOrder({
|
||||
medusaOrder,
|
||||
orderedAnalysisElements,
|
||||
@@ -32,6 +34,8 @@ export async function createOrder({
|
||||
if (orderResult.error || !orderResult.data?.id) {
|
||||
throw new Error(`Failed to create order, message=${orderResult.error}, data=${JSON.stringify(orderResult)}`);
|
||||
}
|
||||
|
||||
return orderResult.data.id;
|
||||
}
|
||||
|
||||
export async function updateOrder({
|
||||
@@ -56,14 +60,22 @@ export async function updateOrder({
|
||||
|
||||
export async function getOrder({
|
||||
medusaOrderId,
|
||||
orderId,
|
||||
}: {
|
||||
medusaOrderId: string;
|
||||
medusaOrderId?: string;
|
||||
orderId?: number;
|
||||
}) {
|
||||
const query = getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('analysis_orders')
|
||||
.select('*')
|
||||
.eq('medusa_order_id', medusaOrderId)
|
||||
if (medusaOrderId) {
|
||||
query.eq('medusa_order_id', medusaOrderId);
|
||||
} else if (orderId) {
|
||||
query.eq('id', orderId);
|
||||
} else {
|
||||
throw new Error('Either medusaOrderId or orderId must be provided');
|
||||
}
|
||||
|
||||
const { data: order } = await query.single().throwOnError();
|
||||
return order;
|
||||
|
||||
Reference in New Issue
Block a user