Merge branch 'develop' into MED-49
This commit is contained in:
@@ -16,8 +16,8 @@ import axios from 'axios';
|
||||
import { toArray } from '@kit/shared/utils';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
|
||||
import type { AnalysisOrder } from '~/lib/types/analysis-order';
|
||||
import type { AnalysisResponseElement } from '~/lib/types/analysis-response-element';
|
||||
import type { AnalysisOrder } from '~/lib/types/order';
|
||||
|
||||
import { getAccountAdmin } from '../account.service';
|
||||
import { getAnalyses } from '../analyses.service';
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
upsertAnalysisResponseElement,
|
||||
} from '../analysis-order.service';
|
||||
import { logMedipostDispatch } from '../audit.service';
|
||||
import { getAnalysisOrder, updateAnalysisOrderStatus } from '../order.service';
|
||||
import { getAnalysisOrder } from '../order.service';
|
||||
import { parseXML } from '../util/xml.service';
|
||||
import { MedipostValidationError } from './MedipostValidationError';
|
||||
import {
|
||||
@@ -430,17 +430,19 @@ export async function readPrivateMessageResponse({
|
||||
medipostExternalOrderId,
|
||||
});
|
||||
if (status.isPartial) {
|
||||
await updateAnalysisOrderStatus({
|
||||
medusaOrderId,
|
||||
orderStatus: 'PARTIAL_ANALYSIS_RESPONSE',
|
||||
});
|
||||
await createUserAnalysesApi(getSupabaseServerAdminClient())
|
||||
.updateAnalysisOrderStatus({
|
||||
medusaOrderId,
|
||||
orderStatus: 'PARTIAL_ANALYSIS_RESPONSE',
|
||||
});
|
||||
hasAnalysisResponse = true;
|
||||
hasPartialAnalysisResponse = true;
|
||||
} else if (status.isCompleted) {
|
||||
await updateAnalysisOrderStatus({
|
||||
medusaOrderId,
|
||||
orderStatus: 'FULL_ANALYSIS_RESPONSE',
|
||||
});
|
||||
await createUserAnalysesApi(getSupabaseServerAdminClient())
|
||||
.updateAnalysisOrderStatus({
|
||||
medusaOrderId,
|
||||
orderStatus: 'FULL_ANALYSIS_RESPONSE',
|
||||
});
|
||||
if (IS_ENABLED_DELETE_PRIVATE_MESSAGE) {
|
||||
await deletePrivateMessage(privateMessageId);
|
||||
}
|
||||
@@ -622,5 +624,9 @@ export async function sendOrderToMedipost({
|
||||
hasAnalysisResults: false,
|
||||
medusaOrderId,
|
||||
});
|
||||
await updateAnalysisOrderStatus({ medusaOrderId, orderStatus: 'PROCESSING' });
|
||||
await createUserAnalysesApi(getSupabaseServerAdminClient())
|
||||
.updateAnalysisOrderStatus({
|
||||
medusaOrderId,
|
||||
orderStatus: 'PROCESSING',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -92,9 +92,15 @@ export async function handleDeleteCartItem({ lineId }: { lineId: string }) {
|
||||
export async function handleNavigateToPayment({
|
||||
language,
|
||||
paymentSessionId,
|
||||
amount,
|
||||
currencyCode,
|
||||
cartId,
|
||||
}: {
|
||||
language: string;
|
||||
paymentSessionId: string;
|
||||
amount: number;
|
||||
currencyCode: string;
|
||||
cartId: string;
|
||||
}) {
|
||||
const { account } = await loadCurrentUserAccount();
|
||||
if (!account) {
|
||||
@@ -137,11 +143,11 @@ export async function handleNavigateToPayment({
|
||||
await new MontonioOrderHandlerService().getMontonioPaymentLink({
|
||||
notificationUrl: `${env().medusaBackendPublicUrl}/hooks/payment/montonio_montonio`,
|
||||
returnUrl: `${env().siteUrl}/home/cart/montonio-callback`,
|
||||
amount: cart.total,
|
||||
currency: cart.currency_code.toUpperCase(),
|
||||
amount,
|
||||
currency: currencyCode.toUpperCase(),
|
||||
description: `Order from Medreport`,
|
||||
locale: language,
|
||||
merchantReference: `${account.id}:${paymentSessionId}:${cart.id}`,
|
||||
merchantReference: `${account.id}:${paymentSessionId}:${cartId}`,
|
||||
});
|
||||
|
||||
await createCartEntriesLog({
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Tables } from '@kit/supabase/database';
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import type { AnalysisOrder } from '../types/analysis-order';
|
||||
import type { AnalysisOrder, TTOOrder } from '../types/order';
|
||||
|
||||
export async function createAnalysisOrder({
|
||||
medusaOrder,
|
||||
@@ -51,48 +51,6 @@ export async function createAnalysisOrder({
|
||||
return orderResult.data.id;
|
||||
}
|
||||
|
||||
export async function updateAnalysisOrder({
|
||||
orderId,
|
||||
orderStatus,
|
||||
}: {
|
||||
orderId: number;
|
||||
orderStatus: Tables<{ schema: 'medreport' }, 'analysis_orders'>['status'];
|
||||
}) {
|
||||
console.info(`Updating order id=${orderId} status=${orderStatus}`);
|
||||
await getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('analysis_orders')
|
||||
.update({
|
||||
status: orderStatus,
|
||||
})
|
||||
.eq('id', orderId)
|
||||
.throwOnError();
|
||||
}
|
||||
|
||||
export async function updateAnalysisOrderStatus({
|
||||
orderId,
|
||||
medusaOrderId,
|
||||
orderStatus,
|
||||
}: {
|
||||
orderId?: number;
|
||||
medusaOrderId?: string;
|
||||
orderStatus: Tables<{ schema: 'medreport' }, 'analysis_orders'>['status'];
|
||||
}) {
|
||||
const orderIdParam = orderId;
|
||||
const medusaOrderIdParam = medusaOrderId;
|
||||
if (!orderIdParam && !medusaOrderIdParam) {
|
||||
throw new Error('Either orderId or medusaOrderId must be provided');
|
||||
}
|
||||
await getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.rpc('update_analysis_order_status', {
|
||||
order_id: orderIdParam ?? -1,
|
||||
status_param: orderStatus,
|
||||
medusa_order_id_param: medusaOrderIdParam ?? '',
|
||||
})
|
||||
.throwOnError();
|
||||
}
|
||||
|
||||
export async function getAnalysisOrder({
|
||||
medusaOrderId,
|
||||
analysisOrderId,
|
||||
@@ -176,10 +134,7 @@ export async function getTtoOrders({
|
||||
orderStatus,
|
||||
lineItemIds,
|
||||
}: {
|
||||
orderStatus?: Tables<
|
||||
{ schema: 'medreport' },
|
||||
'connected_online_reservation'
|
||||
>['status'];
|
||||
orderStatus?: TTOOrder['status'];
|
||||
lineItemIds?: string[];
|
||||
} = {}) {
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
@@ -150,16 +150,25 @@ export async function getCartReservations(
|
||||
return results;
|
||||
}
|
||||
|
||||
export async function createInitialReservation(
|
||||
serviceId: number,
|
||||
clinicId: number,
|
||||
appointmentUserId: number,
|
||||
syncUserID: number,
|
||||
startTime: Date,
|
||||
medusaLineItemId: string,
|
||||
locationId?: number | null,
|
||||
export async function createInitialReservation({
|
||||
serviceId,
|
||||
clinicId,
|
||||
appointmentUserId,
|
||||
syncUserID,
|
||||
startTime,
|
||||
medusaLineItemId,
|
||||
locationId,
|
||||
comments = '',
|
||||
) {
|
||||
}: {
|
||||
serviceId: number;
|
||||
clinicId: number;
|
||||
appointmentUserId: number;
|
||||
syncUserID: number;
|
||||
startTime: Date;
|
||||
medusaLineItemId: string;
|
||||
locationId?: number | null;
|
||||
comments?: string;
|
||||
}) {
|
||||
const logger = await getLogger();
|
||||
const supabase = getSupabaseServerClient();
|
||||
|
||||
@@ -255,15 +264,23 @@ export async function getOrderedTtoServices({
|
||||
return orderedTtoServices;
|
||||
}
|
||||
|
||||
export async function updateReservationTime(
|
||||
reservationId: number,
|
||||
newStartTime: Date,
|
||||
newServiceId: number,
|
||||
newAppointmentUserId: number,
|
||||
newSyncUserId: number,
|
||||
newLocationId: number | null, // TODO stop allowing null when Connected starts returning the correct ids instead of -1
|
||||
cartId: string,
|
||||
) {
|
||||
export async function updateReservationTime({
|
||||
reservationId,
|
||||
newStartTime,
|
||||
newServiceId,
|
||||
newAppointmentUserId,
|
||||
newSyncUserId,
|
||||
newLocationId, // TODO stop allowing null when Connected starts returning the correct ids instead of -1
|
||||
cartId,
|
||||
}: {
|
||||
reservationId: number;
|
||||
newStartTime: Date;
|
||||
newServiceId: number;
|
||||
newAppointmentUserId: number;
|
||||
newSyncUserId: number;
|
||||
newLocationId: number | null;
|
||||
cartId: string;
|
||||
}) {
|
||||
const logger = await getLogger();
|
||||
const supabase = getSupabaseServerClient();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user