generated from reactioncommerce/api-plugin-example
-
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.
- Loading branch information
Showing
4 changed files
with
105 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
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 |
---|---|---|
@@ -1,9 +1,33 @@ | ||
/** | ||
* Fetch all econt offices | ||
* @param {Object} context - graphql context | ||
* @param {Object} input - Request input | ||
* @param {String} [query] - Regex match query string | ||
* @returns {Promise<*>} - econt offices | ||
*/ | ||
export default async function econtOffices(context) { | ||
export default async function econtOffices(context, input) { | ||
const { searchQuery } = input; | ||
|
||
const { collections: { EcontOffices } } = context; | ||
return EcontOffices.find({}).toArray(); | ||
|
||
const query = {}; | ||
|
||
if (searchQuery) { | ||
query.$or = [ | ||
{ | ||
code: { $regex: searchQuery, $options: "i" } | ||
}, | ||
{ | ||
name: { $regex: searchQuery, $options: "i" } | ||
}, | ||
{ | ||
nameEn: { $regex: searchQuery, $options: "i" } | ||
}, | ||
{ | ||
"address.address1": { $regex: searchQuery, $options: "i" } | ||
} | ||
]; | ||
} | ||
|
||
return EcontOffices.find(query); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,25 @@ | ||
import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; | ||
import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; | ||
|
||
/** | ||
* Fetch all econt offices | ||
* @param {Object} parentResult - unused | ||
* @param {ConnectionArgs} args - unused | ||
* @param {Object} context - graphql execution context | ||
* @param {Object} info Info about the GraphQL request | ||
* @returns {Promise<Object>} - econt offices | ||
*/ | ||
export default async function econtOffices(parentResult, args, context) { | ||
return context.queries.econtOffices(context); | ||
export default async function econtOffices(parentResult, args, context, info) { | ||
const { | ||
searchQuery, | ||
...connectionArgs | ||
} = args; | ||
|
||
const query = await context.queries.econtOffices(context, { searchQuery }); | ||
|
||
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