Skip to content

Update Content “complete-mutation” #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/content/complete-mutation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Next lets go into our makeABooking mutation and add the following:
```
import { v1 as uuidv1 } from "uuid";
import stripePackage from "stripe";
import * as dynamoDBLib from "../../libs/dynamodb-lib";
import dynamodb from "../../libs/dynamodb-lib";

export const makeABooking = async (args, context) => {
//Get the listing that the user selected
Expand All @@ -35,7 +35,7 @@ export const makeABooking = async (args, context) => {
},
};
try {
const listings = await dynamoDBLib.call("query", params);
const listings = await dynamodb.query(params);
return listings;
} catch (e) {
return e;
Expand All @@ -54,21 +54,21 @@ Next up let's calculate the price of the booking:
```javascript
//set the listing to a variables so we can resuse it
const listingObject = await getPrices();

//caLCULATE THE amount to be charged to the
//customers card

const bookingCharge = parseInt(listingObject.Items[0].price) * args.size;

const bookingCharge =
parseInt(listingObject.Items[0].price) * args.customers.length;
//get the name of the listing

const listingName = listingObject.listingName;
//create an instance of the stripe lib

console.log(process.env.stripeSecretKey);

const stripe = stripePackage(process.env.stripeSecretKey);

//charge the users card

const stripeResult = await stripe.charges.create({
source: "tok_visa",
amount: bookingCharge,
Expand All @@ -95,7 +95,7 @@ Next up we can create the params to send to DynamoDB:
bookingId: uuidv1(),
listingId: args.listingId,
bookingDate: args.bookingDate,
size: args.size,
size: args.customers.length > 0 ? args.customers.length : 0,
bookingTotal: bookingCharge,
customerEmail: args.customerEmail,
customers: args.customers,
Expand All @@ -113,9 +113,8 @@ Next let's send the params to Dynamo:
```javascript
try {
//insert the booking into the table
await dynamoDBLib.call("put", params);
await dynamodb.put(params);


return {
bookingId: params.Item.bookingId,
listingId: params.Item.listingId,
Expand All @@ -125,7 +124,7 @@ Next let's send the params to Dynamo:
customerEmail: params.Item.customerEmail,
customers: params.Item.customers.map((c) => ({
name: c.name,
Surname: c.Surname,
surname: c.surname,
country: c.country,
passportNumber: c.passportNumber,
physioScore: c.physioScore,
Expand Down