forked from reactioncommerce/reaction
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request reactioncommerce#6684 from reactioncommerce/feat-f…
…ilter-search Filter Feature
- Loading branch information
Showing
30 changed files
with
1,562 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@reactioncommerce/api-core": minor | ||
"@reactioncommerce/api-plugin-accounts": minor | ||
"@reactioncommerce/api-plugin-orders": minor | ||
"@reactioncommerce/api-plugin-products": minor | ||
"@reactioncommerce/api-utils": minor | ||
--- | ||
|
||
Filter feature. This new feature provides a common function that can be used in a new query endpoint to get filtered results from any collection. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/api-plugin-accounts/src/queries/filterAccounts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import generateFilterQuery from "@reactioncommerce/api-utils/generateFilterQuery.js"; | ||
|
||
/** | ||
* @name filterAccounts | ||
* @method | ||
* @memberof GraphQL/Accounts | ||
* @summary Query the Accounts collection for a list of customers/accounts | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} conditions - object containing the filter conditions | ||
* @param {String} shopId - shopID to filter by | ||
* @returns {Promise<Object>} Accounts object Promise | ||
*/ | ||
export default async function filterAccounts(context, conditions, shopId) { | ||
const { collections: { Accounts } } = context; | ||
|
||
if (!shopId) { | ||
throw new Error("shopId is required"); | ||
} | ||
await context.validatePermissions("reaction:legacy:accounts", "read", { shopId }); | ||
|
||
const { filterQuery } = generateFilterQuery(context, "Account", conditions, shopId); | ||
|
||
return Accounts.find(filterQuery); | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/api-plugin-accounts/src/queries/filterCustomers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import generateFilterQuery from "@reactioncommerce/api-utils/generateFilterQuery.js"; | ||
|
||
/** | ||
* @name filterCustomers | ||
* @method | ||
* @memberof GraphQL/Customers | ||
* @summary Query the Accounts collection for a list of customers/accounts | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} conditions - object containing the filter conditions | ||
* @param {String} shopId - shopID to filter by | ||
* @returns {Promise<Object>} Accounts object Promise | ||
*/ | ||
export default async function filterCustomers(context, conditions, shopId) { | ||
const { collections: { Accounts } } = context; | ||
|
||
if (!shopId) { | ||
throw new Error("shopId is required"); | ||
} | ||
await context.validatePermissions("reaction:legacy:accounts", "read", { shopId }); | ||
|
||
const { filterQuery } = generateFilterQuery(context, "Account", conditions, shopId); | ||
|
||
filterQuery.groups = { $in: [null, []] }; // filter out non-customer accounts | ||
return Accounts.find(filterQuery); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/api-plugin-accounts/src/resolvers/Query/filterAccounts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; | ||
import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; | ||
|
||
/** | ||
* @name Query/accounts | ||
* @method | ||
* @memberof Accounts/Query | ||
* @summary Query for a list of accounts | ||
* @param {Object} _ - unused | ||
* @param {Object} args - an object of all arguments that were sent by the client | ||
* @param {String} args.shopId - id of shop to query | ||
* @param {Object} args.conditions - object containing the filter conditions | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} info Info about the GraphQL request | ||
* @returns {Promise<Object>} Accounts | ||
*/ | ||
export default async function filterAccounts(_, args, context, info) { | ||
const { | ||
shopId, | ||
conditions, | ||
...connectionArgs | ||
} = args; | ||
|
||
const query = await context.queries.filterAccounts(context, conditions, shopId); | ||
|
||
return getPaginatedResponse(query, connectionArgs, { | ||
includeHasNextPage: wasFieldRequested("pageInfo.hasNextPage", info), | ||
includeHasPreviousPage: wasFieldRequested("pageInfo.hasPreviousPage", info), | ||
includeTotalCount: wasFieldRequested("totalCount", info) | ||
}); | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/api-plugin-accounts/src/resolvers/Query/filterCustomers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; | ||
import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; | ||
|
||
/** | ||
* @name Query/accounts | ||
* @method | ||
* @memberof Customers/Query | ||
* @summary Query for a list of customers | ||
* @param {Object} _ - unused | ||
* @param {Object} args - an object of all arguments that were sent by the client | ||
* @param {String} args.shopId - id of shop to query | ||
* @param {Object} args.conditions - object containing the filter conditions | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} info Info about the GraphQL request | ||
* @returns {Promise<Object>} Accounts | ||
*/ | ||
export default async function filterCustomers(_, args, context, info) { | ||
const { | ||
shopId, | ||
conditions, | ||
...connectionArgs | ||
} = args; | ||
|
||
const query = await context.queries.filterCustomers(context, conditions, shopId); | ||
|
||
return getPaginatedResponse(query, connectionArgs, { | ||
includeHasNextPage: wasFieldRequested("pageInfo.hasNextPage", info), | ||
includeHasPreviousPage: wasFieldRequested("pageInfo.hasPreviousPage", info), | ||
includeTotalCount: wasFieldRequested("totalCount", info) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import generateFilterQuery from "@reactioncommerce/api-utils/generateFilterQuery.js"; | ||
|
||
/** | ||
* @name filterOrders | ||
* @method | ||
* @memberof GraphQL/Orders | ||
* @summary Query the Orders collection for a list of orders | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} conditions - object containing the filter conditions | ||
* @param {String} shopId - shopID to filter by | ||
* @returns {Promise<Object>} Orders object Promise | ||
*/ | ||
export default async function filterOrders(context, conditions, shopId) { | ||
const { collections: { Orders } } = context; | ||
|
||
if (!shopId) { | ||
throw new Error("shopId is required"); | ||
} | ||
|
||
await context.validatePermissions("reaction:legacy:orders", "read", { shopId }); | ||
|
||
const { filterQuery } = generateFilterQuery(context, "Order", conditions, shopId); | ||
|
||
return Orders.find(filterQuery); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.