feat(MED-131): remove private messages with unknown order ID from queue
This commit is contained in:
@@ -221,10 +221,19 @@ export async function readPrivateMessageResponse({
|
||||
const messageResponse = privateMessageContent?.Saadetis?.Vastus;
|
||||
|
||||
if (!messageResponse) {
|
||||
throw new Error(`Invalid data in private message response`);
|
||||
throw new Error(`Private message response has no results yet`);
|
||||
}
|
||||
console.info(`Private message content: ${JSON.stringify(privateMessageContent)}`);
|
||||
|
||||
let order: Tables<{ schema: 'medreport' }, 'analysis_orders'>;
|
||||
try {
|
||||
order = await getOrder({ medusaOrderId: messageResponse.ValisTellimuseId });
|
||||
} catch (e) {
|
||||
await deletePrivateMessage(privateMessage.messageId);
|
||||
throw new Error(`Order not found by Medipost message ValisTellimuseId=${messageResponse.ValisTellimuseId}`);
|
||||
}
|
||||
|
||||
const status = await syncPrivateMessage({ messageResponse });
|
||||
const status = await syncPrivateMessage({ messageResponse, order });
|
||||
|
||||
if (status === 'COMPLETED') {
|
||||
await deletePrivateMessage(privateMessage.messageId);
|
||||
@@ -552,14 +561,13 @@ function getLatestMessage({
|
||||
|
||||
export async function syncPrivateMessage({
|
||||
messageResponse,
|
||||
order,
|
||||
}: {
|
||||
messageResponse: MedipostOrderResponse['Saadetis']['Vastus'];
|
||||
order: Tables<{ schema: 'medreport' }, 'analysis_orders'>;
|
||||
}) {
|
||||
const supabase = getSupabaseServerAdminClient()
|
||||
|
||||
const status = messageResponse.TellimuseOlek;
|
||||
const order = await getOrder({ medusaOrderId: messageResponse.ValisTellimuseId });
|
||||
|
||||
const { data: analysisOrder, error: analysisOrderError } = await supabase
|
||||
.schema('medreport')
|
||||
.from('analysis_orders')
|
||||
@@ -579,7 +587,7 @@ export async function syncPrivateMessage({
|
||||
{
|
||||
analysis_order_id: order.id,
|
||||
order_number: messageResponse.TellimuseNumber,
|
||||
order_status: AnalysisOrderStatus[status],
|
||||
order_status: AnalysisOrderStatus[messageResponse.TellimuseOlek],
|
||||
user_id: analysisOrder[0].user_id,
|
||||
},
|
||||
{ onConflict: 'order_number', ignoreDuplicates: false },
|
||||
@@ -651,7 +659,7 @@ export async function syncPrivateMessage({
|
||||
);
|
||||
}
|
||||
|
||||
return AnalysisOrderStatus[status];
|
||||
return AnalysisOrderStatus[messageResponse.TellimuseOlek];
|
||||
}
|
||||
|
||||
export async function sendOrderToMedipost({
|
||||
|
||||
Reference in New Issue
Block a user