feat: add location handling for TTO orders and update related components

This commit is contained in:
Danel Kungla
2025-09-30 18:05:32 +03:00
parent bfdd1ec62a
commit 52eac590a4
7 changed files with 62 additions and 7 deletions

View File

@@ -205,5 +205,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;
}