Skip to content

Commit

Permalink
feat: add non bnmo purchases to collectorResume counts
Browse files Browse the repository at this point in the history
  • Loading branch information
egdbear committed Mar 13, 2024
1 parent d483e3a commit 8893eff
Show file tree
Hide file tree
Showing 5 changed files with 21,466 additions and 11 deletions.
11 changes: 11 additions & 0 deletions _schemaV2.graphql
Expand Up @@ -4246,6 +4246,9 @@ type CollectorResume {
# The Collector follows the Gallery profile
isCollectorFollowingPartner: Boolean!

# Collector's purchase history
purchases: purchases

# Collector's ID used to stitch buyerActivity with the Exchange schema
userId: String!
}
Expand Down Expand Up @@ -15262,6 +15265,14 @@ type PublishViewingRoomPayload {
viewingRoom: ViewingRoom!
}

type purchases {
# Total number of purchases
totalAuctionCount: Int

# Total number of private sales
totalPrivateSaleCount: Int
}

type Query {
# Do not use (only used internally for stitching)
_do_not_use_conversation(
Expand Down
45 changes: 34 additions & 11 deletions src/lib/stitching/exchange/v2/stitching.ts
Expand Up @@ -357,21 +357,44 @@ export const exchangeStitchingEnvironment = ({
fragment: gql`
... on CollectorResume {
userId
purchases {
totalAuctionCount
totalPrivateSaleCount
}
}
`,
resolve: async (parent, _args, context, info) => {
const exchangeArgs = {
buyerId: parent.userId,
}
const nonBnmoPurchases =
(parent?.purchases?.totalAuctionCount ?? 0) +
(parent?.purchases?.totalPrivateSaleCount ?? 0)

return await info.mergeInfo.delegateToSchema({
schema: exchangeSchema,
operation: "query",
fieldName: "commerceBuyerActivity",
args: exchangeArgs,
context,
info,
})
try {
const exchangeArgs = {
buyerId: parent.userId,
}

const bnmoPurchases = await info.mergeInfo.delegateToSchema({
schema: exchangeSchema,
operation: "query",
fieldName: "commerceBuyerActivity",
args: exchangeArgs,
context,
info,
})

return {
totalPurchases: bnmoPurchases.totalPurchases + nonBnmoPurchases,
}
} catch (error) {
console.error(
"[schema/v2/conversation/collectorResume/totalPurchases] Error:",
error
)

return {
totalPurchases: nonBnmoPurchases,
}
}
},
},
},
Expand Down
22 changes: 22 additions & 0 deletions src/schema/v2/conversation/collectorResume.ts
Expand Up @@ -3,6 +3,7 @@ import {
GraphQLString,
GraphQLNonNull,
GraphQLBoolean,
GraphQLInt,
} from "graphql"
import { CollectorProfileType } from "schema/v2/CollectorProfile/collectorProfile"
import { ResolverContext } from "types/graphql"
Expand All @@ -25,5 +26,26 @@ export const CollectorResume = new GraphQLObjectType<any, ResolverContext>({
"Collector's ID used to stitch buyerActivity with the Exchange schema",
resolve: ({ userId }) => userId,
},
purchases: {
type: CollectorPurchasesType,
description: "Collector's purchase history",
resolve: ({ purchases }) => purchases,
},
}),
})

const CollectorPurchasesType = new GraphQLObjectType<any, ResolverContext>({
name: "purchases",
fields: {
totalAuctionCount: {
type: GraphQLInt,
description: "Total number of purchases",
resolve: ({ auction }) => auction,
},
totalPrivateSaleCount: {
type: GraphQLInt,
description: "Total number of private sales",
resolve: (data) => data["private sale"],
},
},
})
1 change: 1 addition & 0 deletions src/schema/v2/conversation/index.ts
Expand Up @@ -331,6 +331,7 @@ export const ConversationType = new GraphQLObjectType<any, ResolverContext>({
},
isCollectorFollowingPartner: data.follows_profile,
userId: from_id,
purchases: data.purchases,
}
} catch (error) {
console.error(
Expand Down

0 comments on commit 8893eff

Please sign in to comment.