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: add resolver to get displayStatus from database #5236

Merged
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
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