Skip to content

Commit d5eaf9c

Browse files
committed
nerly done with the mutation
1 parent f38535a commit d5eaf9c

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/content/complete-mutation.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ postnumber: 17
1010

1111
Now we are going to complete the mutation. First off let's install some packages:
1212

13-
```
13+
```javascript
1414
$ yarn add uuid stripe
1515
```
1616

17-
⌛ uuid is used to generate random UUID's for the bookingId. Since Dynamo is a NoSQL datastore it does not auto-generate IDs like a SQL datastore.
17+
`uuid` is used to generate random UUID's for the `bookingId`. Since DynamoDB is a NoSQL datastore it does not auto-generate IDs like a SQL datastore.
1818

19-
⌛ stripe will allow us to interact with the stripe API.
19+
`stripe` will allow us to interact with the stripe API.
2020

21-
Next lets go into our makeABooking mutation and add the following:
21+
Next lets go into our `makeABooking` mutation and add the following:
2222

23-
```
24-
import { v1 as uuidv1 } from "uuid";
25-
import stripePackage from "stripe";
26-
import * as dynamoDBLib from "../../libs/dynamodb-lib";
23+
```javascript
24+
import { v1 as uuidv1 } from "uuid"
25+
import stripePackage from "stripe"
26+
import * as dynamoDBLib from "../../libs/dynamodb-lib"
2727

2828
export const makeABooking = async (args, context) => {
2929
//Get the listing that the user selected
@@ -35,21 +35,20 @@ export const makeABooking = async (args, context) => {
3535
ExpressionAttributeValues: {
3636
":listingId": args.listingId,
3737
},
38-
};
38+
}
3939
try {
40-
const listings = await dynamoDBLib.call("query", params);
41-
return listings;
40+
const listings = await dynamoDBLib.call("query", params)
41+
return listings
4242
} catch (e) {
43-
return e;
43+
return e
4444
}
45-
};
46-
4745
}
46+
}
4847
```
4948

5049
⌛ First off we are adding our necessary libs to the file
5150

52-
then we are creating a function called getPrices that will go into the listings table and get the listing that matches thee listingId for the listing the customer wants to make a booking for.
51+
Then we are creating a function called `getPrices` that will go into the `listings` table and get the listing that matches the `listingId` for the listing the customer wants to make a booking for.
5352

5453
Next up let's calculate the price of the booking:
5554

@@ -66,7 +65,6 @@ const bookingCharge = parseInt(listingObject.Items[0].price) * args.size
6665
const listingName = listingObject.listingName
6766
//create an instance of the stripe lib
6867

69-
console.log(process.env.stripeSecretKey)
7068
const stripe = stripePackage(process.env.stripeSecretKey)
7169

7270
//charge the users card
@@ -108,9 +106,9 @@ const params = {
108106
}
109107
```
110108

111-
⌛ As before we are simply creating a params object that has the necessary TableName, and the fields that match the Booking Type in the schema. We have added a createdTimestamp and paymentDetails fields for internal use that will not be exposed to the API.
109+
⌛ As before we are simply creating a `params` object that has the necessary `TableName`, and the fields that match the Booking Type in the schema. We have added a `createdTimestamp` and `paymentDetails` fields for internal use that will not be exposed to the API.
112110

113-
Next let's send the params to Dynamo:
111+
Next let's send the params to DynamoDB:
114112

115113
```javascript
116114
try {
@@ -138,7 +136,7 @@ try {
138136
}
139137
```
140138

141-
⌛ We are simply doing a put action to Dynamo to insert the mutation into the table.
139+
⌛ We are simply doing a put action to DynamoDB to insert the mutation into the table.
142140

143141
⌛ Then we are returning the Booking object back to the API.
144142

0 commit comments

Comments
 (0)