feat(MED-161): update sync private message
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { getSupabaseServerAdminClient } from "@/packages/supabase/src/clients/server-admin-client";
|
||||
import type { AnalysisResponseElement } from "../types/analysis-response-element";
|
||||
import { AnalysisOrderStatus } from '@/packages/shared/src/types/medipost-analysis';
|
||||
|
||||
export async function getExistingAnalysisResponseElements({
|
||||
analysisResponseId,
|
||||
@@ -15,3 +16,40 @@ export async function getExistingAnalysisResponseElements({
|
||||
|
||||
return data as AnalysisResponseElement[];
|
||||
}
|
||||
|
||||
export async function upsertAnalysisResponse({
|
||||
analysisOrderId,
|
||||
orderNumber,
|
||||
orderStatus,
|
||||
userId,
|
||||
}: {
|
||||
analysisOrderId: number;
|
||||
orderNumber: string;
|
||||
orderStatus: typeof AnalysisOrderStatus[keyof typeof AnalysisOrderStatus];
|
||||
userId: string;
|
||||
}) {
|
||||
const { data: analysisResponse } = await getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('analysis_responses')
|
||||
.upsert(
|
||||
{
|
||||
analysis_order_id: analysisOrderId,
|
||||
order_number: orderNumber,
|
||||
order_status: orderStatus,
|
||||
user_id: userId,
|
||||
},
|
||||
{ onConflict: 'order_number', ignoreDuplicates: false },
|
||||
)
|
||||
.select('id')
|
||||
.throwOnError();
|
||||
|
||||
|
||||
const analysisResponseId = analysisResponse?.[0]?.id;
|
||||
if (!analysisResponseId) {
|
||||
throw new Error(
|
||||
`Failed to insert or update analysis order response (order id: ${analysisOrderId}, order number: ${orderNumber})`,
|
||||
);
|
||||
}
|
||||
|
||||
return { analysisResponseId };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user