From 5849581efb842e84b6e26281381ae25073325ffb Mon Sep 17 00:00:00 2001 From: Nikhil Dange Date: Mon, 25 Mar 2024 17:33:06 -0700 Subject: [PATCH] Fix null linkedEvent for some Order routes (#419) * added left join for getOrder and getAllOrders * fixed order queries with linkedEvent joins * bumped package version to 3.4.3 * removed unnecessary join * cleanup --- package.json | 2 +- repositories/MerchOrderRepository.ts | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index dc8cdcc8..188180e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@acmucsd/membership-portal", - "version": "3.4.2", + "version": "3.4.3", "description": "REST API for ACM UCSD's membership portal.", "main": "index.d.ts", "files": [ diff --git a/repositories/MerchOrderRepository.ts b/repositories/MerchOrderRepository.ts index 139677da..769ceefd 100644 --- a/repositories/MerchOrderRepository.ts +++ b/repositories/MerchOrderRepository.ts @@ -11,7 +11,7 @@ import { MerchandiseItemModel } from '../models/MerchandiseItemModel'; export class MerchOrderRepository extends BaseRepository { /** * Gets a single order. Returns the order joined with ordered items, - * user, pickup event, the ordered items' merch options, + * user, pickup event, the pickup event's linked event, the ordered items' merch options, * and those merch options' merch items. * * This is the same set of joins that gets executed for OrderPickupEventRepository::findByUuid() @@ -25,12 +25,13 @@ export class MerchOrderRepository extends BaseRepository { .leftJoinAndSelect('orderItem.option', 'option') .leftJoinAndSelect('option.item', 'merchItem') .leftJoinAndSelect('merchItem.merchPhotos', 'merchPhotos') + .leftJoinAndSelect('orderPickupEvent.linkedEvent', 'linkedEvent') .where('order.uuid = :uuid', { uuid }) .getOne(); } /** - * Gets all orders for all users. Returns the order joined with its pickup event. + * Gets all orders for all users. Returns the order joined with its pickup event and linked event. * Can optionally filter by order status. */ public async getAllOrdersForAllUsers(...statuses: OrderStatus[]): Promise { @@ -41,14 +42,25 @@ export class MerchOrderRepository extends BaseRepository { }, }); } - return this.repository.find(); + return this.repository + .createQueryBuilder('order') + .leftJoinAndSelect('order.pickupEvent', 'orderPickupEvent') + .leftJoinAndSelect('order.user', 'user') + .leftJoinAndSelect('orderPickupEvent.linkedEvent', 'linkedEvent') + .getMany(); } /** - * Gets all orders for a given user. Returns the order joined with its pickup event and user. + * Gets all orders for a given user. Returns the order joined with its pickup event, linked event, and user. */ public async getAllOrdersForUser(user: UserModel): Promise { - return this.repository.find({ user }); + return this.repository + .createQueryBuilder('order') + .leftJoinAndSelect('order.pickupEvent', 'orderPickupEvent') + .leftJoinAndSelect('order.user', 'user') + .leftJoinAndSelect('orderPickupEvent.linkedEvent', 'linkedEvent') + .where('order.user = :uuid', { uuid: user.uuid }) + .getMany(); } /**