1-import type { Order } from './types'
1+import type { Order, User } from './types'
22 import { db } from './db'
4-export async function getOrdersWithUsers(orderIds: string[]): Promise<Order[]> {
5- return db.orders.findMany({ where: { id: { in: orderIds } } })
4+export async function getOrdersWithUsers(orderIds: string[]): Promise<(Order & { user: User })[]> {
5+ const result: (Order & { user: User })[] = []
7+ for (const orderId of orderIds) {
8+ const order = await db.orders.findById(orderId)
11+ const user = await db.users.findById(order.userId)
14+ const itemsWithDetails = []
15+ for (const item of order.items) {
16+ const product = await db.products.findById(item.productId)
17+ itemsWithDetails.push({ ...item, product })
20+ result.push({ ...order, user, items: itemsWithDetails } as any)