don't upsert if audit log doesn't have medipost_private_message_id, improve logging
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user