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

Commit

Permalink
fix: add full name from payments to order
Browse files Browse the repository at this point in the history
Signed-off-by: Mohan Narayana <mohan.narayana@mailchimp.com>
  • Loading branch information
MohanNarayana committed Jan 15, 2021
1 parent 181a3d3 commit 1cc507a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/resolvers/Order/billingName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @name Order/billingName
* @method
* @memberof Order/GraphQL
* @summary Returns a string of comma separated full names involved with payment
* @param {Object} context An object with request-specific state
* @param {Object} order - Result of the parent resolver, which is a Order object in GraphQL schema format
* @returns {String} A string of names
*/

export default async function billingName (order){
if(!Array.isArray(order.payments)) return null
let name = "";
order.payments.forEach(payment => {
name = name.concat(payment.address.fullName + ", ")
})
//remove the last comma and whitespace
return name.replace(/,\s*$/, "")
}
2 changes: 2 additions & 0 deletions src/resolvers/Order/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import orderSummary from "./orderSummary.js";
import payments from "./payments.js";
import refunds from "./refunds.js";
import totalItemQuantity from "./totalItemQuantity.js";
import billingName from "./billingName.js";

export default {
_id: (node) => encodeOrderOpaqueId(node._id),
account: resolveAccountFromAccountId,
billingName: (node) => billingName(node),
cartId: (node) => encodeCartOpaqueId(node._id),
displayStatus: (node, { language }, context) => orderDisplayStatus(context, node, language),
fulfillmentGroups: (node) => node.shipping || [],
Expand Down
3 changes: 3 additions & 0 deletions src/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ type Order implements Node {
"The account that placed the order. Some orders are created for anonymous users. Anonymous orders have a null account."
account: Account

"Full name(s) involved with payment. Payment can be made by one or more than one person"
billingName: String

"The ID of the cart that created this order. Carts are deleted after becoming orders, so this is just a reference."
cartId: ID

Expand Down

0 comments on commit 1cc507a

Please sign in to comment.