Skip to content

Commit

Permalink
fix(medusa): Select config should be undefined if length === 0 (#2469)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p authored Oct 20, 2022
1 parent 2f00bd1 commit 13611e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-cooks-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): Select config should be undefined if length === 0
6 changes: 1 addition & 5 deletions packages/medusa/src/services/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,7 @@ class CartService extends TransactionBaseService {
query.relations = relations
}

if (select && select.length > 0) {
query.select = select
} else {
query.select = undefined
}
query.select = select?.length ? select : undefined

const queryRelations = query.relations
query.relations = undefined
Expand Down
43 changes: 9 additions & 34 deletions packages/medusa/src/services/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,8 @@ class OrderService extends TransactionBaseService {
order: { created_at: "DESC" },
}
): Promise<Order[]> {
const orderRepo = this.manager_.getCustomRepository(this.orderRepository_)
const query = buildQuery(selector, config)

const { select, relations, totalsToSelect } =
this.transformQueryForTotals(config)

if (select && select.length) {
query.select = select
}

if (relations && relations.length) {
query.relations = relations
}

const raw = await orderRepo.find(query)

return await Promise.all(
raw.map(async (r) => await this.decorateTotals(r, totalsToSelect))
)
const [orders] = await this.listAndCount(selector, config)
return orders
}

/**
Expand Down Expand Up @@ -241,11 +224,9 @@ class OrderService extends TransactionBaseService {
const { select, relations, totalsToSelect } =
this.transformQueryForTotals(config)

if (select && select.length) {
query.select = select
}

query.select = select
const rels = relations

delete query.relations

const raw = await orderRepo.findWithRelations(rels, query)
Expand Down Expand Up @@ -314,14 +295,14 @@ class OrderService extends TransactionBaseService {
select = select.filter((v) => !totalFields.includes(v))
}

const toSelect = [...select]
const toSelect = select
if (toSelect.length > 0 && toSelect.indexOf("tax_rate") === -1) {
toSelect.push("tax_rate")
}

return {
relations,
select: toSelect,
select: toSelect.length ? toSelect : undefined,
totalsToSelect,
}
}
Expand Down Expand Up @@ -349,9 +330,7 @@ class OrderService extends TransactionBaseService {
query.relations = relations
}

if (select && select.length > 0) {
query.select = select
}
query.select = select?.length ? select : undefined

const rels = query.relations
delete query.relations
Expand Down Expand Up @@ -389,9 +368,7 @@ class OrderService extends TransactionBaseService {
query.relations = relations
}

if (select && select.length > 0) {
query.select = select
}
query.select = select?.length ? select : undefined

const raw = await orderRepo.findOne(query)

Expand Down Expand Up @@ -428,9 +405,7 @@ class OrderService extends TransactionBaseService {
query.relations = relations
}

if (select && select.length > 0) {
query.select = select
}
query.select = select?.length ? select : undefined

const rels = query.relations
delete query.relations
Expand Down

0 comments on commit 13611e3

Please sign in to comment.