import type { Repository, SelectQueryBuilder } from 'typeorm'; import { Order } from '../../modules/order/entities/Order'; export const createOrderDetailQuery = (orderRepo: Repository, orderId: string): SelectQueryBuilder => orderRepo .createQueryBuilder('order') .leftJoinAndSelect('order.lines', 'orderLine') .leftJoinAndSelect('orderLine.autoFulfillmentItems', 'autoFulfillmentItem') .leftJoinAndSelect('autoFulfillmentItem.attachments', 'autoFulfillmentItemAttachment') .leftJoinAndSelect('orderLine.manualFulfillment', 'manualFulfillment') .leftJoinAndSelect('order.discounts', 'orderDiscount') .leftJoinAndSelect('order.checkoutInvoice', 'checkoutInvoice') .leftJoinAndSelect('checkoutInvoice.moneroDetails', 'checkoutMoneroDetails') .leftJoinAndSelect('checkoutInvoice.payments', 'checkoutPayment') .leftJoinAndSelect('order.shippingInvoice', 'shippingInvoice') .leftJoinAndSelect('shippingInvoice.moneroDetails', 'shippingMoneroDetails') .leftJoinAndSelect('shippingInvoice.payments', 'shippingPayment') .leftJoinAndSelect('order.messages', 'message') .addSelect('order.accessToken') .addSelect('autoFulfillmentItem.contentSnapshot') .addSelect('autoFulfillmentItemAttachment.storageKey') .orderBy('message.createdAt', 'ASC') .addOrderBy('autoFulfillmentItem.sortOrder', 'ASC') .where('order.id = :orderId', { orderId });