Med 102
This commit is contained in:
danelkungla
2025-10-01 16:23:31 +03:00
committed by GitHub
17 changed files with 231 additions and 17 deletions

View File

@@ -163,5 +163,42 @@ export async function getTtoOrders({
const orders = await query
.order('created_at', { ascending: false })
.throwOnError();
return orders.data;
const ordersWithLocation = await Promise.all(
orders.data.map(async (order) => ({
...order,
location: await getTtoLocation(order.location_sync_id),
})),
);
return ordersWithLocation;
}
export async function getTtoLocation(syncId?: number | null) {
if (!syncId) {
return null;
}
const client = getSupabaseServerClient();
const {
data: { user },
} = await client.auth.getUser();
if (!user) {
throw new Error('Unauthorized');
}
const { data, error } = await client
.schema('medreport')
.from('connected_online_locations')
.select('name')
.eq('sync_id', syncId)
.single();
if (error) {
throw new Error('Could not receive online locations: ', error);
}
return data;
}

View File

@@ -9,4 +9,7 @@ export type Order = {
medusaOrderId?: string;
id?: number;
status?: string;
location?: string;
bookingCode?: string | null;
clinicId?: number;
};