From 0b3ed0ba963767dab8a99c8ce3e653a4ad21995b Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 25 Jun 2019 22:33:34 -0700 Subject: [PATCH 1/2] add resolver to get displayStatus from database Signed-off-by: Erik Kieckhafer --- .../graphql/queries/orderByReferenceId.js | 1 + .../fulfillmentGroupDisplayStatus.js | 30 +++++++++++++++++++ .../resolvers/OrderFulfillmentGroup/index.js | 2 ++ 3 files changed, 33 insertions(+) create mode 100644 imports/plugins/core/orders/server/no-meteor/resolvers/OrderFulfillmentGroup/fulfillmentGroupDisplayStatus.js diff --git a/imports/plugins/core/orders/client/graphql/queries/orderByReferenceId.js b/imports/plugins/core/orders/client/graphql/queries/orderByReferenceId.js index 385b008f8c7..8d6cc446f12 100644 --- a/imports/plugins/core/orders/client/graphql/queries/orderByReferenceId.js +++ b/imports/plugins/core/orders/client/graphql/queries/orderByReferenceId.js @@ -31,6 +31,7 @@ export default gql` } } } + displayStatus(language: $language) items { nodes { _id diff --git a/imports/plugins/core/orders/server/no-meteor/resolvers/OrderFulfillmentGroup/fulfillmentGroupDisplayStatus.js b/imports/plugins/core/orders/server/no-meteor/resolvers/OrderFulfillmentGroup/fulfillmentGroupDisplayStatus.js new file mode 100644 index 00000000000..5c6affc80fa --- /dev/null +++ b/imports/plugins/core/orders/server/no-meteor/resolvers/OrderFulfillmentGroup/fulfillmentGroupDisplayStatus.js @@ -0,0 +1,30 @@ +/** + * @name OrderFulfillmentGroup/fulfillmentGroupDisplayStatus + * @method + * @memberof Order/GraphQL + * @summary Displays a human readable status of order fulfillment group state + * @param {Object} context An object with request-specific state + * @param {Object} fulfillmentGroup - Result of the parent resolver, which is a Fulfillment Group object in GraphQL schema format + * @param {String} language Language to filter item content by + * @return {String} A string of the order status + */ +export default async function fulfillmentGroupDisplayStatus(context, fulfillmentGroup, language) { + const { Shops } = context.collections; + const shop = await Shops.findOne({ _id: fulfillmentGroup.shopId }); + const orderStatusLabels = shop && shop.orderStatusLabels; + const { workflow: { status } } = fulfillmentGroup; + + // If translations are available in the `Shops` collection, + // and are available for this specific order status, get translations + if (orderStatusLabels && orderStatusLabels[status]) { + const orderStatusLabel = orderStatusLabels[status]; + const translatedLabel = orderStatusLabel.find((label) => label.language === language); + + // If translations are available in desired language, return them. + // Otherwise, return raw status + return (translatedLabel && translatedLabel.label) || status; + } + + // If no translations are available in the `Shops` collection, use raw status data + return status; +} diff --git a/imports/plugins/core/orders/server/no-meteor/resolvers/OrderFulfillmentGroup/index.js b/imports/plugins/core/orders/server/no-meteor/resolvers/OrderFulfillmentGroup/index.js index 2dcbd50eea1..120cd4cca7c 100644 --- a/imports/plugins/core/orders/server/no-meteor/resolvers/OrderFulfillmentGroup/index.js +++ b/imports/plugins/core/orders/server/no-meteor/resolvers/OrderFulfillmentGroup/index.js @@ -3,6 +3,7 @@ import { xformOrderFulfillmentGroupSelectedOption } from "@reactioncommerce/reaction-graphql-xforms/order"; import { resolveShopFromShopId } from "@reactioncommerce/reaction-graphql-utils"; +import fulfillmentGroupDisplayStatus from "./fulfillmentGroupDisplayStatus"; import items from "./items"; import summary from "./summary"; @@ -14,6 +15,7 @@ export default { } return null; }, + displayStatus: (node, { language }, context) => fulfillmentGroupDisplayStatus(context, node, language), items, selectedFulfillmentOption: (node) => xformOrderFulfillmentGroupSelectedOption(node.shipmentMethod, node), shop: resolveShopFromShopId, From 4f8e4a4c5e93993af89ce0900dbfc51c6cb718cc Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Wed, 26 Jun 2019 09:50:17 -0700 Subject: [PATCH 2/2] add displayStatus to schema Signed-off-by: Erik Kieckhafer --- .../core/orders/server/no-meteor/schemas/schema.graphql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/imports/plugins/core/orders/server/no-meteor/schemas/schema.graphql b/imports/plugins/core/orders/server/no-meteor/schemas/schema.graphql index c7cd25175d4..5cb5b3f810a 100644 --- a/imports/plugins/core/orders/server/no-meteor/schemas/schema.graphql +++ b/imports/plugins/core/orders/server/no-meteor/schemas/schema.graphql @@ -287,6 +287,9 @@ type OrderFulfillmentGroup implements Node { "Information needed by the selected fulfillment method to properly fulfill the order" data: OrderFulfillmentGroupData + "The order status for display in UI" + displayStatus(language: String!): String! + "The items that are part of this fulfillment group" items(after: ConnectionCursor, before: ConnectionCursor, first: ConnectionLimitInt, last: ConnectionLimitInt, sortOrder: SortOrder = desc, sortBy: OrderFulfillmentGroupItemsSortByField = addedAt): OrderItemConnection