Merge branch 'develop' into add-eslint

This commit is contained in:
Danel Kungla
2025-09-23 10:56:41 +03:00
7 changed files with 118 additions and 53 deletions

View File

@@ -51,27 +51,29 @@ export async function upsertMedipostActionLog({
medipostExternalOrderId?: string | null;
medipostPrivateMessageId?: string | null;
}) {
const { data } = await getSupabaseServerAdminClient()
const recordData = {
action,
xml,
has_analysis_results: hasAnalysisResults,
medusa_order_id: medusaOrderId,
response_xml: responseXml,
has_error: hasError,
medipost_external_order_id: medipostExternalOrderId,
medipost_private_message_id: medipostPrivateMessageId,
};
const query = getSupabaseServerAdminClient()
.schema('medreport')
.from('medipost_actions')
.upsert(
{
action,
xml,
has_analysis_results: hasAnalysisResults,
medusa_order_id: medusaOrderId,
response_xml: responseXml,
has_error: hasError,
medipost_external_order_id: medipostExternalOrderId,
medipost_private_message_id: medipostPrivateMessageId,
},
{
onConflict: 'medipost_private_message_id',
ignoreDuplicates: false,
},
)
.select('id')
.throwOnError();
.from('medipost_actions');
const { data } = medipostPrivateMessageId
? await query
.upsert(recordData, {
onConflict: 'medipost_private_message_id',
ignoreDuplicates: false,
})
.select('id')
.throwOnError()
: await query.insert(recordData).select('id').throwOnError();
const medipostActionId = data?.[0]?.id;
if (!medipostActionId) {

View File

@@ -369,6 +369,7 @@ export async function readPrivateMessageResponse({
const hasInvalidOrderId = isNaN(analysisOrderId);
if (hasInvalidOrderId || !messageResponse || !patientPersonalCode) {
console.error(`Invalid order id or message response or patient personal code, medipostExternalOrderId=${medipostExternalOrderId}, privateMessageId=${privateMessageId}`);
await upsertMedipostActionLog({
action: 'sync_analysis_results_from_medipost',
xml: privateMessageXml,
@@ -415,6 +416,7 @@ export async function readPrivateMessageResponse({
order: analysisOrder,
});
console.info(`Successfully synced analysis results from Medipost message privateMessageId=${privateMessageId}`);
await upsertMedipostActionLog({
action: 'sync_analysis_results_from_medipost',
xml: privateMessageXml,
@@ -571,6 +573,7 @@ export async function sendOrderToMedipost({
isMedipostError,
errorMessage: e.response,
});
console.error(`Failed to send order to Medipost, medusaOrderId=${medusaOrderId}, error=${e.response}`);
await upsertMedipostActionLog({
action: 'send_order_to_medipost',
xml: orderXml,
@@ -580,6 +583,7 @@ export async function sendOrderToMedipost({
hasError: true,
});
} else {
console.error(`Failed to send order to Medipost, medusaOrderId=${medusaOrderId}, error=${e}`);
await logMedipostDispatch({
medusaOrderId,
isSuccess: false,
@@ -596,6 +600,7 @@ export async function sendOrderToMedipost({
throw e;
}
console.info(`Successfully sent order to Medipost, medusaOrderId=${medusaOrderId}`);
await logMedipostDispatch({
medusaOrderId,
isSuccess: true,

View File

@@ -9,8 +9,6 @@ import { z } from 'zod';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { requireUserInServerComponent } from '../server/require-user-in-server-component';
const env = () =>
z
.object({