dannyeloD
Convex Community2y ago
2 replies
dannyelo

Extracted function types

Hello! I extracted a function to map a query. But I can't find the correct types.
I'm looking for the type order, orderLine, ctx and q.
order and orderLine are raw records in the database.

const transformOrderForClient = async (order: any, ctx: any) => {
  const orderLines = await ctx.db
    .query('order_lines')
    .filter((q: any) => q.eq(q.field('orderId'), order._id))
    .collect()

  const mappedOrderLines = await Promise.all(
    orderLines.map(async (orderLine: any) => {
      const product = await ctx.db.get(orderLine.productId)
      console.log('product', orderLine)

      return {
        // ...
      }
    }),
  )

  const grandTotalAmount = orderLines.reduce((acc: any, orderLine: any) => {
    return acc + orderLine?.price * orderLine?.quantity
  }, 0)
  const grandTotalQuantity = orderLines.reduce((acc: any, orderLine: any) => {
    return acc + orderLine.quantity
  }, 0)

  return {
    // ...
  }
}
Was this page helpful?