Skip to content

Commit

Permalink
chore: address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan committed Apr 6, 2023
1 parent 68ec1ff commit d86d60f
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .changeset/healthy-garlics-retire.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
"@medusajs/medusa": patch
"@medusajs/utils": patch
---

chore(medusa): rename buildLegacyFieldsListFrom to objectToStringPath
chore(medusa, utils): rename buildLegacyFieldsListFrom to objectToStringPath
2 changes: 1 addition & 1 deletion packages/medusa/src/repositories/customer-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
queryEntityWithIds,
queryEntityWithoutRelations,
} from "../utils/repository"
import { objectToStringPath } from "../utils"
import { objectToStringPath } from "@medusajs/utils"
import { dataSource } from "../loaders/database"

export type DefaultWithoutRelations = Omit<
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/repositories/order.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { flatten, groupBy, map, merge } from "lodash"
import { FindManyOptions, FindOptionsRelations, In } from "typeorm"
import { Order } from "../models"
import { objectToStringPath } from "../utils"
import { objectToStringPath } from "@medusajs/utils"
import { dataSource } from "../loaders/database"

const ITEMS_REL_NAME = "items"
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/repositories/product-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { ProductCategory } from "../models/product-category"
import { ExtendedFindConfig, QuerySelector } from "../types/common"
import { dataSource } from "../loaders/database"
import { objectToStringPath } from "../utils"
import { objectToStringPath } from "@medusajs/utils"
import { isEmpty } from "lodash"

export const ProductCategoryRepository = dataSource
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/repositories/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { ExtendedFindConfig } from "../types/common"
import { dataSource } from "../loaders/database"
import { ProductFilterOptions } from "../types/product"
import {
objectToStringPath,
isObject,
fetchCategoryDescendantsIds,
} from "../utils"
import { objectToStringPath } from "@medusajs/utils"

export const ProductRepository = dataSource.getRepository(Product).extend({
async bulkAddToCollection(
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/repositories/tax-rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "../models"
import { TaxRateListByConfig } from "../types/tax-rate"
import { isDefined } from "medusa-core-utils"
import { objectToStringPath } from "../utils"
import { objectToStringPath } from "@medusajs/utils"
import { dataSource } from "../loaders/database"

const resolveableFields = [
Expand Down
5 changes: 3 additions & 2 deletions packages/medusa/src/utils/build-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function buildWhere<TWhereKeys extends object, TEntity>(

/**
* Revert new object structure of find options to the legacy structure of previous version
* @deprecated in favor of import { objectToStringPath } from "@medusajs/utils"
* @example
* input: {
* test: {
Expand All @@ -153,7 +154,7 @@ function buildWhere<TWhereKeys extends object, TEntity>(
* output: ['test.test1', 'test.test2', 'test.test3.test4', 'test2']
* @param input
*/
export function objectToStringPath<TEntity>(
export function buildLegacyFieldsListFrom<TEntity>(
input:
| FindOptionsWhere<TEntity>
| FindOptionsSelect<TEntity>
Expand All @@ -168,7 +169,7 @@ export function objectToStringPath<TEntity>(

for (const key of Object.keys(input)) {
if (input[key] != undefined && typeof input[key] === "object") {
const deepRes = objectToStringPath(input[key])
const deepRes = buildLegacyFieldsListFrom(input[key])

const items = deepRes.reduce((acc, val) => {
acc.push(`${key}.${val}`)
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/common/build-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ function buildWhere<TWhereKeys extends object, TEntity>(
}

/**
* Revert new object structure of find options to the legacy structure of previous version
* Converts a typeorms structure of find options to an
* array of string paths
* @example
* input: {
* test: {
Expand Down

0 comments on commit d86d60f

Please sign in to comment.