Skip to content

Commit

Permalink
comment
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Oct 5, 2022
1 parent c2621e2 commit b5c4d83
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
8 changes: 6 additions & 2 deletions integration-tests/api/__tests__/admin/customer-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,17 @@ describe("/admin/customer-groups", () => {
}
}

const discountConditionId = IdMap.getId("discount-condition-tag-1")
const discountConditionId = IdMap.getId(
"discount-condition-customer-group-1"
)
await simpleDiscountFactory(
dbConnection,
buildDiscountData("code-1", discountConditionId, [customerGroup1.id])
)

const discountConditionId2 = IdMap.getId("discount-condition-tag-2")
const discountConditionId2 = IdMap.getId(
"discount-condition-customer-group-2"
)
await simpleDiscountFactory(
dbConnection,
buildDiscountData("code-2", discountConditionId2, [customerGroup2.id])
Expand Down
27 changes: 27 additions & 0 deletions packages/medusa/src/utils/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { flatten, groupBy, map, merge } from "lodash"
import { Repository, SelectQueryBuilder } from "typeorm"
import { FindWithoutRelationsOptions } from "../repositories/customer-group"

/**
* Custom query entity, it is part of the creation of a custom findWithRelationsAndCount needs.
* Allow to query the relations for the specified entity ids
* @param repository
* @param entityIds
* @param groupedRelations
* @param withDeleted
* @param select
*/
export async function queryEntityWithIds<T>(
repository: Repository<T>,
entityIds: string[],
Expand Down Expand Up @@ -55,6 +64,15 @@ export async function queryEntityWithIds<T>(
).then(flatten)
}

/**
* Custom query entity without relations, it is part of the creation of a custom findWithRelationsAndCount needs.
* Allow to query the entities without taking into account the relations. The relations will be queried separately
* using the queryEntityWithIds util
* @param repository
* @param optionsWithoutRelations
* @param shouldCount
* @param customJoinBuilders
*/
export async function queryEntityWithoutRelations<T>(
repository: Repository<T>,
optionsWithoutRelations: FindWithoutRelationsOptions,
Expand Down Expand Up @@ -112,6 +130,10 @@ export async function queryEntityWithoutRelations<T>(
return [entities, count]
}

/**
* Grouped the relation to the top level entity
* @param relations
*/
export function getGroupedRelations(relations: string[]): {
[toplevel: string]: string[]
} {
Expand All @@ -128,6 +150,11 @@ export function getGroupedRelations(relations: string[]): {
return groupedRelations
}

/**
* Merged the entities and relations that composed by the result of queryEntityWithIds and queryEntityWithoutRelations
* call
* @param entitiesAndRelations
*/
export function mergeEntitiesWithRelations<T>(
entitiesAndRelations: Array<Partial<T>>
): T[] {
Expand Down

0 comments on commit b5c4d83

Please sign in to comment.