From 628662b1a38e9ec89485b8b158593380b240cc0c Mon Sep 17 00:00:00 2001 From: Michelle Mabuyo Date: Wed, 5 Jun 2024 17:36:20 -0400 Subject: [PATCH] lesson 10c - resolvers for monolith --- monolith/resolvers.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/monolith/resolvers.js b/monolith/resolvers.js index 3ccee4e..dc15976 100644 --- a/monolith/resolvers.js +++ b/monolith/resolvers.js @@ -381,8 +381,8 @@ const resolvers = { }, }, Listing: { - host: ({ hostId }, _, { dataSources }) => { - return dataSources.accountsAPI.getUser(hostId); + host: ({ hostId }) => { + return { id: hostId }; }, overallRating: ({ id }, _, { dataSources }) => { return dataSources.reviewsDb.getOverallRatingForListing(id); @@ -425,8 +425,8 @@ const resolvers = { checkOutDate: ({ checkOutDate }, _, { dataSources }) => { return dataSources.bookingsDb.getHumanReadableDate(checkOutDate); }, - guest: ({ guestId }, _, { dataSources }) => { - return dataSources.accountsAPI.getUser(guestId); + guest: ({ guestId }) => { + return { id: guestId }; }, totalPrice: async ( { listingId, checkInDate, checkOutDate }, @@ -451,8 +451,14 @@ const resolvers = { }, }, Review: { - author: ({ authorId }, _, { dataSources }) => { - return dataSources.accountsAPI.getUser(authorId); + author: (review) => { + let role = ""; + if (review.targetType === "LISTING" || review.targetType === "HOST") { + role = "Guest"; + } else { + role = "Host"; + } + return { __typename: role, id: review.authorId, role }; }, }, AmenityCategory: {