Skip to content

Commit

Permalink
Merge pull request #5236 from reactioncommerce/feat-kieckhafer-addHum…
Browse files Browse the repository at this point in the history
…anReadableStatusForFulfillment

feat: add resolver to get displayStatus from database
  • Loading branch information
willopez authored Jun 27, 2019
2 parents d26729c + bac0acc commit ad08298
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default gql`
}
}
}
displayStatus(language: $language)
items {
nodes {
_id
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ad08298

Please sign in to comment.