don't upsert if audit log doesn't have medipost_private_message_id, improve logging

This commit is contained in:
Karli
2025-09-22 15:31:06 +03:00
parent 5f0ca6bdae
commit 428a1dfb87
4 changed files with 32 additions and 23 deletions

View File

@@ -49,27 +49,30 @@ export async function upsertMedipostActionLog({
medipostExternalOrderId?: string | null;
medipostPrivateMessageId?: string | null;
}) {
const { data } = await 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();
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');
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) {