Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from reactioncommerce/willopez-update-translations
Browse files Browse the repository at this point in the history
refactor: update translations
  • Loading branch information
mikemurray authored Apr 16, 2020
2 parents 969504e + 66c2d29 commit 7de6d44
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 50 deletions.
114 changes: 69 additions & 45 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,71 @@
[{
"language": "English",
"i18n": "en",
"ns": "discount-codes",
"translation": {
"discount-codes": {
"checkoutPayment": {
"applyDiscount": "Apply",
"discountError": "Sorry, there was an error applying discount."
},
"discounts": {
"enterItHere": "Have a code? Enter it here.",
"discountLabel": "Discount Code",
"submitted": "Discount saved and applied",
"applied": "applied",
"code": "code",
"codeIsExpired": "Code is expired",
"codeIsInvalid": "Code is invalid",
"multiShopError": "Discounts cannot be applied to a multi-shop cart or order"
},
"admin": {
"paymentSettings": {
"codesLabel": "Codes"
},
"settings": {
"codesLabel": "Codes",
"noCustomDiscountCodesFound": "No discount codes found.",
"settingsSaveSuccess": "Settings saved successfully.",
"settingsSaveFailure": "Failed to save settings.",
"confirmRateDelete": "Confirm discount rate deletion."
},
"discountGrid": {
"code": "Code",
"label": "Label",
"discountMethod": "Method",
"discount": "Discount",
"calculation": {
"method": "Calculation"
},
"conditions": {
"redemptionLimit": "Limit"
}
[
{
"language": "English",
"i18n": "en",
"ns": "discount-codes",
"translation": {
"discount-codes": {
"checkoutPayment": {
"applyDiscount": "Apply",
"discountError": "Sorry, there was an error applying discount."
},
"discounts": {
"title": "Discount Codes",
"enterItHere": "Have a code? Enter it here.",
"discountLabel": "Discount Code",
"submitted": "Discount saved and applied",
"applied": "applied",
"code": "code",
"codeIsExpired": "Code is expired",
"codeIsInvalid": "Code is invalid",
"multiShopError": "Discounts cannot be applied to a multi-shop cart or order"
},
"admin": {
"paymentSettings": {
"codesLabel": "Codes"
},
"discountCode": {
"addDiscount": "Add Discount",
"addDiscountModalTitle": "Add a New Discount Code",
"confirmRateDelete": "Confirm discount rate deletion.",
"title": "Discount Codes",
"noCustomDiscountCodesFound": "No discount codes found",
"failure": "The operation failed",
"createSuccess": "A new discount code has been successfully created",
"deleteSuccess": "Discount code successfully deleted",
"updateSuccess": "Discount code successfully updated",
"settingsSaveSuccess": "Settings saved successfully.",
"form": {
"calculationMethod": "Calculation Method",
"code": "Discount Code",
"codePlaceholder": "Discount code",
"deleteDialogTitle": "Delete Discount Code",
"deleteMessage": "Are you sure you want to delete this discount code?",
"discount": "Discount",
"discountPlaceholder": "Discount value, i.e. a value 10 will translate to 10% off",
"accountLimit": "Account Limit",
"accountLimitPlaceholder": "How many times a user can redeem this discount",
"redemptionLimit": "Total Limit",
"redemptionLimitPlaceholder": "The total number of times this discount can be redeemed"
}
},
"discountsTable": {
"headers": {
"code": "Code",
"discountMethod": "Method",
"discount": "Discount",
"calculation": {
"method": "Calculation"
},
"conditions": {
"accountLimit": "Account Limit",
"redemptionLimit": "Total Limit"
}
},
"filterPlaceholder": "Filter discount codes"
}
}
}
}
}
}
}
}]
]
28 changes: 25 additions & 3 deletions src/queries/discountCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,37 @@
* @summary Query the Discounts collection
* @param {Object} context - an object containing the per-request state
* @param {String} shopId - ID of Shop to query against
* @param {Object} filters - filters to be applied
* @returns {Promise<Object>} DiscountCodes object Promise
*/
export default async function discountCodes(context, shopId) {
export default async function discountCodes(context, shopId, filters) {
const { collections } = context;
const { Discounts } = collections;

await context.validatePermissions("reaction:legacy:discounts", "read", { shopId });

return Discounts.find({
// Create the mongo selector from the provided filters
let selector = {
shopId
});
};

// filter by searchField
if (filters && filters.searchField) {
const cond = {
$regex: filters.searchField,
$options: "i"
};
selector = {
...selector,
$or: [{
code: cond
}, {
label: cond
}, {
description: cond
}]
};
}

return Discounts.find(selector);
}
5 changes: 3 additions & 2 deletions src/resolvers/Query/discountCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import { decodeShopOpaqueId } from "../../xforms/id.js";
* @param {Object} _ - unused
* @param {Object} args - an object of all arguments that were sent by the client
* @param {String} args.shopId - id of the shop
* @param {Object} args.filters - query filters
* @param {Object} context - an object containing the per-request state
* @param {Object} info Info about the GraphQL request
* @returns {Promise<Object>} An array of discount codes
*/
export default async function discountCodes(_, args, context, info) {
const { shopId: opaqueShopId, ...connectionArgs } = args;
const { shopId: opaqueShopId, filters, ...connectionArgs } = args;

const shopId = decodeShopOpaqueId(opaqueShopId);

const query = await context.queries.discountCodes(context, shopId);
const query = await context.queries.discountCodes(context, shopId, filters);

return getPaginatedResponse(query, connectionArgs, {
includeHasNextPage: wasFieldRequested("pageInfo.hasNextPage", info),
Expand Down
9 changes: 9 additions & 0 deletions src/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ input RemoveDiscountCodeFromCartInput {
token: String
}

"Input type for filters to be applied to an discount codes list"
input DiscountCodeFilterInput {
"Keywords typed by the user in the search input field"
searchField: String
}

"Response from the `applyDiscountCodeToCart` mutation"
type ApplyDiscountCodeToCartPayload {
"The updated cart with discount code applied"
Expand Down Expand Up @@ -370,6 +376,9 @@ extend type Query {
"Provide a shop ID from which you want to get discount codes"
shopId: ID!

"Filters to apply to a discount codes query"
filters: DiscountCodeFilterInput

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

Expand Down

0 comments on commit 7de6d44

Please sign in to comment.