You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (user) returnnewBuffer(email).toString('base64');
75
102
returnfalse;
76
103
},
77
-
}
104
+
},
78
105
```
79
106
80
107
As shown in the code above, there are three resolver functions, `bookTrip`, `cancelTrip`, and `login`.
81
108
82
-
The `bookTrip` function takes in a `launchId`, and makes a request to book a trip for that particular launch.
109
+
The `bookTrip` function takes in a `launchId`, and makes a request to book a trip for that particular launch. If a trip is booked successfully, then the function retrieves the booked launch and returns an object containing a success status and message back to the client.
110
+
111
+
The `cancelTrip` function takes in a `launchId`, and makes a request via the `cancelTrip` method of the user data source to cancel a trip. If a trip is canceled successfully, then the function retrieves the launch that has been canceled and returns an object indicating a success status back to the client.
83
112
84
-
The `cancelTrip` function takes in a `launchId`, and makes a request via the `cancelTrip` method of the user data source to cancel a trip.
113
+
For both functions, if the request fails, then an object containing a failed success status and message is returned to the client.
85
114
86
115
The `login` function takes in an email, checks the user table in the database via the `findOrCreateUser` method to verify if the user exists or not. If the user exists or a new user is created, return a `base64` encoding of the user's email.
87
116
88
117
The `base64` encoding of the user's detail is for obscuring the data. The result is a form of unique string token which we use for authentication.
89
118
90
-
Now, let's get to the `User` resolver functions.
91
-
92
-
Copy the code below and paste it just after the `Mutation` resolver functions.
119
+
Now, we need to add a resolver function to take care of the booked status on a launch. Copy the code below and paste it just after the `Mutation` resolver functions.
The `isBooked` function makes a request to the `isBookedOnLaunch` method of the `UserAPI` datasource class with the id of a launch. This request confirms whether the launch has been booked by the logged-in user.
132
+
133
+
Now, let's implement the `User` resolver functions.
134
+
135
+
Copy the code below and paste it just after the `Launch` resolver function.
0 commit comments