Skip to content

Commit

Permalink
Fix null linkedEvent for some Order routes (#419)
Browse files Browse the repository at this point in the history
* added left join for getOrder and getAllOrders

* fixed order queries with linkedEvent joins

* bumped package version to 3.4.3

* removed unnecessary join

* cleanup
  • Loading branch information
nik-dange authored Mar 26, 2024
1 parent 5c1bd1b commit 5849581
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
22 changes: 17 additions & 5 deletions repositories/MerchOrderRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MerchandiseItemModel } from '../models/MerchandiseItemModel';
export class MerchOrderRepository extends BaseRepository<OrderModel> {
/**
* 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()
Expand All @@ -25,12 +25,13 @@ export class MerchOrderRepository extends BaseRepository<OrderModel> {
.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<OrderModel[]> {
Expand All @@ -41,14 +42,25 @@ export class MerchOrderRepository extends BaseRepository<OrderModel> {
},
});
}
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<OrderModel[]> {
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();
}

/**
Expand Down

0 comments on commit 5849581

Please sign in to comment.