fix tto order tables
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
'use server';
|
||||
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
import { updateLineItem } from '@lib/data/cart';
|
||||
import { StoreProductVariant } from '@medusajs/types';
|
||||
|
||||
@@ -89,3 +90,22 @@ export async function cancelTtoBooking(
|
||||
console.error('Error cancelling booking: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function isPaymentRequiredForService(serviceId: number) {
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
|
||||
try {
|
||||
const { data } = await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('connected_online_services')
|
||||
.select('requires_payment')
|
||||
.eq('id', serviceId)
|
||||
.is('requires_payment', true)
|
||||
.maybeSingle();
|
||||
|
||||
return !!data;
|
||||
} catch (error) {
|
||||
console.error('Error checking payment requirement: ', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ import { z } from 'zod';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
|
||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||
import {
|
||||
bookAppointment,
|
||||
getConfirmedService,
|
||||
} from '~/lib/services/connected-online.service';
|
||||
import { bookAppointment } from '~/lib/services/connected-online.service';
|
||||
import { sendOrderToMedipost } from '~/lib/services/medipost/medipostPrivateMessage.service';
|
||||
import { handleNavigateToPayment } from '~/lib/services/medusaCart.service';
|
||||
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
|
||||
|
||||
@@ -2,6 +2,7 @@ import { cache } from 'react';
|
||||
|
||||
import { getProductCategories, listProducts } from '@lib/data';
|
||||
|
||||
import { isPaymentRequiredForService } from './actions';
|
||||
import { loadCountryCodes } from './load-analyses';
|
||||
|
||||
async function categoryLoader({ handle }: { handle: string }) {
|
||||
@@ -26,6 +27,24 @@ async function categoryLoader({ handle }: { handle: string }) {
|
||||
queryParams: { limit: 100, category_id: response.product_categories[0].id },
|
||||
});
|
||||
|
||||
const productsWithNoRequiredPayment = categoryProducts.filter(
|
||||
async (product) => {
|
||||
if (product.metadata?.serviceIds) {
|
||||
const serviceIds: number[] = JSON.parse(
|
||||
product.metadata.serviceIds as string,
|
||||
);
|
||||
for (const serviceId of serviceIds) {
|
||||
const requiresPayment = await isPaymentRequiredForService(serviceId);
|
||||
if (requiresPayment) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
category: {
|
||||
color:
|
||||
@@ -36,7 +55,7 @@ async function categoryLoader({ handle }: { handle: string }) {
|
||||
handle: category?.handle || '',
|
||||
name: category?.name || '',
|
||||
countryCode,
|
||||
products: categoryProducts,
|
||||
products: productsWithNoRequiredPayment,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user