Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/promotions: API Changes #6646

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions packages/api-plugin-promotions/src/queries/promotions.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
/**
* @summary return a possibly filtered list of promotions
* @param {Object} context - The application context
* @param {Object} input - The filters
* @param {String} shopId - The shopId to query for
* @param {Object} filter - optional filter parameters
* @return {Promise<Promotions>} - A list of promotions
*/
export default async function promotions(context, input) {
const { shopId, enabled, startDate, endDate } = input;
export default async function promotions(context, shopId, filter) {
const { enabled } = filter;
const { collections: { Promotions } } = context;
const filter = {
shopId
};


// because enabled could be false we need to check for undefined
if (typeof enabled !== "undefined") {
filter.enabled = enabled;
}

if (startDate) filter.startDate = startDate;
if (endDate) filter.endDate = endDate;
filter.shopId = shopId;
return Promotions.find(filter);
}
12 changes: 3 additions & 9 deletions packages/api-plugin-promotions/src/resolvers/Query/promotions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginat
import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js";

/**
* @summary Query for a list of products
* @summary Query for a list of promotions
* @param {Object} _ - unused
* @param {Object} args - an object of all arguments that were sent by the client
* @param {String} args.shopId - id of user to query
Expand All @@ -11,15 +11,9 @@ import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldReque
* @returns {Promise<Object>} Products
*/
export default async function promotions(_, args, context, info) {
const { input } = args;
const { shopId, enabled, startDate, endDate, ...connectionArgs } = input;
const { shopId, filter, ...connectionArgs } = args;
await context.validatePermissions("reaction:legacy:promotions", "read", { shopId });
const query = await context.queries.promotions(context, {
shopId,
enabled,
startDate,
endDate
});
const query = await context.queries.promotions(context, shopId, filter);

return getPaginatedResponse(query, connectionArgs, {
includeHasNextPage: wasFieldRequested("pageInfo.hasNextPage", info),
Expand Down
29 changes: 27 additions & 2 deletions packages/api-plugin-promotions/src/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,33 @@ extend type Query {
): Promotion
}



extend type Query {
promotions(
input: PromotionFilter
): PromotionConnection
"Shop ID"
shopId: ID!

"Return only results that come after this cursor. Use this with `first` to specify the number of results to return."
after: ConnectionCursor,

"Return only results that come before this cursor. Use this with `last` to specify the number of results to return."
before: ConnectionCursor,

"Return at most this many results. This parameter may be used with either `after` or `offset` parameters."
first: ConnectionLimitInt,

"Return at most this many results. This parameter may be used with the `before` parameter."
last: ConnectionLimitInt,

"Return only results that come after the Nth result. This parameter may be used with the `first` parameter."
offset: Int,

filter: PromotionFilter

sortBy: String

sortOrder: String

): PromotionConnection!
}