From 223a5f2a7a4c9b9f20de0a2921928c617d36a834 Mon Sep 17 00:00:00 2001 From: DorianMazur Date: Thu, 25 Aug 2022 18:10:08 +0200 Subject: [PATCH] Remove Query Builder Service (cherry picked from commit c9a38519882033edac58c57b1d6dd1ac87879e11) --- .../services/classes/QueryBuilderService.md | 79 ------------------- docs/content/references/services/index.md | 1 - .../src/services/__mocks__/query-builder.js | 11 --- packages/medusa/src/services/index.ts | 1 - packages/medusa/src/services/query-builder.js | 52 ------------ 5 files changed, 144 deletions(-) delete mode 100644 docs/content/references/services/classes/QueryBuilderService.md delete mode 100644 packages/medusa/src/services/__mocks__/query-builder.js delete mode 100644 packages/medusa/src/services/query-builder.js diff --git a/docs/content/references/services/classes/QueryBuilderService.md b/docs/content/references/services/classes/QueryBuilderService.md deleted file mode 100644 index 53b6625823a99..0000000000000 --- a/docs/content/references/services/classes/QueryBuilderService.md +++ /dev/null @@ -1,79 +0,0 @@ -# Class: QueryBuilderService - -## Hierarchy - -- `"medusa-interfaces"` - - ↳ **`QueryBuilderService`** - -## Constructors - -### constructor - -• **new QueryBuilderService**() - -#### Inherited from - -BaseService.constructor - -## Methods - -### buildFilterQuery - -▸ **buildFilterQuery**(`filters`): `undefined` \| {} - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `filters` | `any` | - -#### Returns - -`undefined` \| {} - -#### Defined in - -[packages/medusa/src/services/query-builder.js:25](https://github.com/medusajs/medusa/blob/f406c8d4/packages/medusa/src/services/query-builder.js#L25) - -___ - -### buildQuery - -▸ **buildQuery**(`params`, `properties`): `Object` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `params` | `any` | -| `properties` | `any` | - -#### Returns - -`Object` - -#### Defined in - -[packages/medusa/src/services/query-builder.js:5](https://github.com/medusajs/medusa/blob/f406c8d4/packages/medusa/src/services/query-builder.js#L5) - -___ - -### buildTextSearchQuery - -▸ **buildTextSearchQuery**(`search`, `searchProperties`): `undefined` \| { `$or`: `any` = searchQuery } - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `search` | `any` | -| `searchProperties` | `any` | - -#### Returns - -`undefined` \| { `$or`: `any` = searchQuery } - -#### Defined in - -[packages/medusa/src/services/query-builder.js:39](https://github.com/medusajs/medusa/blob/f406c8d4/packages/medusa/src/services/query-builder.js#L39) diff --git a/docs/content/references/services/index.md b/docs/content/references/services/index.md index 942d17e03783a..51188aa3250b5 100644 --- a/docs/content/references/services/index.md +++ b/docs/content/references/services/index.md @@ -30,7 +30,6 @@ - [ProductService](classes/ProductService.md) - [ProductTypeService](classes/ProductTypeService.md) - [ProductVariantService](classes/ProductVariantService.md) -- [QueryBuilderService](classes/QueryBuilderService.md) - [RegionService](classes/RegionService.md) - [ReturnReasonService](classes/ReturnReasonService.md) - [ReturnService](classes/ReturnService.md) diff --git a/packages/medusa/src/services/__mocks__/query-builder.js b/packages/medusa/src/services/__mocks__/query-builder.js deleted file mode 100644 index 8f3d68bc3e338..0000000000000 --- a/packages/medusa/src/services/__mocks__/query-builder.js +++ /dev/null @@ -1,11 +0,0 @@ -export const QueryBuilderServiceMock = { - buildQuery: jest.fn().mockImplementation(data => { - return Promise.resolve() - }), -} - -const mock = jest.fn().mockImplementation(() => { - return QueryBuilderServiceMock -}) - -export default mock diff --git a/packages/medusa/src/services/index.ts b/packages/medusa/src/services/index.ts index c6feace3ecf2d..f32404fbc357b 100644 --- a/packages/medusa/src/services/index.ts +++ b/packages/medusa/src/services/index.ts @@ -26,7 +26,6 @@ export { default as ProductCollectionService } from "./product-collection" export { default as ProductService } from "./product" export { default as ProductTypeService } from "./product-type" export { default as ProductVariantService } from "./product-variant" -export { default as QueryBuilderService } from "./query-builder" export { default as RegionService } from "./region" export { default as ReturnReasonService } from "./return-reason" export { default as ReturnService } from "./return" diff --git a/packages/medusa/src/services/query-builder.js b/packages/medusa/src/services/query-builder.js deleted file mode 100644 index a2ba84ac40767..0000000000000 --- a/packages/medusa/src/services/query-builder.js +++ /dev/null @@ -1,52 +0,0 @@ -import { BaseService } from "medusa-interfaces" -import _ from "lodash" - -class QueryBuilderService extends BaseService { - buildQuery(params, properties) { - const textSearch = _.pick(params, ["q"]) - const filters = _.pick(params, properties) - - const textQuery = this.buildTextSearchQuery(textSearch, properties) - const filterQuery = this.buildFilterQuery(filters) - - if (textQuery && filterQuery) { - return { - $and: [textQuery, filterQuery], - } - } else if (!textQuery && filterQuery) { - return filterQuery - } else if (textQuery && !filterQuery) { - return textQuery - } else { - return {} - } - } - - buildFilterQuery(filters) { - if (_.isEmpty(filters)) { - return - } - - const filterQuery = {} - - Object.keys(filters).map((filter) => { - filterQuery[filter] = filters[filter] - }) - - return filterQuery - } - - buildTextSearchQuery(search, searchProperties) { - if (_.isEmpty(search)) { - return - } - - const searchQuery = searchProperties.map((s) => ({ - [s]: new RegExp(search.q, "i"), - })) - - return { $or: searchQuery } - } -} - -export default QueryBuilderService