summaryrefslogtreecommitdiffstats
path: root/stepped-solutions
diff options
context:
space:
mode:
Diffstat (limited to 'stepped-solutions')
-rwxr-xr-xstepped-solutions/27/backend/src/index.js33
-rwxr-xr-xstepped-solutions/27/backend/src/resolvers/Query.js21
-rwxr-xr-xstepped-solutions/27/backend/src/schema.graphql15
-rwxr-xr-xstepped-solutions/27/frontend/components/Nav.js32
-rwxr-xr-xstepped-solutions/27/frontend/components/User.js27
-rwxr-xr-xstepped-solutions/28/backend/src/resolvers/Mutation.js95
-rwxr-xr-xstepped-solutions/28/backend/src/schema.graphql17
-rwxr-xr-xstepped-solutions/28/frontend/components/Nav.js36
-rwxr-xr-xstepped-solutions/28/frontend/components/Signin.js76
-rwxr-xr-xstepped-solutions/28/frontend/components/Signup.js86
-rwxr-xr-xstepped-solutions/28/frontend/components/User.js27
-rwxr-xr-xstepped-solutions/28/frontend/pages/signup.js18
-rwxr-xr-xstepped-solutions/29/backend/src/resolvers/Mutation.js99
-rwxr-xr-xstepped-solutions/29/backend/src/schema.graphql22
-rwxr-xr-xstepped-solutions/29/frontend/components/Nav.js38
-rwxr-xr-xstepped-solutions/29/frontend/components/Signout.js19
-rwxr-xr-xstepped-solutions/29/frontend/components/styles/NavStyles.js66
-rwxr-xr-xstepped-solutions/30/src/resolvers/Mutation.js156
-rwxr-xr-xstepped-solutions/30/src/schema.graphql30
-rwxr-xr-xstepped-solutions/31/frontend/components/RequestReset.js58
-rwxr-xr-xstepped-solutions/31/frontend/components/Reset.js84
-rwxr-xr-xstepped-solutions/31/frontend/pages/reset.js10
-rwxr-xr-xstepped-solutions/31/frontend/pages/signup.js20
-rwxr-xr-xstepped-solutions/32/backend/src/mail.js28
-rwxr-xr-xstepped-solutions/32/backend/src/resolvers/Mutation.js167
-rwxr-xr-xstepped-solutions/33/backend/datamodel.graphql28
-rwxr-xr-xstepped-solutions/33/backend/src/generated/prisma.graphql850
-rwxr-xr-xstepped-solutions/33/backend/src/resolvers/Mutation.js175
-rwxr-xr-xstepped-solutions/34/frontend/components/PleaseSignIn.js22
-rwxr-xr-xstepped-solutions/34/frontend/pages/sell.js12
-rwxr-xr-xstepped-solutions/35/backend/src/index.js46
-rwxr-xr-xstepped-solutions/35/backend/src/resolvers/Query.js34
-rwxr-xr-xstepped-solutions/35/backend/src/schema.graphql31
-rwxr-xr-xstepped-solutions/35/frontend/components/Permissions.js73
-rwxr-xr-xstepped-solutions/35/frontend/pages/permissions.js12
-rwxr-xr-xstepped-solutions/36/frontend/components/Permissions.js104
-rwxr-xr-xstepped-solutions/36/frontend/components/User.js27
-rwxr-xr-xstepped-solutions/37/backend/src/resolvers/Mutation.js207
-rwxr-xr-xstepped-solutions/37/backend/src/schema.graphql32
-rwxr-xr-xstepped-solutions/37/frontend/components/Permissions.js131
-rwxr-xr-xstepped-solutions/37/frontend/components/styles/Table.js35
-rwxr-xr-xstepped-solutions/38/backend/src/resolvers/Mutation.js215
-rwxr-xr-xstepped-solutions/38/frontend/components/DeleteItem.js50
-rwxr-xr-xstepped-solutions/40/frontend/components/Cart.js47
-rwxr-xr-xstepped-solutions/40/frontend/components/Header.js74
-rwxr-xr-xstepped-solutions/40/frontend/components/Nav.js45
-rwxr-xr-xstepped-solutions/40/frontend/lib/withData.js42
-rwxr-xr-xstepped-solutions/41/backend/datamodel.graphql37
-rwxr-xr-xstepped-solutions/41/backend/src/generated/prisma.graphql1141
-rwxr-xr-xstepped-solutions/41/backend/src/resolvers/Mutation.js254
-rwxr-xr-xstepped-solutions/41/backend/src/schema.graphql34
-rwxr-xr-xstepped-solutions/41/frontend/components/AddToCart.js29
-rwxr-xr-xstepped-solutions/41/frontend/components/Item.js50
-rwxr-xr-xstepped-solutions/42/frontend/components/AddToCart.js35
-rwxr-xr-xstepped-solutions/42/frontend/components/Cart.js63
-rwxr-xr-xstepped-solutions/42/frontend/components/CartItem.js41
-rwxr-xr-xstepped-solutions/42/frontend/components/User.js38
-rwxr-xr-xstepped-solutions/43/backend/src/resolvers/Mutation.js278
-rwxr-xr-xstepped-solutions/43/backend/src/schema.graphql35
-rwxr-xr-xstepped-solutions/43/frontend/components/CartItem.js43
-rwxr-xr-xstepped-solutions/43/frontend/components/RemoveFromCart.js49
-rwxr-xr-xstepped-solutions/44/frontend/components/RemoveFromCart.js72
-rwxr-xr-xstepped-solutions/45/frontend/components/CartCount.js60
-rwxr-xr-xstepped-solutions/45/frontend/components/Nav.js49
-rwxr-xr-xstepped-solutions/46/backend/datamodel.graphql37
-rwxr-xr-xstepped-solutions/46/backend/src/generated/prisma.graphql1142
-rwxr-xr-xstepped-solutions/46/frontend/components/CartItem.js53
-rwxr-xr-xstepped-solutions/47/frontend/components/Cart.js61
-rwxr-xr-xstepped-solutions/48/frontend/components/Header.js75
-rwxr-xr-xstepped-solutions/48/frontend/components/Search.js67
-rwxr-xr-xstepped-solutions/49/frontend/components/Search.js93
-rwxr-xr-xstepped-solutions/49/frontend/lib/withData.js42
-rwxr-xr-xstepped-solutions/50/frontend/components/Cart.js64
-rwxr-xr-xstepped-solutions/50/frontend/components/TakeMyMoney.js43
-rwxr-xr-xstepped-solutions/51/backend/datamodel.graphql55
-rwxr-xr-xstepped-solutions/51/backend/src/generated/prisma.graphql1805
-rwxr-xr-xstepped-solutions/51/backend/src/resolvers/Mutation.js312
-rwxr-xr-xstepped-solutions/51/backend/src/schema.graphql36
-rwxr-xr-xstepped-solutions/51/frontend/components/TakeMyMoney.js72
-rwxr-xr-xstepped-solutions/52/backend/src/resolvers/Mutation.js337
-rwxr-xr-xstepped-solutions/52/frontend/components/TakeMyMoney.js73
-rwxr-xr-xstepped-solutions/53/backend/datamodel.graphql57
-rwxr-xr-xstepped-solutions/53/backend/src/generated/prisma.graphql1855
-rwxr-xr-xstepped-solutions/53/backend/src/resolvers/Query.js55
-rwxr-xr-xstepped-solutions/53/backend/src/schema.graphql37
-rwxr-xr-xstepped-solutions/53/frontend/components/Cart.js66
-rwxr-xr-xstepped-solutions/53/frontend/components/Order.js91
-rwxr-xr-xstepped-solutions/53/frontend/components/Search.js94
-rwxr-xr-xstepped-solutions/53/frontend/components/TakeMyMoney.js77
-rwxr-xr-xstepped-solutions/53/frontend/components/styles/OrderStyles.js37
-rwxr-xr-xstepped-solutions/53/frontend/pages/order.js12
-rwxr-xr-xstepped-solutions/54/backend/src/resolvers/Query.js69
-rwxr-xr-xstepped-solutions/54/backend/src/schema.graphql38
-rwxr-xr-xstepped-solutions/54/frontend/components/OrderList.js80
-rwxr-xr-xstepped-solutions/54/frontend/pages/orders.js12
-rwxr-xr-xstepped-solutions/56/frontend/__tests__/formatMoney.test.js23
-rwxr-xr-xstepped-solutions/56/frontend/__tests__/sample.test.js19
-rwxr-xr-xstepped-solutions/57/frontend/__tests__/mocking.test.js36
-rwxr-xr-xstepped-solutions/59/frontend/__tests__/CartCount.test.js21
-rwxr-xr-xstepped-solutions/59/frontend/__tests__/Item.test.js39
-rwxr-xr-xstepped-solutions/59/frontend/__tests__/__snapshots__/CartCount.test.js.snap79
-rwxr-xr-xstepped-solutions/59/frontend/__tests__/__snapshots__/Item.test.js.snap58
-rwxr-xr-xstepped-solutions/60/frontend/__tests__/SingleItem.test.js57
-rwxr-xr-xstepped-solutions/60/frontend/__tests__/__snapshots__/SingleItem.test.js.snap32
-rwxr-xr-xstepped-solutions/60/frontend/components/SingleItem.js70
-rwxr-xr-xstepped-solutions/62/frontend/__tests__/Nav.test.js76
-rwxr-xr-xstepped-solutions/62/frontend/__tests__/Pagination.test.js89
-rwxr-xr-xstepped-solutions/62/frontend/__tests__/PleaseSignIn.test.js51
-rwxr-xr-xstepped-solutions/62/frontend/__tests__/__snapshots__/Nav.test.js.snap37
-rwxr-xr-xstepped-solutions/62/frontend/__tests__/__snapshots__/Pagination.test.js.snap67
-rwxr-xr-xstepped-solutions/62/frontend/components/Nav.js49
-rwxr-xr-xstepped-solutions/62/frontend/components/Pagination.js67
-rw-r--r--stepped-solutions/63/update.zipbin0 -> 6085 bytes
-rwxr-xr-xstepped-solutions/64/frontend/__tests__/Signup.test.js80
-rwxr-xr-xstepped-solutions/64/frontend/__tests__/__snapshots__/Signup.test.js.snap62
-rwxr-xr-xstepped-solutions/64/frontend/components/Signup.js87
-rwxr-xr-xstepped-solutions/64/frontend/components/User.js41
-rwxr-xr-xstepped-solutions/65/frontend/__tests__/AddToCart.test.js97
-rwxr-xr-xstepped-solutions/65/frontend/__tests__/Cart.test.js39
-rwxr-xr-xstepped-solutions/65/frontend/__tests__/RemoveFromCart.test.js67
-rwxr-xr-xstepped-solutions/65/frontend/components/AddToCart.js36
-rwxr-xr-xstepped-solutions/65/frontend/components/RemoveFromCart.js71
-rwxr-xr-xstepped-solutions/66/backend/prisma.yml7
-rwxr-xr-xstepped-solutions/66/backend/src/generated/prisma.graphql1862
-rwxr-xr-xstepped-solutions/66/frontend/__tests__/Order.test.js27
-rwxr-xr-xstepped-solutions/66/frontend/__tests__/TakeMyMoney.test.js98
-rwxr-xr-xstepped-solutions/66/frontend/__tests__/__snapshots__/Order.test.js.snap118
-rwxr-xr-xstepped-solutions/66/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap67
-rwxr-xr-xstepped-solutions/66/frontend/components/Order.js92
-rwxr-xr-xstepped-solutions/66/frontend/components/TakeMyMoney.js79
130 files changed, 16627 insertions, 0 deletions
diff --git a/stepped-solutions/27/backend/src/index.js b/stepped-solutions/27/backend/src/index.js
new file mode 100755
index 0000000..d95ec58
--- /dev/null
+++ b/stepped-solutions/27/backend/src/index.js
@@ -0,0 +1,33 @@
+const cookieParser = require('cookie-parser');
+const jwt = require('jsonwebtoken');
+
+require('dotenv').config({ path: 'variables.env' });
+const createServer = require('./createServer');
+const db = require('./db');
+
+const server = createServer();
+
+server.express.use(cookieParser());
+
+// decode the JWT so we can get the user Id on each request
+server.express.use((req, res, next) => {
+ const { token } = req.cookies;
+ if (token) {
+ const { userId } = jwt.verify(token, process.env.APP_SECRET);
+ // put the userId onto the req for future requests to access
+ req.userId = userId;
+ }
+ next();
+});
+
+server.start(
+ {
+ cors: {
+ credentials: true,
+ origin: process.env.FRONTEND_URL,
+ },
+ },
+ deets => {
+ console.log(`Server is now running on port http://localhost:${deets.port}`);
+ }
+);
diff --git a/stepped-solutions/27/backend/src/resolvers/Query.js b/stepped-solutions/27/backend/src/resolvers/Query.js
new file mode 100755
index 0000000..8055122
--- /dev/null
+++ b/stepped-solutions/27/backend/src/resolvers/Query.js
@@ -0,0 +1,21 @@
+const { forwardTo } = require('prisma-binding');
+
+const Query = {
+ items: forwardTo('db'),
+ item: forwardTo('db'),
+ itemsConnection: forwardTo('db'),
+ me(parent, args, ctx, info) {
+ // check if there is a current user ID
+ if (!ctx.request.userId) {
+ return null;
+ }
+ return ctx.db.query.user(
+ {
+ where: { id: ctx.request.userId },
+ },
+ info
+ );
+ },
+};
+
+module.exports = Query;
diff --git a/stepped-solutions/27/backend/src/schema.graphql b/stepped-solutions/27/backend/src/schema.graphql
new file mode 100755
index 0000000..f2cc283
--- /dev/null
+++ b/stepped-solutions/27/backend/src/schema.graphql
@@ -0,0 +1,15 @@
+# import * from './generated/prisma.graphql'
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+}
diff --git a/stepped-solutions/27/frontend/components/Nav.js b/stepped-solutions/27/frontend/components/Nav.js
new file mode 100755
index 0000000..df6e47f
--- /dev/null
+++ b/stepped-solutions/27/frontend/components/Nav.js
@@ -0,0 +1,32 @@
+import Link from 'next/link';
+import NavStyles from './styles/NavStyles';
+import User from './User';
+
+const Nav = () => (
+ <NavStyles>
+ <User>
+ {({ data: { me } }) => {
+ console.log(me);
+ if (me) return <p>{me.name}</p>;
+ return null;
+ }}
+ </User>
+ <Link href="/items">
+ <a>Shop</a>
+ </Link>
+ <Link href="/sell">
+ <a>Sell</a>
+ </Link>
+ <Link href="/signup">
+ <a>Signup</a>
+ </Link>
+ <Link href="/orders">
+ <a>Orders</a>
+ </Link>
+ <Link href="/me">
+ <a>Account</a>
+ </Link>
+ </NavStyles>
+);
+
+export default Nav;
diff --git a/stepped-solutions/27/frontend/components/User.js b/stepped-solutions/27/frontend/components/User.js
new file mode 100755
index 0000000..addd79d
--- /dev/null
+++ b/stepped-solutions/27/frontend/components/User.js
@@ -0,0 +1,27 @@
+import { Query } from 'react-apollo';
+import gql from 'graphql-tag';
+import PropTypes from 'prop-types';
+
+const CURRENT_USER_QUERY = gql`
+ query {
+ me {
+ id
+ email
+ name
+ permissions
+ }
+ }
+`;
+
+const User = props => (
+ <Query {...props} query={CURRENT_USER_QUERY}>
+ {payload => props.children(payload)}
+ </Query>
+);
+
+User.PropTypes = {
+ children: PropTypes.func.isRequired,
+};
+
+export default User;
+export { CURRENT_USER_QUERY };
diff --git a/stepped-solutions/28/backend/src/resolvers/Mutation.js b/stepped-solutions/28/backend/src/resolvers/Mutation.js
new file mode 100755
index 0000000..7bcbb9c
--- /dev/null
+++ b/stepped-solutions/28/backend/src/resolvers/Mutation.js
@@ -0,0 +1,95 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ // TODO: Check if they are logged in
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title}`);
+ // 2. Check if they own that item, or have the permissions
+ // TODO
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/28/backend/src/schema.graphql b/stepped-solutions/28/backend/src/schema.graphql
new file mode 100755
index 0000000..a8ad765
--- /dev/null
+++ b/stepped-solutions/28/backend/src/schema.graphql
@@ -0,0 +1,17 @@
+# import * from './generated/prisma.graphql'
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+ signin(email: String!, password: String!): User!
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+
+}
diff --git a/stepped-solutions/28/frontend/components/Nav.js b/stepped-solutions/28/frontend/components/Nav.js
new file mode 100755
index 0000000..28e94d3
--- /dev/null
+++ b/stepped-solutions/28/frontend/components/Nav.js
@@ -0,0 +1,36 @@
+import Link from 'next/link';
+import NavStyles from './styles/NavStyles';
+import User from './User';
+
+const Nav = () => (
+ <User>
+ {({ data: { me } }) => (
+ <NavStyles>
+ <Link href="/items">
+ <a>Shop</a>
+ </Link>
+ {me && (
+ <>
+ <Link href="/sell">
+ <a>Sell</a>
+ </Link>
+ <Link href="/orders">
+ <a>Orders</a>
+ </Link>
+ <Link href="/me">
+ <a>Account</a>
+ </Link>
+ </>
+ )}
+ {!me && (
+ <Link href="/signup">
+ <a>Sign In</a>
+ </Link>
+
+ )}
+ </NavStyles>
+ )}
+ </User>
+);
+
+export default Nav;
diff --git a/stepped-solutions/28/frontend/components/Signin.js b/stepped-solutions/28/frontend/components/Signin.js
new file mode 100755
index 0000000..4fd3013
--- /dev/null
+++ b/stepped-solutions/28/frontend/components/Signin.js
@@ -0,0 +1,76 @@
+import React, { Component } from 'react';
+import { Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import Form from './styles/Form';
+import Error from './ErrorMessage';
+import { CURRENT_USER_QUERY } from './User';
+
+const SIGNIN_MUTATION = gql`
+ mutation SIGNIN_MUTATION($email: String!, $password: String!) {
+ signin(email: $email, password: $password) {
+ id
+ email
+ name
+ }
+ }
+`;
+
+class Signin extends Component {
+ state = {
+ name: '',
+ password: '',
+ email: '',
+ };
+ saveToState = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+ render() {
+ return (
+ <Mutation
+ mutation={SIGNIN_MUTATION}
+ variables={this.state}
+ refetchQueries={[{ query: CURRENT_USER_QUERY }]}
+ >
+ {(signup, { error, loading }) => (
+ <Form
+ method="post"
+ onSubmit={async e => {
+ e.preventDefault();
+ await signup();
+ this.setState({ name: '', email: '', password: '' });
+ }}
+ >
+ <fieldset disabled={loading} aria-busy={loading}>
+ <h2>Sign into your account</h2>
+ <Error error={error} />
+ <label htmlFor="email">
+ Email
+ <input
+ type="email"
+ name="email"
+ placeholder="email"
+ value={this.state.email}
+ onChange={this.saveToState}
+ />
+ </label>
+ <label htmlFor="password">
+ Password
+ <input
+ type="password"
+ name="password"
+ placeholder="password"
+ value={this.state.password}
+ onChange={this.saveToState}
+ />
+ </label>
+
+ <button type="submit">Sign In!</button>
+ </fieldset>
+ </Form>
+ )}
+ </Mutation>
+ );
+ }
+}
+
+export default Signin;
diff --git a/stepped-solutions/28/frontend/components/Signup.js b/stepped-solutions/28/frontend/components/Signup.js
new file mode 100755
index 0000000..3e59a2b
--- /dev/null
+++ b/stepped-solutions/28/frontend/components/Signup.js
@@ -0,0 +1,86 @@
+import React, { Component } from 'react';
+import { Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import Form from './styles/Form';
+import Error from './ErrorMessage';
+import { CURRENT_USER_QUERY } from './User';
+
+const SIGNUP_MUTATION = gql`
+ mutation SIGNUP_MUTATION($email: String!, $name: String!, $password: String!) {
+ signup(email: $email, name: $name, password: $password) {
+ id
+ email
+ name
+ }
+ }
+`;
+
+class Signup extends Component {
+ state = {
+ name: '',
+ password: '',
+ email: '',
+ };
+ saveToState = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+ render() {
+ return (
+ <Mutation
+ mutation={SIGNUP_MUTATION}
+ variables={this.state}
+ refetchQueries={[{ query: CURRENT_USER_QUERY }]}
+ >
+ {(signup, { error, loading }) => (
+ <Form
+ method="post"
+ onSubmit={async e => {
+ e.preventDefault();
+ await signup();
+ this.setState({ name: '', email: '', password: '' });
+ }}
+ >
+ <fieldset disabled={loading} aria-busy={loading}>
+ <h2>Sign Up for An Account</h2>
+ <Error error={error} />
+ <label htmlFor="email">
+ Email
+ <input
+ type="email"
+ name="email"
+ placeholder="email"
+ value={this.state.email}
+ onChange={this.saveToState}
+ />
+ </label>
+ <label htmlFor="name">
+ Name
+ <input
+ type="text"
+ name="name"
+ placeholder="name"
+ value={this.state.name}
+ onChange={this.saveToState}
+ />
+ </label>
+ <label htmlFor="password">
+ Password
+ <input
+ type="password"
+ name="password"
+ placeholder="password"
+ value={this.state.password}
+ onChange={this.saveToState}
+ />
+ </label>
+
+ <button type="submit">Sign Up!</button>
+ </fieldset>
+ </Form>
+ )}
+ </Mutation>
+ );
+ }
+}
+
+export default Signup;
diff --git a/stepped-solutions/28/frontend/components/User.js b/stepped-solutions/28/frontend/components/User.js
new file mode 100755
index 0000000..af074c0
--- /dev/null
+++ b/stepped-solutions/28/frontend/components/User.js
@@ -0,0 +1,27 @@
+import { Query } from 'react-apollo';
+import gql from 'graphql-tag';
+import PropTypes from 'prop-types';
+
+const CURRENT_USER_QUERY = gql`
+ query {
+ me {
+ id
+ email
+ name
+ permissions
+ }
+ }
+`;
+
+const User = props => (
+ <Query {...props} query={CURRENT_USER_QUERY}>
+ {payload => console.log(payload) || props.children(payload)}
+ </Query>
+);
+
+User.PropTypes = {
+ children: PropTypes.func.isRequired,
+};
+
+export default User;
+export { CURRENT_USER_QUERY };
diff --git a/stepped-solutions/28/frontend/pages/signup.js b/stepped-solutions/28/frontend/pages/signup.js
new file mode 100755
index 0000000..28ed2f4
--- /dev/null
+++ b/stepped-solutions/28/frontend/pages/signup.js
@@ -0,0 +1,18 @@
+import Signup from '../components/Signup';
+import Signin from '../components/Signin';
+import styled from 'styled-components';
+
+const Columns = styled.div`
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
+ grid-gap: 20px;
+`;
+
+const SignupPage = props => (
+ <Columns>
+ <Signup />
+ <Signin />
+ </Columns>
+);
+
+export default SignupPage;
diff --git a/stepped-solutions/29/backend/src/resolvers/Mutation.js b/stepped-solutions/29/backend/src/resolvers/Mutation.js
new file mode 100755
index 0000000..6c34b8c
--- /dev/null
+++ b/stepped-solutions/29/backend/src/resolvers/Mutation.js
@@ -0,0 +1,99 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ // TODO: Check if they are logged in
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title}`);
+ // 2. Check if they own that item, or have the permissions
+ // TODO
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+ signout(parent, args, ctx, info) {
+ ctx.response.clearCookie('token');
+ return { message: 'Goodbye!' };
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/29/backend/src/schema.graphql b/stepped-solutions/29/backend/src/schema.graphql
new file mode 100755
index 0000000..40916a1
--- /dev/null
+++ b/stepped-solutions/29/backend/src/schema.graphql
@@ -0,0 +1,22 @@
+# import * from './generated/prisma.graphql'
+
+type SuccessMessage {
+ message: String
+}
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+ signin(email: String!, password: String!): User!
+ signout: SuccessMessage
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+
+}
diff --git a/stepped-solutions/29/frontend/components/Nav.js b/stepped-solutions/29/frontend/components/Nav.js
new file mode 100755
index 0000000..12abde5
--- /dev/null
+++ b/stepped-solutions/29/frontend/components/Nav.js
@@ -0,0 +1,38 @@
+import Link from 'next/link';
+import NavStyles from './styles/NavStyles';
+import User from './User';
+import Signout from './Signout';
+
+const Nav = () => (
+ <User>
+ {({ data: { me } }) => (
+ <NavStyles>
+ <Link href="/items">
+ <a>Shop</a>
+ </Link>
+ {me && (
+ <>
+ <Link href="/sell">
+ <a>Sell</a>
+ </Link>
+ <Link href="/orders">
+ <a>Orders</a>
+ </Link>
+ <Link href="/me">
+ <a>Account</a>
+ </Link>
+ <Signout />
+ </>
+ )}
+ {!me && (
+ <Link href="/signup">
+ <a>Sign In</a>
+ </Link>
+
+ )}
+ </NavStyles>
+ )}
+ </User>
+);
+
+export default Nav;
diff --git a/stepped-solutions/29/frontend/components/Signout.js b/stepped-solutions/29/frontend/components/Signout.js
new file mode 100755
index 0000000..f852531
--- /dev/null
+++ b/stepped-solutions/29/frontend/components/Signout.js
@@ -0,0 +1,19 @@
+import React, { Component } from 'react';
+import { Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import { CURRENT_USER_QUERY } from './User';
+
+const SIGN_OUT_MUTATION = gql`
+ mutation SIGN_OUT_MUTATION {
+ signout {
+ message
+ }
+ }
+`;
+
+const Signout = props => (
+ <Mutation mutation={SIGN_OUT_MUTATION} refetchQueries={[{ query: CURRENT_USER_QUERY }]}>
+ {signout => <button onClick={signout}>Sign Out</button>}
+ </Mutation>
+);
+export default Signout;
diff --git a/stepped-solutions/29/frontend/components/styles/NavStyles.js b/stepped-solutions/29/frontend/components/styles/NavStyles.js
new file mode 100755
index 0000000..fe4abda
--- /dev/null
+++ b/stepped-solutions/29/frontend/components/styles/NavStyles.js
@@ -0,0 +1,66 @@
+import styled from 'styled-components';
+
+const NavStyles = styled.ul`
+ margin: 0;
+ padding: 0;
+ display: flex;
+ justify-self: end;
+ font-size: 2rem;
+ a,
+ button {
+ padding: 1rem 3rem;
+ display: flex;
+ align-items: center;
+ position: relative;
+ text-transform: uppercase;
+ font-weight: 900;
+ font-size: 1em;
+ background: none;
+ border: 0;
+ cursor: pointer;
+ color: ${props => props.theme.black};
+ font-weight: 800;
+ @media (max-width: 700px) {
+ font-size: 10px;
+ padding: 0 10px;
+ }
+ &:before {
+ content: '';
+ width: 2px;
+ background: ${props => props.theme.lightgrey};
+ height: 100%;
+ left: 0;
+ position: absolute;
+ transform: skew(-20deg);
+ top: 0;
+ bottom: 0;
+ }
+ &:after {
+ height: 2px;
+ background: red;
+ content: '';
+ width: 0;
+ position: absolute;
+ transform: translateX(-50%);
+ transition: width 0.4s;
+ transition-timing-function: cubic-bezier(1, -0.65, 0, 2.31);
+ left: 50%;
+ margin-top: 2rem;
+ }
+ &:hover,
+ &:focus {
+ outline: none;
+ &:after {
+ width: calc(100% - 60px);
+ }
+ }
+ }
+ @media (max-width: 1300px) {
+ border-top: 1px solid ${props => props.theme.lightgrey};
+ width: 100%;
+ justify-content: center;
+ font-size: 1.5rem;
+ }
+`;
+
+export default NavStyles;
diff --git a/stepped-solutions/30/src/resolvers/Mutation.js b/stepped-solutions/30/src/resolvers/Mutation.js
new file mode 100755
index 0000000..7f43b1a
--- /dev/null
+++ b/stepped-solutions/30/src/resolvers/Mutation.js
@@ -0,0 +1,156 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+const { randomBytes } = require('crypto');
+const { promisify } = require('util');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ // TODO: Check if they are logged in
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title}`);
+ // 2. Check if they own that item, or have the permissions
+ // TODO
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+ signout(parent, args, ctx, info) {
+ ctx.response.clearCookie('token');
+ return { message: 'Goodbye!' };
+ },
+ async requestReset(parent, args, ctx, info) {
+ // 1. Check if this is a real user
+ const user = await ctx.db.query.user({ where: { email: args.email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${args.email}`);
+ }
+ // 2. Set a reset token and expiry on that user
+ const randomBytesPromiseified = promisify(randomBytes);
+ const resetToken = (await randomBytesPromiseified(20)).toString('hex');
+ const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now
+ const res = await ctx.db.mutation.updateUser({
+ where: { email: args.email },
+ data: { resetToken, resetTokenExpiry },
+ });
+ console.log(res);
+ return { message: 'Thanks!' };
+ // 3. Email them that reset token
+ },
+ async resetPassword(parent, args, ctx, info) {
+ // 1. check if the passwords match
+ if (args.password !== args.confirmPassword) {
+ throw new Error("Yo Passwords don't match!");
+ }
+ // 2. check if its a legit reset token
+ // 3. Check if its expired
+ const [user] = await ctx.db.query.users({
+ where: {
+ resetToken: args.resetToken,
+ resetTokenExpiry_gte: Date.now() - 3600000,
+ },
+ });
+ if (!user) {
+ throw new Error('This token is either invalid or expired!');
+ }
+ // 4. Hash their new password
+ const password = await bcrypt.hash(args.password, 10);
+ // 5. Save the new password to the user and remove old resetToken fields
+ const updatedUser = await ctx.db.mutation.updateUser({
+ where: { email: user.email },
+ data: {
+ password,
+ resetToken: null,
+ resetTokenExpiry: null,
+ },
+ });
+ // 6. Generate JWT
+ const token = jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET);
+ // 7. Set the JWT cookie
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 8. return the new user
+ return updatedUser;
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/30/src/schema.graphql b/stepped-solutions/30/src/schema.graphql
new file mode 100755
index 0000000..d1db1ba
--- /dev/null
+++ b/stepped-solutions/30/src/schema.graphql
@@ -0,0 +1,30 @@
+# import * from './generated/prisma.graphql'
+
+type SuccessMessage {
+ message: String
+}
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+ signin(email: String!, password: String!): User!
+ signout: SuccessMessage
+ requestReset(email: String!): SuccessMessage
+ resetPassword(resetToken: String!, password: String!, confirmPassword: String!): User!
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+}
+
+type User{
+ id: ID!
+ name: String!
+ email: String!
+ permissions: [Permission!]!
+}
diff --git a/stepped-solutions/31/frontend/components/RequestReset.js b/stepped-solutions/31/frontend/components/RequestReset.js
new file mode 100755
index 0000000..dbc77ab
--- /dev/null
+++ b/stepped-solutions/31/frontend/components/RequestReset.js
@@ -0,0 +1,58 @@
+import React, { Component } from 'react';
+import { Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import Form from './styles/Form';
+import Error from './ErrorMessage';
+
+const REQUEST_RESET_MUTATION = gql`
+ mutation REQUEST_RESET_MUTATION($email: String!) {
+ requestReset(email: $email) {
+ message
+ }
+ }
+`;
+
+class Signin extends Component {
+ state = {
+ email: '',
+ };
+ saveToState = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+ render() {
+ return (
+ <Mutation mutation={REQUEST_RESET_MUTATION} variables={this.state}>
+ {(reset, { error, loading, called }) => (
+ <Form
+ method="post"
+ onSubmit={async e => {
+ e.preventDefault();
+ await reset();
+ this.setState({ email: '' });
+ }}
+ >
+ <fieldset disabled={loading} aria-busy={loading}>
+ <h2>Request a password reset</h2>
+ <Error error={error} />
+ {!error && !loading && called && <p>Success! Check your email for a reset link!</p>}
+ <label htmlFor="email">
+ Email
+ <input
+ type="email"
+ name="email"
+ placeholder="email"
+ value={this.state.email}
+ onChange={this.saveToState}
+ />
+ </label>
+
+ <button type="submit">Request Reset!</button>
+ </fieldset>
+ </Form>
+ )}
+ </Mutation>
+ );
+ }
+}
+
+export default Signin;
diff --git a/stepped-solutions/31/frontend/components/Reset.js b/stepped-solutions/31/frontend/components/Reset.js
new file mode 100755
index 0000000..a132f03
--- /dev/null
+++ b/stepped-solutions/31/frontend/components/Reset.js
@@ -0,0 +1,84 @@
+import React, { Component } from 'react';
+import { Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import PropTypes from 'prop-types';
+import Form from './styles/Form';
+import Error from './ErrorMessage';
+import { CURRENT_USER_QUERY } from './User';
+
+const RESET_MUTATION = gql`
+ mutation RESET_MUTATION($resetToken: String!, $password: String!, $confirmPassword: String!) {
+ resetPassword(resetToken: $resetToken, password: $password, confirmPassword: $confirmPassword) {
+ id
+ email
+ name
+ }
+ }
+`;
+
+class Reset extends Component {
+ static propTypes = {
+ resetToken: PropTypes.string.isRequired,
+ };
+ state = {
+ password: '',
+ confirmPassword: '',
+ };
+ saveToState = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+ render() {
+ return (
+ <Mutation
+ mutation={RESET_MUTATION}
+ variables={{
+ resetToken: this.props.resetToken,
+ password: this.state.password,
+ confirmPassword: this.state.confirmPassword,
+ }}
+ refetchQueries={[{ query: CURRENT_USER_QUERY }]}
+ >
+ {(reset, { error, loading, called }) => (
+ <Form
+ method="post"
+ onSubmit={async e => {
+ e.preventDefault();
+ await reset();
+ this.setState({ password: '', confirmPassword: '' });
+ }}
+ >
+ <fieldset disabled={loading} aria-busy={loading}>
+ <h2>Reset Your Password</h2>
+ <Error error={error} />
+ <label htmlFor="password">
+ Password
+ <input
+ type="password"
+ name="password"
+ placeholder="password"
+ value={this.state.password}
+ onChange={this.saveToState}
+ />
+ </label>
+
+ <label htmlFor="confirmPassword">
+ Confirm Your Password
+ <input
+ type="password"
+ name="confirmPassword"
+ placeholder="confirmPassword"
+ value={this.state.confirmPassword}
+ onChange={this.saveToState}
+ />
+ </label>
+
+ <button type="submit">Reset Your Password!</button>
+ </fieldset>
+ </Form>
+ )}
+ </Mutation>
+ );
+ }
+}
+
+export default Reset;
diff --git a/stepped-solutions/31/frontend/pages/reset.js b/stepped-solutions/31/frontend/pages/reset.js
new file mode 100755
index 0000000..118ba72
--- /dev/null
+++ b/stepped-solutions/31/frontend/pages/reset.js
@@ -0,0 +1,10 @@
+import Reset from '../components/Reset';
+
+const Sell = props => (
+ <div>
+ <p>Reset Your Password {props.query.resetToken}</p>
+ <Reset resetToken={props.query.resetToken} />
+ </div>
+);
+
+export default Sell;
diff --git a/stepped-solutions/31/frontend/pages/signup.js b/stepped-solutions/31/frontend/pages/signup.js
new file mode 100755
index 0000000..342cfea
--- /dev/null
+++ b/stepped-solutions/31/frontend/pages/signup.js
@@ -0,0 +1,20 @@
+import Signup from '../components/Signup';
+import Signin from '../components/Signin';
+import RequestReset from '../components/RequestReset';
+import styled from 'styled-components';
+
+const Columns = styled.div`
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
+ grid-gap: 20px;
+`;
+
+const SignupPage = props => (
+ <Columns>
+ <Signup />
+ <Signin />
+ <RequestReset />
+ </Columns>
+);
+
+export default SignupPage;
diff --git a/stepped-solutions/32/backend/src/mail.js b/stepped-solutions/32/backend/src/mail.js
new file mode 100755
index 0000000..5274310
--- /dev/null
+++ b/stepped-solutions/32/backend/src/mail.js
@@ -0,0 +1,28 @@
+const nodemailer = require('nodemailer');
+
+const transport = nodemailer.createTransport({
+ host: process.env.MAIL_HOST,
+ port: process.env.MAIL_PORT,
+ auth: {
+ user: process.env.MAIL_USER,
+ pass: process.env.MAIL_PASS,
+ },
+});
+
+const makeANiceEmail = text => `
+ <div className="email" style="
+ border: 1px solid black;
+ padding: 20px;
+ font-family: sans-serif;
+ line-height: 2;
+ font-size: 20px;
+ ">
+ <h2>Hello There!</h2>
+ <p>${text}</p>
+
+ <p>😘, Wes Bos</p>
+ </div>
+`;
+
+exports.transport = transport;
+exports.makeANiceEmail = makeANiceEmail;
diff --git a/stepped-solutions/32/backend/src/resolvers/Mutation.js b/stepped-solutions/32/backend/src/resolvers/Mutation.js
new file mode 100755
index 0000000..294fc00
--- /dev/null
+++ b/stepped-solutions/32/backend/src/resolvers/Mutation.js
@@ -0,0 +1,167 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+const { randomBytes } = require('crypto');
+const { promisify } = require('util');
+const { transport, makeANiceEmail } = require('../mail');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ // TODO: Check if they are logged in
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title}`);
+ // 2. Check if they own that item, or have the permissions
+ // TODO
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+ signout(parent, args, ctx, info) {
+ ctx.response.clearCookie('token');
+ return { message: 'Goodbye!' };
+ },
+ async requestReset(parent, args, ctx, info) {
+ // 1. Check if this is a real user
+ const user = await ctx.db.query.user({ where: { email: args.email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${args.email}`);
+ }
+ // 2. Set a reset token and expiry on that user
+ const randomBytesPromiseified = promisify(randomBytes);
+ const resetToken = (await randomBytesPromiseified(20)).toString('hex');
+ const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now
+ const res = await ctx.db.mutation.updateUser({
+ where: { email: args.email },
+ data: { resetToken, resetTokenExpiry },
+ });
+ // 3. Email them that reset token
+ const mailRes = await transport.sendMail({
+ from: 'wes@wesbos.com',
+ to: user.email,
+ subject: 'Your Password Reset Token',
+ html: makeANiceEmail(`Your Password Reset Token is here!
+ \n\n
+ <a href="${process.env
+ .FRONTEND_URL}/reset?resetToken=${resetToken}">Click Here to Reset</a>`),
+ });
+
+ // 4. Return the message
+ return { message: 'Thanks!' };
+ },
+ async resetPassword(parent, args, ctx, info) {
+ // 1. check if the passwords match
+ if (args.password !== args.confirmPassword) {
+ throw new Error("Yo Passwords don't match!");
+ }
+ // 2. check if its a legit reset token
+ // 3. Check if its expired
+ const [user] = await ctx.db.query.users({
+ where: {
+ resetToken: args.resetToken,
+ resetTokenExpiry_gte: Date.now() - 3600000,
+ },
+ });
+ if (!user) {
+ throw new Error('This token is either invalid or expired!');
+ }
+ // 4. Hash their new password
+ const password = await bcrypt.hash(args.password, 10);
+ // 5. Save the new password to the user and remove old resetToken fields
+ const updatedUser = await ctx.db.mutation.updateUser({
+ where: { email: user.email },
+ data: {
+ password,
+ resetToken: null,
+ resetTokenExpiry: null,
+ },
+ });
+ // 6. Generate JWT
+ const token = jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET);
+ // 7. Set the JWT cookie
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 8. return the new user
+ return updatedUser;
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/33/backend/datamodel.graphql b/stepped-solutions/33/backend/datamodel.graphql
new file mode 100755
index 0000000..e9b8009
--- /dev/null
+++ b/stepped-solutions/33/backend/datamodel.graphql
@@ -0,0 +1,28 @@
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type User {
+ id: ID! @unique
+ name: String!
+ email: String! @unique
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission]
+}
+
+type Item {
+ id: ID! @unique
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: User!
+}
diff --git a/stepped-solutions/33/backend/src/generated/prisma.graphql b/stepped-solutions/33/backend/src/generated/prisma.graphql
new file mode 100755
index 0000000..40a64c0
--- /dev/null
+++ b/stepped-solutions/33/backend/src/generated/prisma.graphql
@@ -0,0 +1,850 @@
+# source: https://us1.prisma.sh/wesbos/siccccccccck-fits/dev
+# timestamp: Tue Aug 14 2018 13:23:45 GMT-0400 (EDT)
+
+type AggregateItem {
+ count: Int!
+}
+
+type AggregateUser {
+ count: Int!
+}
+
+type BatchPayload {
+ """The number of nodes that have been affected by the Batch operation."""
+ count: Long!
+}
+
+type Item implements Node {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type ItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [ItemEdge]!
+ aggregate: AggregateItem!
+}
+
+input ItemCreateInput {
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: UserCreateOneInput!
+}
+
+"""An edge in a connection."""
+type ItemEdge {
+ """The item at the end of the edge."""
+ node: Item!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum ItemOrderByInput {
+ id_ASC
+ id_DESC
+ title_ASC
+ title_DESC
+ description_ASC
+ description_DESC
+ image_ASC
+ image_DESC
+ largeImage_ASC
+ largeImage_DESC
+ price_ASC
+ price_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type ItemPreviousValues {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+}
+
+type ItemSubscriptionPayload {
+ mutation: MutationType!
+ node: Item
+ updatedFields: [String!]
+ previousValues: ItemPreviousValues
+}
+
+input ItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: ItemWhereInput
+}
+
+input ItemUpdateInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneInput
+}
+
+input ItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ title: String
+
+ """All values that are not equal to given value."""
+ title_not: String
+
+ """All values that are contained in given list."""
+ title_in: [String!]
+
+ """All values that are not contained in given list."""
+ title_not_in: [String!]
+
+ """All values less than the given value."""
+ title_lt: String
+
+ """All values less than or equal the given value."""
+ title_lte: String
+
+ """All values greater than the given value."""
+ title_gt: String
+
+ """All values greater than or equal the given value."""
+ title_gte: String
+
+ """All values containing the given string."""
+ title_contains: String
+
+ """All values not containing the given string."""
+ title_not_contains: String
+
+ """All values starting with the given string."""
+ title_starts_with: String
+
+ """All values not starting with the given string."""
+ title_not_starts_with: String
+
+ """All values ending with the given string."""
+ title_ends_with: String
+
+ """All values not ending with the given string."""
+ title_not_ends_with: String
+ description: String
+
+ """All values that are not equal to given value."""
+ description_not: String
+
+ """All values that are contained in given list."""
+ description_in: [String!]
+
+ """All values that are not contained in given list."""
+ description_not_in: [String!]
+
+ """All values less than the given value."""
+ description_lt: String
+
+ """All values less than or equal the given value."""
+ description_lte: String
+
+ """All values greater than the given value."""
+ description_gt: String
+
+ """All values greater than or equal the given value."""
+ description_gte: String
+
+ """All values containing the given string."""
+ description_contains: String
+
+ """All values not containing the given string."""
+ description_not_contains: String
+
+ """All values starting with the given string."""
+ description_starts_with: String
+
+ """All values not starting with the given string."""
+ description_not_starts_with: String
+
+ """All values ending with the given string."""
+ description_ends_with: String
+
+ """All values not ending with the given string."""
+ description_not_ends_with: String
+ image: String
+
+ """All values that are not equal to given value."""
+ image_not: String
+
+ """All values that are contained in given list."""
+ image_in: [String!]
+
+ """All values that are not contained in given list."""
+ image_not_in: [String!]
+
+ """All values less than the given value."""
+ image_lt: String
+
+ """All values less than or equal the given value."""
+ image_lte: String
+
+ """All values greater than the given value."""
+ image_gt: String
+
+ """All values greater than or equal the given value."""
+ image_gte: String
+
+ """All values containing the given string."""
+ image_contains: String
+
+ """All values not containing the given string."""
+ image_not_contains: String
+
+ """All values starting with the given string."""
+ image_starts_with: String
+
+ """All values not starting with the given string."""
+ image_not_starts_with: String
+
+ """All values ending with the given string."""
+ image_ends_with: String
+
+ """All values not ending with the given string."""
+ image_not_ends_with: String
+ largeImage: String
+
+ """All values that are not equal to given value."""
+ largeImage_not: String
+
+ """All values that are contained in given list."""
+ largeImage_in: [String!]
+
+ """All values that are not contained in given list."""
+ largeImage_not_in: [String!]
+
+ """All values less than the given value."""
+ largeImage_lt: String
+
+ """All values less than or equal the given value."""
+ largeImage_lte: String
+
+ """All values greater than the given value."""
+ largeImage_gt: String
+
+ """All values greater than or equal the given value."""
+ largeImage_gte: String
+
+ """All values containing the given string."""
+ largeImage_contains: String
+
+ """All values not containing the given string."""
+ largeImage_not_contains: String
+
+ """All values starting with the given string."""
+ largeImage_starts_with: String
+
+ """All values not starting with the given string."""
+ largeImage_not_starts_with: String
+
+ """All values ending with the given string."""
+ largeImage_ends_with: String
+
+ """All values not ending with the given string."""
+ largeImage_not_ends_with: String
+ price: Int
+
+ """All values that are not equal to given value."""
+ price_not: Int
+
+ """All values that are contained in given list."""
+ price_in: [Int!]
+
+ """All values that are not contained in given list."""
+ price_not_in: [Int!]
+
+ """All values less than the given value."""
+ price_lt: Int
+
+ """All values less than or equal the given value."""
+ price_lte: Int
+
+ """All values greater than the given value."""
+ price_gt: Int
+
+ """All values greater than or equal the given value."""
+ price_gte: Int
+ user: UserWhereInput
+}
+
+input ItemWhereUniqueInput {
+ id: ID
+}
+
+"""
+The `Long` scalar type represents non-fractional signed whole numeric values.
+Long can represent values between -(2^63) and 2^63 - 1.
+"""
+scalar Long
+
+type Mutation {
+ createItem(data: ItemCreateInput!): Item!
+ createUser(data: UserCreateInput!): User!
+ updateItem(data: ItemUpdateInput!, where: ItemWhereUniqueInput!): Item
+ updateUser(data: UserUpdateInput!, where: UserWhereUniqueInput!): User
+ deleteItem(where: ItemWhereUniqueInput!): Item
+ deleteUser(where: UserWhereUniqueInput!): User
+ upsertItem(where: ItemWhereUniqueInput!, create: ItemCreateInput!, update: ItemUpdateInput!): Item!
+ upsertUser(where: UserWhereUniqueInput!, create: UserCreateInput!, update: UserUpdateInput!): User!
+ updateManyItems(data: ItemUpdateInput!, where: ItemWhereInput): BatchPayload!
+ updateManyUsers(data: UserUpdateInput!, where: UserWhereInput): BatchPayload!
+ deleteManyItems(where: ItemWhereInput): BatchPayload!
+ deleteManyUsers(where: UserWhereInput): BatchPayload!
+}
+
+enum MutationType {
+ CREATED
+ UPDATED
+ DELETED
+}
+
+"""An object with an ID"""
+interface Node {
+ """The id of the object."""
+ id: ID!
+}
+
+"""Information about pagination in a connection."""
+type PageInfo {
+ """When paginating forwards, are there more items?"""
+ hasNextPage: Boolean!
+
+ """When paginating backwards, are there more items?"""
+ hasPreviousPage: Boolean!
+
+ """When paginating backwards, the cursor to continue."""
+ startCursor: String
+
+ """When paginating forwards, the cursor to continue."""
+ endCursor: String
+}
+
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Item]!
+ users(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [User]!
+ item(where: ItemWhereUniqueInput!): Item
+ user(where: UserWhereUniqueInput!): User
+ itemsConnection(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): ItemConnection!
+ usersConnection(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): UserConnection!
+
+ """Fetches an object given its ID"""
+ node(
+ """The ID of an object"""
+ id: ID!
+ ): Node
+}
+
+type Subscription {
+ item(where: ItemSubscriptionWhereInput): ItemSubscriptionPayload
+ user(where: UserSubscriptionWhereInput): UserSubscriptionPayload
+}
+
+type User implements Node {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+}
+
+"""A connection to a list of items."""
+type UserConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [UserEdge]!
+ aggregate: AggregateUser!
+}
+
+input UserCreateInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+}
+
+input UserCreateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreatepermissionsInput {
+ set: [Permission!]
+}
+
+"""An edge in a connection."""
+type UserEdge {
+ """The item at the end of the edge."""
+ node: User!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum UserOrderByInput {
+ id_ASC
+ id_DESC
+ name_ASC
+ name_DESC
+ email_ASC
+ email_DESC
+ password_ASC
+ password_DESC
+ resetToken_ASC
+ resetToken_DESC
+ resetTokenExpiry_ASC
+ resetTokenExpiry_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type UserPreviousValues {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+}
+
+type UserSubscriptionPayload {
+ mutation: MutationType!
+ node: User
+ updatedFields: [String!]
+ previousValues: UserPreviousValues
+}
+
+input UserSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: UserWhereInput
+}
+
+input UserUpdateDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+}
+
+input UserUpdateInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+}
+
+input UserUpdateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+ delete: Boolean
+ update: UserUpdateDataInput
+ upsert: UserUpsertNestedInput
+}
+
+input UserUpdatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserUpsertNestedInput {
+ update: UserUpdateDataInput!
+ create: UserCreateInput!
+}
+
+input UserWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ name: String
+
+ """All values that are not equal to given value."""
+ name_not: String
+
+ """All values that are contained in given list."""
+ name_in: [String!]
+
+ """All values that are not contained in given list."""
+ name_not_in: [String!]
+
+ """All values less than the given value."""
+ name_lt: String
+
+ """All values less than or equal the given value."""
+ name_lte: String
+
+ """All values greater than the given value."""
+ name_gt: String
+
+ """All values greater than or equal the given value."""
+ name_gte: String
+
+ """All values containing the given string."""
+ name_contains: String
+
+ """All values not containing the given string."""
+ name_not_contains: String
+
+ """All values starting with the given string."""
+ name_starts_with: String
+
+ """All values not starting with the given string."""
+ name_not_starts_with: String
+
+ """All values ending with the given string."""
+ name_ends_with: String
+
+ """All values not ending with the given string."""
+ name_not_ends_with: String
+ email: String
+
+ """All values that are not equal to given value."""
+ email_not: String
+
+ """All values that are contained in given list."""
+ email_in: [String!]
+
+ """All values that are not contained in given list."""
+ email_not_in: [String!]
+
+ """All values less than the given value."""
+ email_lt: String
+
+ """All values less than or equal the given value."""
+ email_lte: String
+
+ """All values greater than the given value."""
+ email_gt: String
+
+ """All values greater than or equal the given value."""
+ email_gte: String
+
+ """All values containing the given string."""
+ email_contains: String
+
+ """All values not containing the given string."""
+ email_not_contains: String
+
+ """All values starting with the given string."""
+ email_starts_with: String
+
+ """All values not starting with the given string."""
+ email_not_starts_with: String
+
+ """All values ending with the given string."""
+ email_ends_with: String
+
+ """All values not ending with the given string."""
+ email_not_ends_with: String
+ password: String
+
+ """All values that are not equal to given value."""
+ password_not: String
+
+ """All values that are contained in given list."""
+ password_in: [String!]
+
+ """All values that are not contained in given list."""
+ password_not_in: [String!]
+
+ """All values less than the given value."""
+ password_lt: String
+
+ """All values less than or equal the given value."""
+ password_lte: String
+
+ """All values greater than the given value."""
+ password_gt: String
+
+ """All values greater than or equal the given value."""
+ password_gte: String
+
+ """All values containing the given string."""
+ password_contains: String
+
+ """All values not containing the given string."""
+ password_not_contains: String
+
+ """All values starting with the given string."""
+ password_starts_with: String
+
+ """All values not starting with the given string."""
+ password_not_starts_with: String
+
+ """All values ending with the given string."""
+ password_ends_with: String
+
+ """All values not ending with the given string."""
+ password_not_ends_with: String
+ resetToken: String
+
+ """All values that are not equal to given value."""
+ resetToken_not: String
+
+ """All values that are contained in given list."""
+ resetToken_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetToken_not_in: [String!]
+
+ """All values less than the given value."""
+ resetToken_lt: String
+
+ """All values less than or equal the given value."""
+ resetToken_lte: String
+
+ """All values greater than the given value."""
+ resetToken_gt: String
+
+ """All values greater than or equal the given value."""
+ resetToken_gte: String
+
+ """All values containing the given string."""
+ resetToken_contains: String
+
+ """All values not containing the given string."""
+ resetToken_not_contains: String
+
+ """All values starting with the given string."""
+ resetToken_starts_with: String
+
+ """All values not starting with the given string."""
+ resetToken_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetToken_ends_with: String
+
+ """All values not ending with the given string."""
+ resetToken_not_ends_with: String
+ resetTokenExpiry: String
+
+ """All values that are not equal to given value."""
+ resetTokenExpiry_not: String
+
+ """All values that are contained in given list."""
+ resetTokenExpiry_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetTokenExpiry_not_in: [String!]
+
+ """All values less than the given value."""
+ resetTokenExpiry_lt: String
+
+ """All values less than or equal the given value."""
+ resetTokenExpiry_lte: String
+
+ """All values greater than the given value."""
+ resetTokenExpiry_gt: String
+
+ """All values greater than or equal the given value."""
+ resetTokenExpiry_gte: String
+
+ """All values containing the given string."""
+ resetTokenExpiry_contains: String
+
+ """All values not containing the given string."""
+ resetTokenExpiry_not_contains: String
+
+ """All values starting with the given string."""
+ resetTokenExpiry_starts_with: String
+
+ """All values not starting with the given string."""
+ resetTokenExpiry_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetTokenExpiry_ends_with: String
+
+ """All values not ending with the given string."""
+ resetTokenExpiry_not_ends_with: String
+}
+
+input UserWhereUniqueInput {
+ id: ID
+ email: String
+}
diff --git a/stepped-solutions/33/backend/src/resolvers/Mutation.js b/stepped-solutions/33/backend/src/resolvers/Mutation.js
new file mode 100755
index 0000000..ada7d3c
--- /dev/null
+++ b/stepped-solutions/33/backend/src/resolvers/Mutation.js
@@ -0,0 +1,175 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+const { randomBytes } = require('crypto');
+const { promisify } = require('util');
+const { transport, makeANiceEmail } = require('../mail');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in to do that!');
+ }
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ // This is how to create a relationship between the Item and the User
+ user: {
+ connect: {
+ id: ctx.request.userId,
+ },
+ },
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title}`);
+ // 2. Check if they own that item, or have the permissions
+ // TODO
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+ signout(parent, args, ctx, info) {
+ ctx.response.clearCookie('token');
+ return { message: 'Goodbye!' };
+ },
+ async requestReset(parent, args, ctx, info) {
+ // 1. Check if this is a real user
+ const user = await ctx.db.query.user({ where: { email: args.email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${args.email}`);
+ }
+ // 2. Set a reset token and expiry on that user
+ const randomBytesPromiseified = promisify(randomBytes);
+ const resetToken = (await randomBytesPromiseified(20)).toString('hex');
+ const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now
+ const res = await ctx.db.mutation.updateUser({
+ where: { email: args.email },
+ data: { resetToken, resetTokenExpiry },
+ });
+ // 3. Email them that reset token
+ const mailRes = await transport.sendMail({
+ from: 'wes@wesbos.com',
+ to: user.email,
+ subject: 'Your Password Reset Token',
+ html: makeANiceEmail(`Your Password Reset Token is here!
+ \n\n
+ <a href="${process.env
+ .FRONTEND_URL}/reset?resetToken=${resetToken}">Click Here to Reset</a>`),
+ });
+
+ // 4. Return the message
+ return { message: 'Thanks!' };
+ },
+ async resetPassword(parent, args, ctx, info) {
+ // 1. check if the passwords match
+ if (args.password !== args.confirmPassword) {
+ throw new Error("Yo Passwords don't match!");
+ }
+ // 2. check if its a legit reset token
+ // 3. Check if its expired
+ const [user] = await ctx.db.query.users({
+ where: {
+ resetToken: args.resetToken,
+ resetTokenExpiry_gte: Date.now() - 3600000,
+ },
+ });
+ if (!user) {
+ throw new Error('This token is either invalid or expired!');
+ }
+ // 4. Hash their new password
+ const password = await bcrypt.hash(args.password, 10);
+ // 5. Save the new password to the user and remove old resetToken fields
+ const updatedUser = await ctx.db.mutation.updateUser({
+ where: { email: user.email },
+ data: {
+ password,
+ resetToken: null,
+ resetTokenExpiry: null,
+ },
+ });
+ // 6. Generate JWT
+ const token = jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET);
+ // 7. Set the JWT cookie
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 8. return the new user
+ return updatedUser;
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/34/frontend/components/PleaseSignIn.js b/stepped-solutions/34/frontend/components/PleaseSignIn.js
new file mode 100755
index 0000000..80cfdbf
--- /dev/null
+++ b/stepped-solutions/34/frontend/components/PleaseSignIn.js
@@ -0,0 +1,22 @@
+import { Query } from 'react-apollo';
+import { CURRENT_USER_QUERY } from './User';
+import Signin from './Signin';
+
+const PleaseSignIn = props => (
+ <Query query={CURRENT_USER_QUERY}>
+ {({ data, loading }) => {
+ if (loading) return <p>Loading...</p>;
+ if (!data.me) {
+ return (
+ <div>
+ <p>Please Sign In before Continuing</p>
+ <Signin />
+ </div>
+ );
+ }
+ return props.children;
+ }}
+ </Query>
+);
+
+export default PleaseSignIn;
diff --git a/stepped-solutions/34/frontend/pages/sell.js b/stepped-solutions/34/frontend/pages/sell.js
new file mode 100755
index 0000000..b60ae80
--- /dev/null
+++ b/stepped-solutions/34/frontend/pages/sell.js
@@ -0,0 +1,12 @@
+import CreateItem from '../components/CreateItem';
+import PleaseSignIn from '../components/PleaseSignIn';
+
+const Sell = props => (
+ <div>
+ <PleaseSignIn>
+ <CreateItem />
+ </PleaseSignIn>
+ </div>
+);
+
+export default Sell;
diff --git a/stepped-solutions/35/backend/src/index.js b/stepped-solutions/35/backend/src/index.js
new file mode 100755
index 0000000..804d6d6
--- /dev/null
+++ b/stepped-solutions/35/backend/src/index.js
@@ -0,0 +1,46 @@
+const cookieParser = require('cookie-parser');
+const jwt = require('jsonwebtoken');
+
+require('dotenv').config({ path: 'variables.env' });
+const createServer = require('./createServer');
+const db = require('./db');
+
+const server = createServer();
+
+server.express.use(cookieParser());
+
+// decode the JWT so we can get the user Id on each request
+server.express.use((req, res, next) => {
+ const { token } = req.cookies;
+ if (token) {
+ const { userId } = jwt.verify(token, process.env.APP_SECRET);
+ // put the userId onto the req for future requests to access
+ req.userId = userId;
+ }
+ next();
+});
+
+// 2. Create a middleware that populates the user on each request
+
+server.express.use(async (req, res, next) => {
+ // if they aren't logged in, skip this
+ if (!req.userId) return next();
+ const user = await db.query.user(
+ { where: { id: req.userId } },
+ '{ id, permissions, email, name }'
+ );
+ req.user = user;
+ next();
+});
+
+server.start(
+ {
+ cors: {
+ credentials: true,
+ origin: process.env.FRONTEND_URL,
+ },
+ },
+ deets => {
+ console.log(`Server is now running on port http://localhost:${deets.port}`);
+ }
+);
diff --git a/stepped-solutions/35/backend/src/resolvers/Query.js b/stepped-solutions/35/backend/src/resolvers/Query.js
new file mode 100755
index 0000000..8af7b6c
--- /dev/null
+++ b/stepped-solutions/35/backend/src/resolvers/Query.js
@@ -0,0 +1,34 @@
+const { forwardTo } = require('prisma-binding');
+const { hasPermission } = require('../utils');
+
+const Query = {
+ items: forwardTo('db'),
+ item: forwardTo('db'),
+ itemsConnection: forwardTo('db'),
+ me(parent, args, ctx, info) {
+ // check if there is a current user ID
+ if (!ctx.request.userId) {
+ return null;
+ }
+ return ctx.db.query.user(
+ {
+ where: { id: ctx.request.userId },
+ },
+ info
+ );
+ },
+ async users(parent, args, ctx, info) {
+ // 1. Check if they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in!');
+ }
+ console.log(ctx.request.userId);
+ // 2. Check if the user has the permissions to query all the users
+ hasPermission(ctx.request.user, ['ADMIN', 'PERMISSIONUPDATE']);
+
+ // 2. if they do, query all the users!
+ return ctx.db.query.users({}, info);
+ },
+};
+
+module.exports = Query;
diff --git a/stepped-solutions/35/backend/src/schema.graphql b/stepped-solutions/35/backend/src/schema.graphql
new file mode 100755
index 0000000..323b1dc
--- /dev/null
+++ b/stepped-solutions/35/backend/src/schema.graphql
@@ -0,0 +1,31 @@
+# import * from './generated/prisma.graphql'
+
+type SuccessMessage {
+ message: String
+}
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+ signin(email: String!, password: String!): User!
+ signout: SuccessMessage
+ requestReset(email: String!): SuccessMessage
+ resetPassword(resetToken: String!, password: String!, confirmPassword: String!): User!
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+ users: [User]!
+}
+
+type User{
+ id: ID!
+ name: String!
+ email: String!
+ permissions: [Permission!]!
+}
diff --git a/stepped-solutions/35/frontend/components/Permissions.js b/stepped-solutions/35/frontend/components/Permissions.js
new file mode 100755
index 0000000..ca42ef6
--- /dev/null
+++ b/stepped-solutions/35/frontend/components/Permissions.js
@@ -0,0 +1,73 @@
+import { Query } from 'react-apollo';
+import Error from './ErrorMessage';
+import gql from 'graphql-tag';
+import Table from './styles/Table';
+import SickButton from './styles/SickButton';
+
+const possiblePermissions = [
+ 'ADMIN',
+ 'USER',
+ 'ITEMCREATE',
+ 'ITEMUPDATE',
+ 'ITEMDELETE',
+ 'PERMISSIONUPDATE',
+];
+
+const ALL_USERS_QUERY = gql`
+ query {
+ users {
+ id
+ name
+ email
+ permissions
+ }
+ }
+`;
+
+const Permissions = props => (
+ <Query query={ALL_USERS_QUERY}>
+ {({ data, loading, error }) => (
+ <div>
+ <Error error={error} />
+ <div>
+ <h2>Manage Permissions</h2>
+ <Table>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Email</th>
+ {possiblePermissions.map(permission => <th>{permission}</th>)}
+ <th>👇🏻</th>
+ </tr>
+ </thead>
+ <tbody>{data.users.map(user => <User user={user} />)}</tbody>
+ </Table>
+ </div>
+ </div>
+ )}
+ </Query>
+);
+
+class User extends React.Component {
+ render() {
+ const user = this.props.user;
+ return (
+ <tr>
+ <td>{user.name}</td>
+ <td>{user.email}</td>
+ {possiblePermissions.map(permission => (
+ <td>
+ <label htmlFor={`${user.id}-permission-${permission}`}>
+ <input type="checkbox" />
+ </label>
+ </td>
+ ))}
+ <td>
+ <SickButton>Update</SickButton>
+ </td>
+ </tr>
+ );
+ }
+}
+
+export default Permissions;
diff --git a/stepped-solutions/35/frontend/pages/permissions.js b/stepped-solutions/35/frontend/pages/permissions.js
new file mode 100755
index 0000000..de58c51
--- /dev/null
+++ b/stepped-solutions/35/frontend/pages/permissions.js
@@ -0,0 +1,12 @@
+import PleaseSignIn from '../components/PleaseSignIn';
+import Permissions from '../components/Permissions';
+
+const PermissionsPage = props => (
+ <div>
+ <PleaseSignIn>
+ <Permissions />
+ </PleaseSignIn>
+ </div>
+);
+
+export default PermissionsPage;
diff --git a/stepped-solutions/36/frontend/components/Permissions.js b/stepped-solutions/36/frontend/components/Permissions.js
new file mode 100755
index 0000000..10b59ab
--- /dev/null
+++ b/stepped-solutions/36/frontend/components/Permissions.js
@@ -0,0 +1,104 @@
+import { Query } from 'react-apollo';
+import Error from './ErrorMessage';
+import gql from 'graphql-tag';
+import Table from './styles/Table';
+import SickButton from './styles/SickButton';
+import PropTypes from 'prop-types';
+
+const possiblePermissions = [
+ 'ADMIN',
+ 'USER',
+ 'ITEMCREATE',
+ 'ITEMUPDATE',
+ 'ITEMDELETE',
+ 'PERMISSIONUPDATE',
+];
+
+const ALL_USERS_QUERY = gql`
+ query {
+ users {
+ id
+ name
+ email
+ permissions
+ }
+ }
+`;
+
+const Permissions = props => (
+ <Query query={ALL_USERS_QUERY}>
+ {({ data, loading, error }) => (
+ <div>
+ <Error error={error} />
+ <div>
+ <h2>Manage Permissions</h2>
+ <Table>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Email</th>
+ {possiblePermissions.map(permission => <th key={permission}>{permission}</th>)}
+ <th>👇🏻</th>
+ </tr>
+ </thead>
+ <tbody>{data.users.map(user => <UserPermissions user={user} key={user.id} />)}</tbody>
+ </Table>
+ </div>
+ </div>
+ )}
+ </Query>
+);
+
+class UserPermissions extends React.Component {
+ static propTypes = {
+ user: PropTypes.shape({
+ name: PropTypes.string,
+ email: PropTypes.string,
+ id: PropTypes.string,
+ permissions: PropTypes.array,
+ }).isRequired,
+ };
+ state = {
+ permissions: this.props.user.permissions,
+ };
+ handlePermissionChange = e => {
+ const checkbox = e.target;
+ // take a copy of the current permissions
+ let updatedPermissions = [...this.state.permissions];
+ // figure out if we need to remove or add this permission
+ if (checkbox.checked) {
+ // add it in!
+ updatedPermissions.push(checkbox.value);
+ } else {
+ updatedPermissions = updatedPermissions.filter(permission => permission !== checkbox.value);
+ }
+ this.setState({ permissions: updatedPermissions });
+ console.log(updatedPermissions);
+ };
+ render() {
+ const user = this.props.user;
+ return (
+ <tr>
+ <td>{user.name}</td>
+ <td>{user.email}</td>
+ {possiblePermissions.map(permission => (
+ <td key={permission}>
+ <label htmlFor={`${user.id}-permission-${permission}`}>
+ <input
+ type="checkbox"
+ checked={this.state.permissions.includes(permission)}
+ value={permission}
+ onChange={this.handlePermissionChange}
+ />
+ </label>
+ </td>
+ ))}
+ <td>
+ <SickButton>Update</SickButton>
+ </td>
+ </tr>
+ );
+ }
+}
+
+export default Permissions;
diff --git a/stepped-solutions/36/frontend/components/User.js b/stepped-solutions/36/frontend/components/User.js
new file mode 100755
index 0000000..a33649b
--- /dev/null
+++ b/stepped-solutions/36/frontend/components/User.js
@@ -0,0 +1,27 @@
+import { Query } from 'react-apollo';
+import gql from 'graphql-tag';
+import PropTypes from 'prop-types';
+
+const CURRENT_USER_QUERY = gql`
+ query {
+ me {
+ id
+ email
+ name
+ permissions
+ }
+ }
+`;
+
+const User = props => (
+ <Query {...props} query={CURRENT_USER_QUERY}>
+ {payload => console.log(payload) || props.children(payload)}
+ </Query>
+);
+
+User.propTypes = {
+ children: PropTypes.func.isRequired,
+};
+
+export default User;
+export { CURRENT_USER_QUERY };
diff --git a/stepped-solutions/37/backend/src/resolvers/Mutation.js b/stepped-solutions/37/backend/src/resolvers/Mutation.js
new file mode 100755
index 0000000..f2ecc16
--- /dev/null
+++ b/stepped-solutions/37/backend/src/resolvers/Mutation.js
@@ -0,0 +1,207 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+const { randomBytes } = require('crypto');
+const { promisify } = require('util');
+const { transport, makeANiceEmail } = require('../mail');
+const { hasPermission } = require('../utils');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in to do that!');
+ }
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ // This is how to create a relationship between the Item and the User
+ user: {
+ connect: {
+ id: ctx.request.userId,
+ },
+ },
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title}`);
+ // 2. Check if they own that item, or have the permissions
+ // TODO
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+ signout(parent, args, ctx, info) {
+ ctx.response.clearCookie('token');
+ return { message: 'Goodbye!' };
+ },
+ async requestReset(parent, args, ctx, info) {
+ // 1. Check if this is a real user
+ const user = await ctx.db.query.user({ where: { email: args.email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${args.email}`);
+ }
+ // 2. Set a reset token and expiry on that user
+ const randomBytesPromiseified = promisify(randomBytes);
+ const resetToken = (await randomBytesPromiseified(20)).toString('hex');
+ const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now
+ const res = await ctx.db.mutation.updateUser({
+ where: { email: args.email },
+ data: { resetToken, resetTokenExpiry },
+ });
+ // 3. Email them that reset token
+ const mailRes = await transport.sendMail({
+ from: 'wes@wesbos.com',
+ to: user.email,
+ subject: 'Your Password Reset Token',
+ html: makeANiceEmail(`Your Password Reset Token is here!
+ \n\n
+ <a href="${process.env
+ .FRONTEND_URL}/reset?resetToken=${resetToken}">Click Here to Reset</a>`),
+ });
+
+ // 4. Return the message
+ return { message: 'Thanks!' };
+ },
+ async resetPassword(parent, args, ctx, info) {
+ // 1. check if the passwords match
+ if (args.password !== args.confirmPassword) {
+ throw new Error("Yo Passwords don't match!");
+ }
+ // 2. check if its a legit reset token
+ // 3. Check if its expired
+ const [user] = await ctx.db.query.users({
+ where: {
+ resetToken: args.resetToken,
+ resetTokenExpiry_gte: Date.now() - 3600000,
+ },
+ });
+ if (!user) {
+ throw new Error('This token is either invalid or expired!');
+ }
+ // 4. Hash their new password
+ const password = await bcrypt.hash(args.password, 10);
+ // 5. Save the new password to the user and remove old resetToken fields
+ const updatedUser = await ctx.db.mutation.updateUser({
+ where: { email: user.email },
+ data: {
+ password,
+ resetToken: null,
+ resetTokenExpiry: null,
+ },
+ });
+ // 6. Generate JWT
+ const token = jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET);
+ // 7. Set the JWT cookie
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 8. return the new user
+ return updatedUser;
+ },
+ async updatePermissions(parent, args, ctx, info) {
+ // 1. Check if they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in!');
+ }
+ // 2. Query the current user
+ const currentUser = await ctx.db.query.user(
+ {
+ where: {
+ id: ctx.request.userId,
+ },
+ },
+ info
+ );
+ // 3. Check if they have permissions to do this
+ hasPermission(currentUser, ['ADMIN', 'PERMISSIONUPDATE']);
+ // 4. Update the permissions
+ return ctx.db.mutation.updateUser(
+ {
+ data: {
+ permissions: {
+ set: args.permissions,
+ },
+ },
+ where: {
+ id: args.userId,
+ },
+ },
+ info
+ );
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/37/backend/src/schema.graphql b/stepped-solutions/37/backend/src/schema.graphql
new file mode 100755
index 0000000..c59d53a
--- /dev/null
+++ b/stepped-solutions/37/backend/src/schema.graphql
@@ -0,0 +1,32 @@
+# import * from './generated/prisma.graphql'
+
+type SuccessMessage {
+ message: String
+}
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+ signin(email: String!, password: String!): User!
+ signout: SuccessMessage
+ requestReset(email: String!): SuccessMessage
+ resetPassword(resetToken: String!, password: String!, confirmPassword: String!): User!
+ updatePermissions(permissions: [Permission], userId: ID!): User
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+ users: [User]!
+}
+
+type User{
+ id: ID!
+ name: String!
+ email: String!
+ permissions: [Permission!]!
+}
diff --git a/stepped-solutions/37/frontend/components/Permissions.js b/stepped-solutions/37/frontend/components/Permissions.js
new file mode 100755
index 0000000..4b08c39
--- /dev/null
+++ b/stepped-solutions/37/frontend/components/Permissions.js
@@ -0,0 +1,131 @@
+import { Query, Mutation } from 'react-apollo';
+import Error from './ErrorMessage';
+import gql from 'graphql-tag';
+import Table from './styles/Table';
+import SickButton from './styles/SickButton';
+import PropTypes from 'prop-types';
+
+const possiblePermissions = [
+ 'ADMIN',
+ 'USER',
+ 'ITEMCREATE',
+ 'ITEMUPDATE',
+ 'ITEMDELETE',
+ 'PERMISSIONUPDATE',
+];
+
+const UPDATE_PERMISSIONS_MUTATION = gql`
+ mutation updatePermissions($permissions: [Permission], $userId: ID!) {
+ updatePermissions(permissions: $permissions, userId: $userId) {
+ id
+ permissions
+ name
+ email
+ }
+ }
+`;
+
+const ALL_USERS_QUERY = gql`
+ query {
+ users {
+ id
+ name
+ email
+ permissions
+ }
+ }
+`;
+
+const Permissions = props => (
+ <Query query={ALL_USERS_QUERY}>
+ {({ data, loading, error }) => (
+ <div>
+ <Error error={error} />
+ <div>
+ <h2>Manage Permissions</h2>
+ <Table>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Email</th>
+ {possiblePermissions.map(permission => <th key={permission}>{permission}</th>)}
+ <th>👇🏻</th>
+ </tr>
+ </thead>
+ <tbody>{data.users.map(user => <UserPermissions user={user} key={user.id} />)}</tbody>
+ </Table>
+ </div>
+ </div>
+ )}
+ </Query>
+);
+
+class UserPermissions extends React.Component {
+ static propTypes = {
+ user: PropTypes.shape({
+ name: PropTypes.string,
+ email: PropTypes.string,
+ id: PropTypes.string,
+ permissions: PropTypes.array,
+ }).isRequired,
+ };
+ state = {
+ permissions: this.props.user.permissions,
+ };
+ handlePermissionChange = (e) => {
+ const checkbox = e.target;
+ // take a copy of the current permissions
+ let updatedPermissions = [...this.state.permissions];
+ // figure out if we need to remove or add this permission
+ if (checkbox.checked) {
+ // add it in!
+ updatedPermissions.push(checkbox.value);
+ } else {
+ updatedPermissions = updatedPermissions.filter(permission => permission !== checkbox.value);
+ }
+ this.setState({ permissions: updatedPermissions });
+ };
+ render() {
+ const user = this.props.user;
+ return (
+ <Mutation
+ mutation={UPDATE_PERMISSIONS_MUTATION}
+ variables={{
+ permissions: this.state.permissions,
+ userId: this.props.user.id,
+ }}
+ >
+ {(updatePermissions, { loading, error }) => (
+ <>
+ {error && <tr><td colspan="8"><Error error={error} /></td></tr>}
+ < tr >
+ <td>{user.name}</td>
+ <td>{user.email}</td>
+ {possiblePermissions.map(permission => (
+ <td key={permission}>
+ <label htmlFor={`${user.id}-permission-${permission}`}>
+ <input
+ id={`${user.id}-permission-${permission}`}
+ type="checkbox"
+ checked={this.state.permissions.includes(permission)}
+ value={permission}
+ onChange={this.handlePermissionChange}
+ />
+ </label>
+ </td>
+ ))}
+ <td>
+ <SickButton type="button" disabled={loading} onClick={updatePermissions}>
+ Updat{loading ? 'ing' : 'e'}
+ </SickButton>
+ </td>
+ </tr>
+ </>
+ )
+ }
+ </Mutation>
+ );
+ }
+}
+
+export default Permissions;
diff --git a/stepped-solutions/37/frontend/components/styles/Table.js b/stepped-solutions/37/frontend/components/styles/Table.js
new file mode 100755
index 0000000..b2cd6c4
--- /dev/null
+++ b/stepped-solutions/37/frontend/components/styles/Table.js
@@ -0,0 +1,35 @@
+import styled from 'styled-components';
+
+const Table = styled.table`
+ border-spacing: 0;
+ width: 100%;
+ border: 1px solid ${props => props.theme.offWhite};
+ thead {
+ font-size: 10px;
+ }
+ td,
+ th {
+ border-bottom: 1px solid ${props => props.theme.offWhite};
+ border-right: 1px solid ${props => props.theme.offWhite};
+ padding: 5px;
+ position: relative;
+ &:last-child {
+ border-right: none;
+ width: 150px;
+ button {
+ width: 100%;
+ }
+ }
+ label {
+ padding: 10px 5px;
+ display: block;
+ }
+ }
+ tr {
+ &:hover {
+ background: ${props => props.theme.offWhite};
+ }
+ }
+`;
+
+export default Table;
diff --git a/stepped-solutions/38/backend/src/resolvers/Mutation.js b/stepped-solutions/38/backend/src/resolvers/Mutation.js
new file mode 100755
index 0000000..b48be39
--- /dev/null
+++ b/stepped-solutions/38/backend/src/resolvers/Mutation.js
@@ -0,0 +1,215 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+const { randomBytes } = require('crypto');
+const { promisify } = require('util');
+const { transport, makeANiceEmail } = require('../mail');
+const { hasPermission } = require('../utils');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in to do that!');
+ }
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ // This is how to create a relationship between the Item and the User
+ user: {
+ connect: {
+ id: ctx.request.userId,
+ },
+ },
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title user { id }}`);
+ // 2. Check if they own that item, or have the permissions
+ const ownsItem = item.user.id === ctx.request.userId;
+ const hasPermissions = ctx.request.user.permissions.some(permission =>
+ ['ADMIN', 'ITEMDELETE'].includes(permission)
+ );
+
+ if (!ownsItem && hasPermissions) {
+ throw new Error("You don't have permission to do that!");
+ }
+
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+ signout(parent, args, ctx, info) {
+ ctx.response.clearCookie('token');
+ return { message: 'Goodbye!' };
+ },
+ async requestReset(parent, args, ctx, info) {
+ // 1. Check if this is a real user
+ const user = await ctx.db.query.user({ where: { email: args.email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${args.email}`);
+ }
+ // 2. Set a reset token and expiry on that user
+ const randomBytesPromiseified = promisify(randomBytes);
+ const resetToken = (await randomBytesPromiseified(20)).toString('hex');
+ const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now
+ const res = await ctx.db.mutation.updateUser({
+ where: { email: args.email },
+ data: { resetToken, resetTokenExpiry },
+ });
+ // 3. Email them that reset token
+ const mailRes = await transport.sendMail({
+ from: 'wes@wesbos.com',
+ to: user.email,
+ subject: 'Your Password Reset Token',
+ html: makeANiceEmail(`Your Password Reset Token is here!
+ \n\n
+ <a href="${process.env
+ .FRONTEND_URL}/reset?resetToken=${resetToken}">Click Here to Reset</a>`),
+ });
+
+ // 4. Return the message
+ return { message: 'Thanks!' };
+ },
+ async resetPassword(parent, args, ctx, info) {
+ // 1. check if the passwords match
+ if (args.password !== args.confirmPassword) {
+ throw new Error("Yo Passwords don't match!");
+ }
+ // 2. check if its a legit reset token
+ // 3. Check if its expired
+ const [user] = await ctx.db.query.users({
+ where: {
+ resetToken: args.resetToken,
+ resetTokenExpiry_gte: Date.now() - 3600000,
+ },
+ });
+ if (!user) {
+ throw new Error('This token is either invalid or expired!');
+ }
+ // 4. Hash their new password
+ const password = await bcrypt.hash(args.password, 10);
+ // 5. Save the new password to the user and remove old resetToken fields
+ const updatedUser = await ctx.db.mutation.updateUser({
+ where: { email: user.email },
+ data: {
+ password,
+ resetToken: null,
+ resetTokenExpiry: null,
+ },
+ });
+ // 6. Generate JWT
+ const token = jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET);
+ // 7. Set the JWT cookie
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 8. return the new user
+ return updatedUser;
+ },
+ async updatePermissions(parent, args, ctx, info) {
+ // 1. Check if they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in!');
+ }
+ // 2. Query the current user
+ const currentUser = await ctx.db.query.user(
+ {
+ where: {
+ id: ctx.request.userId,
+ },
+ },
+ info
+ );
+ // 3. Check if they have permissions to do this
+ hasPermission(currentUser, ['ADMIN', 'PERMISSIONUPDATE']);
+ // 4. Update the permissions
+ return ctx.db.mutation.updateUser(
+ {
+ data: {
+ permissions: {
+ set: args.permissions,
+ },
+ },
+ where: {
+ id: args.userId,
+ },
+ },
+ info
+ );
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/38/frontend/components/DeleteItem.js b/stepped-solutions/38/frontend/components/DeleteItem.js
new file mode 100755
index 0000000..e5e4752
--- /dev/null
+++ b/stepped-solutions/38/frontend/components/DeleteItem.js
@@ -0,0 +1,50 @@
+import React, { Component } from 'react';
+import { Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import { ALL_ITEMS_QUERY } from './Items';
+
+const DELETE_ITEM_MUTATION = gql`
+ mutation DELETE_ITEM_MUTATION($id: ID!) {
+ deleteItem(id: $id) {
+ id
+ }
+ }
+`;
+
+class DeleteItem extends Component {
+ update = (cache, payload) => {
+ // manually update the cache on the client, so it matches the server
+ // 1. Read the cache for the items we want
+ const data = cache.readQuery({ query: ALL_ITEMS_QUERY });
+ console.log(data, payload);
+ // 2. Filter the deleted itemout of the page
+ data.items = data.items.filter(item => item.id !== payload.data.deleteItem.id);
+ // 3. Put the items back!
+ cache.writeQuery({ query: ALL_ITEMS_QUERY, data });
+ };
+ render() {
+ return (
+ <Mutation
+ mutation={DELETE_ITEM_MUTATION}
+ variables={{ id: this.props.id }}
+ update={this.update}
+ >
+ {(deleteItem, { error }) => (
+ <button
+ onClick={() => {
+ if (confirm('Are you sure you want to delete this item?')) {
+ deleteItem().catch(err => {
+ alert(err.message);
+ });
+ }
+ }}
+ >
+ {this.props.children}
+ </button>
+ )}
+ </Mutation>
+ );
+ }
+}
+
+export default DeleteItem;
diff --git a/stepped-solutions/40/frontend/components/Cart.js b/stepped-solutions/40/frontend/components/Cart.js
new file mode 100755
index 0000000..a273b39
--- /dev/null
+++ b/stepped-solutions/40/frontend/components/Cart.js
@@ -0,0 +1,47 @@
+import React from 'react';
+import { Query, Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import CartStyles from './styles/CartStyles';
+import Supreme from './styles/Supreme';
+import CloseButton from './styles/CloseButton';
+import SickButton from './styles/SickButton';
+
+const LOCAL_STATE_QUERY = gql`
+ query {
+ cartOpen @client
+ }
+`;
+
+const TOGGLE_CART_MUTATION = gql`
+ mutation {
+ toggleCart @client
+ }
+`;
+
+const Cart = () => (
+ <Mutation mutation={TOGGLE_CART_MUTATION}>
+ {toggleCart => (
+ <Query query={LOCAL_STATE_QUERY}>
+ {({ data }) => (
+ <CartStyles open={data.cartOpen}>
+ <header>
+ <CloseButton onClick={toggleCart} title="close">
+ &times;
+ </CloseButton>
+ <Supreme>Your Cart</Supreme>
+ <p>You Have __ Items in your cart.</p>
+ </header>
+
+ <footer>
+ <p>$10.10</p>
+ <SickButton>Checkout</SickButton>
+ </footer>
+ </CartStyles>
+ )}
+ </Query>
+ )}
+ </Mutation>
+);
+
+export default Cart;
+export { LOCAL_STATE_QUERY, TOGGLE_CART_MUTATION };
diff --git a/stepped-solutions/40/frontend/components/Header.js b/stepped-solutions/40/frontend/components/Header.js
new file mode 100755
index 0000000..5910309
--- /dev/null
+++ b/stepped-solutions/40/frontend/components/Header.js
@@ -0,0 +1,74 @@
+import Link from 'next/link';
+import styled from 'styled-components';
+import NProgress from 'nprogress';
+import Router from 'next/router';
+import Nav from './Nav';
+import Cart from './Cart';
+
+Router.onRouteChangeStart = () => {
+ NProgress.start();
+};
+Router.onRouteChangeComplete = () => {
+ NProgress.done();
+};
+
+Router.onRouteChangeError = () => {
+ NProgress.done();
+};
+
+const Logo = styled.h1`
+ font-size: 4rem;
+ margin-left: 2rem;
+ position: relative;
+ z-index: 2;
+ transform: skew(-7deg);
+ a {
+ padding: 0.5rem 1rem;
+ background: ${props => props.theme.red};
+ color: white;
+ text-transform: uppercase;
+ text-decoration: none;
+ }
+ @media (max-width: 1300px) {
+ margin: 0;
+ text-align: center;
+ }
+`;
+
+const StyledHeader = styled.header`
+ .bar {
+ border-bottom: 10px solid ${props => props.theme.black};
+ display: grid;
+ grid-template-columns: auto 1fr;
+ justify-content: space-between;
+ align-items: stretch;
+ @media (max-width: 1300px) {
+ grid-template-columns: 1fr;
+ justify-content: center;
+ }
+ }
+ .sub-bar {
+ display: grid;
+ grid-template-columns: 1fr auto;
+ border-bottom: 1px solid ${props => props.theme.lightgrey};
+ }
+`;
+
+const Header = () => (
+ <StyledHeader>
+ <div className="bar">
+ <Logo>
+ <Link href="/">
+ <a>Sick Fits</a>
+ </Link>
+ </Logo>
+ <Nav />
+ </div>
+ <div className="sub-bar">
+ <p>Search</p>
+ </div>
+ <Cart />
+ </StyledHeader>
+);
+
+export default Header;
diff --git a/stepped-solutions/40/frontend/components/Nav.js b/stepped-solutions/40/frontend/components/Nav.js
new file mode 100755
index 0000000..aebbcb2
--- /dev/null
+++ b/stepped-solutions/40/frontend/components/Nav.js
@@ -0,0 +1,45 @@
+import Link from 'next/link';
+import { Mutation } from 'react-apollo';
+import { TOGGLE_CART_MUTATION } from './Cart';
+import NavStyles from './styles/NavStyles';
+import User from './User';
+import Signout from './Signout';
+
+const Nav = () => (
+ <User>
+ {({ data: { me } }) => (
+ <NavStyles>
+ <Link href="/items">
+ <a>Shop</a>
+ </Link>
+ {me && (
+ <>
+ <Link href="/sell">
+ <a>Sell</a>
+ </Link>
+ <Link href="/orders">
+ <a>Orders</a>
+ </Link>
+ <Link href="/me">
+ <a>Account</a>
+ </Link>
+ <Signout />
+ <Mutation mutation={TOGGLE_CART_MUTATION}>
+ {(toggleCart) => (
+ <button onClick={toggleCart}>My Cart</button>
+ )}
+ </Mutation>
+ </>
+ )}
+ {!me && (
+ <Link href="/signup">
+ <a>Sign In</a>
+ </Link>
+
+ )}
+ </NavStyles>
+ )}
+ </User>
+);
+
+export default Nav;
diff --git a/stepped-solutions/40/frontend/lib/withData.js b/stepped-solutions/40/frontend/lib/withData.js
new file mode 100755
index 0000000..33908d6
--- /dev/null
+++ b/stepped-solutions/40/frontend/lib/withData.js
@@ -0,0 +1,42 @@
+import withApollo from 'next-with-apollo';
+import ApolloClient from 'apollo-boost';
+import { endpoint } from '../config';
+import { LOCAL_STATE_QUERY } from '../components/Cart';
+
+function createClient({ headers }) {
+ return new ApolloClient({
+ uri: process.env.NODE_ENV === 'development' ? endpoint : endpoint,
+ request: operation => {
+ operation.setContext({
+ fetchOptions: {
+ credentials: 'include',
+ },
+ headers,
+ });
+ },
+ // local data
+ clientState: {
+ resolvers: {
+ Mutation: {
+ toggleCart(_, variables, { cache }) {
+ // read the cartOpen value from the cache
+ const { cartOpen } = cache.readQuery({
+ query: LOCAL_STATE_QUERY,
+ });
+ // Write the cart State to the opposite
+ const data = {
+ data: { cartOpen: !cartOpen },
+ };
+ cache.writeData(data);
+ return data;
+ },
+ },
+ },
+ defaults: {
+ cartOpen: true,
+ },
+ },
+ });
+}
+
+export default withApollo(createClient);
diff --git a/stepped-solutions/41/backend/datamodel.graphql b/stepped-solutions/41/backend/datamodel.graphql
new file mode 100755
index 0000000..9d7a8b4
--- /dev/null
+++ b/stepped-solutions/41/backend/datamodel.graphql
@@ -0,0 +1,37 @@
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type User {
+ id: ID! @unique
+ name: String!
+ email: String! @unique
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission]
+ cart: [CartItem!]!
+}
+
+type Item {
+ id: ID! @unique
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: User!
+}
+
+
+type CartItem {
+ id: ID! @unique
+ quantity: Int! @default(value: 1)
+ item: Item! # relationship to Item
+ user: User! # relationship to User
+}
diff --git a/stepped-solutions/41/backend/src/generated/prisma.graphql b/stepped-solutions/41/backend/src/generated/prisma.graphql
new file mode 100755
index 0000000..c9a523f
--- /dev/null
+++ b/stepped-solutions/41/backend/src/generated/prisma.graphql
@@ -0,0 +1,1141 @@
+# source: https://us1.prisma.sh/wesbos/siccccccccck-fits/dev
+# timestamp: Thu Aug 16 2018 12:51:33 GMT-0400 (EDT)
+
+type AggregateCartItem {
+ count: Int!
+}
+
+type AggregateItem {
+ count: Int!
+}
+
+type AggregateUser {
+ count: Int!
+}
+
+type BatchPayload {
+ """The number of nodes that have been affected by the Batch operation."""
+ count: Long!
+}
+
+type CartItem implements Node {
+ id: ID!
+ quantity: Int!
+ item(where: ItemWhereInput): Item!
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type CartItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [CartItemEdge]!
+ aggregate: AggregateCartItem!
+}
+
+input CartItemCreateInput {
+ quantity: Int
+ item: ItemCreateOneInput!
+ user: UserCreateOneWithoutCartInput!
+}
+
+input CartItemCreateManyWithoutUserInput {
+ create: [CartItemCreateWithoutUserInput!]
+ connect: [CartItemWhereUniqueInput!]
+}
+
+input CartItemCreateWithoutUserInput {
+ quantity: Int
+ item: ItemCreateOneInput!
+}
+
+"""An edge in a connection."""
+type CartItemEdge {
+ """The item at the end of the edge."""
+ node: CartItem!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum CartItemOrderByInput {
+ id_ASC
+ id_DESC
+ quantity_ASC
+ quantity_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type CartItemPreviousValues {
+ id: ID!
+ quantity: Int!
+}
+
+type CartItemSubscriptionPayload {
+ mutation: MutationType!
+ node: CartItem
+ updatedFields: [String!]
+ previousValues: CartItemPreviousValues
+}
+
+input CartItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [CartItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [CartItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [CartItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: CartItemWhereInput
+}
+
+input CartItemUpdateInput {
+ quantity: Int
+ item: ItemUpdateOneInput
+ user: UserUpdateOneWithoutCartInput
+}
+
+input CartItemUpdateManyWithoutUserInput {
+ create: [CartItemCreateWithoutUserInput!]
+ connect: [CartItemWhereUniqueInput!]
+ disconnect: [CartItemWhereUniqueInput!]
+ delete: [CartItemWhereUniqueInput!]
+ update: [CartItemUpdateWithWhereUniqueWithoutUserInput!]
+ upsert: [CartItemUpsertWithWhereUniqueWithoutUserInput!]
+}
+
+input CartItemUpdateWithoutUserDataInput {
+ quantity: Int
+ item: ItemUpdateOneInput
+}
+
+input CartItemUpdateWithWhereUniqueWithoutUserInput {
+ where: CartItemWhereUniqueInput!
+ data: CartItemUpdateWithoutUserDataInput!
+}
+
+input CartItemUpsertWithWhereUniqueWithoutUserInput {
+ where: CartItemWhereUniqueInput!
+ update: CartItemUpdateWithoutUserDataInput!
+ create: CartItemCreateWithoutUserInput!
+}
+
+input CartItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [CartItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [CartItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [CartItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ quantity: Int
+
+ """All values that are not equal to given value."""
+ quantity_not: Int
+
+ """All values that are contained in given list."""
+ quantity_in: [Int!]
+
+ """All values that are not contained in given list."""
+ quantity_not_in: [Int!]
+
+ """All values less than the given value."""
+ quantity_lt: Int
+
+ """All values less than or equal the given value."""
+ quantity_lte: Int
+
+ """All values greater than the given value."""
+ quantity_gt: Int
+
+ """All values greater than or equal the given value."""
+ quantity_gte: Int
+ item: ItemWhereInput
+ user: UserWhereInput
+}
+
+input CartItemWhereUniqueInput {
+ id: ID
+}
+
+type Item implements Node {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type ItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [ItemEdge]!
+ aggregate: AggregateItem!
+}
+
+input ItemCreateInput {
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: UserCreateOneInput!
+}
+
+input ItemCreateOneInput {
+ create: ItemCreateInput
+ connect: ItemWhereUniqueInput
+}
+
+"""An edge in a connection."""
+type ItemEdge {
+ """The item at the end of the edge."""
+ node: Item!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum ItemOrderByInput {
+ id_ASC
+ id_DESC
+ title_ASC
+ title_DESC
+ description_ASC
+ description_DESC
+ image_ASC
+ image_DESC
+ largeImage_ASC
+ largeImage_DESC
+ price_ASC
+ price_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type ItemPreviousValues {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+}
+
+type ItemSubscriptionPayload {
+ mutation: MutationType!
+ node: Item
+ updatedFields: [String!]
+ previousValues: ItemPreviousValues
+}
+
+input ItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: ItemWhereInput
+}
+
+input ItemUpdateDataInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneInput
+}
+
+input ItemUpdateInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneInput
+}
+
+input ItemUpdateOneInput {
+ create: ItemCreateInput
+ connect: ItemWhereUniqueInput
+ delete: Boolean
+ update: ItemUpdateDataInput
+ upsert: ItemUpsertNestedInput
+}
+
+input ItemUpsertNestedInput {
+ update: ItemUpdateDataInput!
+ create: ItemCreateInput!
+}
+
+input ItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ title: String
+
+ """All values that are not equal to given value."""
+ title_not: String
+
+ """All values that are contained in given list."""
+ title_in: [String!]
+
+ """All values that are not contained in given list."""
+ title_not_in: [String!]
+
+ """All values less than the given value."""
+ title_lt: String
+
+ """All values less than or equal the given value."""
+ title_lte: String
+
+ """All values greater than the given value."""
+ title_gt: String
+
+ """All values greater than or equal the given value."""
+ title_gte: String
+
+ """All values containing the given string."""
+ title_contains: String
+
+ """All values not containing the given string."""
+ title_not_contains: String
+
+ """All values starting with the given string."""
+ title_starts_with: String
+
+ """All values not starting with the given string."""
+ title_not_starts_with: String
+
+ """All values ending with the given string."""
+ title_ends_with: String
+
+ """All values not ending with the given string."""
+ title_not_ends_with: String
+ description: String
+
+ """All values that are not equal to given value."""
+ description_not: String
+
+ """All values that are contained in given list."""
+ description_in: [String!]
+
+ """All values that are not contained in given list."""
+ description_not_in: [String!]
+
+ """All values less than the given value."""
+ description_lt: String
+
+ """All values less than or equal the given value."""
+ description_lte: String
+
+ """All values greater than the given value."""
+ description_gt: String
+
+ """All values greater than or equal the given value."""
+ description_gte: String
+
+ """All values containing the given string."""
+ description_contains: String
+
+ """All values not containing the given string."""
+ description_not_contains: String
+
+ """All values starting with the given string."""
+ description_starts_with: String
+
+ """All values not starting with the given string."""
+ description_not_starts_with: String
+
+ """All values ending with the given string."""
+ description_ends_with: String
+
+ """All values not ending with the given string."""
+ description_not_ends_with: String
+ image: String
+
+ """All values that are not equal to given value."""
+ image_not: String
+
+ """All values that are contained in given list."""
+ image_in: [String!]
+
+ """All values that are not contained in given list."""
+ image_not_in: [String!]
+
+ """All values less than the given value."""
+ image_lt: String
+
+ """All values less than or equal the given value."""
+ image_lte: String
+
+ """All values greater than the given value."""
+ image_gt: String
+
+ """All values greater than or equal the given value."""
+ image_gte: String
+
+ """All values containing the given string."""
+ image_contains: String
+
+ """All values not containing the given string."""
+ image_not_contains: String
+
+ """All values starting with the given string."""
+ image_starts_with: String
+
+ """All values not starting with the given string."""
+ image_not_starts_with: String
+
+ """All values ending with the given string."""
+ image_ends_with: String
+
+ """All values not ending with the given string."""
+ image_not_ends_with: String
+ largeImage: String
+
+ """All values that are not equal to given value."""
+ largeImage_not: String
+
+ """All values that are contained in given list."""
+ largeImage_in: [String!]
+
+ """All values that are not contained in given list."""
+ largeImage_not_in: [String!]
+
+ """All values less than the given value."""
+ largeImage_lt: String
+
+ """All values less than or equal the given value."""
+ largeImage_lte: String
+
+ """All values greater than the given value."""
+ largeImage_gt: String
+
+ """All values greater than or equal the given value."""
+ largeImage_gte: String
+
+ """All values containing the given string."""
+ largeImage_contains: String
+
+ """All values not containing the given string."""
+ largeImage_not_contains: String
+
+ """All values starting with the given string."""
+ largeImage_starts_with: String
+
+ """All values not starting with the given string."""
+ largeImage_not_starts_with: String
+
+ """All values ending with the given string."""
+ largeImage_ends_with: String
+
+ """All values not ending with the given string."""
+ largeImage_not_ends_with: String
+ price: Int
+
+ """All values that are not equal to given value."""
+ price_not: Int
+
+ """All values that are contained in given list."""
+ price_in: [Int!]
+
+ """All values that are not contained in given list."""
+ price_not_in: [Int!]
+
+ """All values less than the given value."""
+ price_lt: Int
+
+ """All values less than or equal the given value."""
+ price_lte: Int
+
+ """All values greater than the given value."""
+ price_gt: Int
+
+ """All values greater than or equal the given value."""
+ price_gte: Int
+ user: UserWhereInput
+}
+
+input ItemWhereUniqueInput {
+ id: ID
+}
+
+"""
+The `Long` scalar type represents non-fractional signed whole numeric values.
+Long can represent values between -(2^63) and 2^63 - 1.
+"""
+scalar Long
+
+type Mutation {
+ createCartItem(data: CartItemCreateInput!): CartItem!
+ createItem(data: ItemCreateInput!): Item!
+ createUser(data: UserCreateInput!): User!
+ updateCartItem(data: CartItemUpdateInput!, where: CartItemWhereUniqueInput!): CartItem
+ updateItem(data: ItemUpdateInput!, where: ItemWhereUniqueInput!): Item
+ updateUser(data: UserUpdateInput!, where: UserWhereUniqueInput!): User
+ deleteCartItem(where: CartItemWhereUniqueInput!): CartItem
+ deleteItem(where: ItemWhereUniqueInput!): Item
+ deleteUser(where: UserWhereUniqueInput!): User
+ upsertCartItem(where: CartItemWhereUniqueInput!, create: CartItemCreateInput!, update: CartItemUpdateInput!): CartItem!
+ upsertItem(where: ItemWhereUniqueInput!, create: ItemCreateInput!, update: ItemUpdateInput!): Item!
+ upsertUser(where: UserWhereUniqueInput!, create: UserCreateInput!, update: UserUpdateInput!): User!
+ updateManyCartItems(data: CartItemUpdateInput!, where: CartItemWhereInput): BatchPayload!
+ updateManyItems(data: ItemUpdateInput!, where: ItemWhereInput): BatchPayload!
+ updateManyUsers(data: UserUpdateInput!, where: UserWhereInput): BatchPayload!
+ deleteManyCartItems(where: CartItemWhereInput): BatchPayload!
+ deleteManyItems(where: ItemWhereInput): BatchPayload!
+ deleteManyUsers(where: UserWhereInput): BatchPayload!
+}
+
+enum MutationType {
+ CREATED
+ UPDATED
+ DELETED
+}
+
+"""An object with an ID"""
+interface Node {
+ """The id of the object."""
+ id: ID!
+}
+
+"""Information about pagination in a connection."""
+type PageInfo {
+ """When paginating forwards, are there more items?"""
+ hasNextPage: Boolean!
+
+ """When paginating backwards, are there more items?"""
+ hasPreviousPage: Boolean!
+
+ """When paginating backwards, the cursor to continue."""
+ startCursor: String
+
+ """When paginating forwards, the cursor to continue."""
+ endCursor: String
+}
+
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type Query {
+ cartItems(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [CartItem]!
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Item]!
+ users(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [User]!
+ cartItem(where: CartItemWhereUniqueInput!): CartItem
+ item(where: ItemWhereUniqueInput!): Item
+ user(where: UserWhereUniqueInput!): User
+ cartItemsConnection(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): CartItemConnection!
+ itemsConnection(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): ItemConnection!
+ usersConnection(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): UserConnection!
+
+ """Fetches an object given its ID"""
+ node(
+ """The ID of an object"""
+ id: ID!
+ ): Node
+}
+
+type Subscription {
+ cartItem(where: CartItemSubscriptionWhereInput): CartItemSubscriptionPayload
+ item(where: ItemSubscriptionWhereInput): ItemSubscriptionPayload
+ user(where: UserSubscriptionWhereInput): UserSubscriptionPayload
+}
+
+type User implements Node {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+ cart(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [CartItem!]
+}
+
+"""A connection to a list of items."""
+type UserConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [UserEdge]!
+ aggregate: AggregateUser!
+}
+
+input UserCreateInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+ cart: CartItemCreateManyWithoutUserInput
+}
+
+input UserCreateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreateOneWithoutCartInput {
+ create: UserCreateWithoutCartInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserCreateWithoutCartInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+}
+
+"""An edge in a connection."""
+type UserEdge {
+ """The item at the end of the edge."""
+ node: User!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum UserOrderByInput {
+ id_ASC
+ id_DESC
+ name_ASC
+ name_DESC
+ email_ASC
+ email_DESC
+ password_ASC
+ password_DESC
+ resetToken_ASC
+ resetToken_DESC
+ resetTokenExpiry_ASC
+ resetTokenExpiry_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type UserPreviousValues {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+}
+
+type UserSubscriptionPayload {
+ mutation: MutationType!
+ node: User
+ updatedFields: [String!]
+ previousValues: UserPreviousValues
+}
+
+input UserSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: UserWhereInput
+}
+
+input UserUpdateDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+ cart: CartItemUpdateManyWithoutUserInput
+}
+
+input UserUpdateInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+ cart: CartItemUpdateManyWithoutUserInput
+}
+
+input UserUpdateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+ delete: Boolean
+ update: UserUpdateDataInput
+ upsert: UserUpsertNestedInput
+}
+
+input UserUpdateOneWithoutCartInput {
+ create: UserCreateWithoutCartInput
+ connect: UserWhereUniqueInput
+ delete: Boolean
+ update: UserUpdateWithoutCartDataInput
+ upsert: UserUpsertWithoutCartInput
+}
+
+input UserUpdatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserUpdateWithoutCartDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+}
+
+input UserUpsertNestedInput {
+ update: UserUpdateDataInput!
+ create: UserCreateInput!
+}
+
+input UserUpsertWithoutCartInput {
+ update: UserUpdateWithoutCartDataInput!
+ create: UserCreateWithoutCartInput!
+}
+
+input UserWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ name: String
+
+ """All values that are not equal to given value."""
+ name_not: String
+
+ """All values that are contained in given list."""
+ name_in: [String!]
+
+ """All values that are not contained in given list."""
+ name_not_in: [String!]
+
+ """All values less than the given value."""
+ name_lt: String
+
+ """All values less than or equal the given value."""
+ name_lte: String
+
+ """All values greater than the given value."""
+ name_gt: String
+
+ """All values greater than or equal the given value."""
+ name_gte: String
+
+ """All values containing the given string."""
+ name_contains: String
+
+ """All values not containing the given string."""
+ name_not_contains: String
+
+ """All values starting with the given string."""
+ name_starts_with: String
+
+ """All values not starting with the given string."""
+ name_not_starts_with: String
+
+ """All values ending with the given string."""
+ name_ends_with: String
+
+ """All values not ending with the given string."""
+ name_not_ends_with: String
+ email: String
+
+ """All values that are not equal to given value."""
+ email_not: String
+
+ """All values that are contained in given list."""
+ email_in: [String!]
+
+ """All values that are not contained in given list."""
+ email_not_in: [String!]
+
+ """All values less than the given value."""
+ email_lt: String
+
+ """All values less than or equal the given value."""
+ email_lte: String
+
+ """All values greater than the given value."""
+ email_gt: String
+
+ """All values greater than or equal the given value."""
+ email_gte: String
+
+ """All values containing the given string."""
+ email_contains: String
+
+ """All values not containing the given string."""
+ email_not_contains: String
+
+ """All values starting with the given string."""
+ email_starts_with: String
+
+ """All values not starting with the given string."""
+ email_not_starts_with: String
+
+ """All values ending with the given string."""
+ email_ends_with: String
+
+ """All values not ending with the given string."""
+ email_not_ends_with: String
+ password: String
+
+ """All values that are not equal to given value."""
+ password_not: String
+
+ """All values that are contained in given list."""
+ password_in: [String!]
+
+ """All values that are not contained in given list."""
+ password_not_in: [String!]
+
+ """All values less than the given value."""
+ password_lt: String
+
+ """All values less than or equal the given value."""
+ password_lte: String
+
+ """All values greater than the given value."""
+ password_gt: String
+
+ """All values greater than or equal the given value."""
+ password_gte: String
+
+ """All values containing the given string."""
+ password_contains: String
+
+ """All values not containing the given string."""
+ password_not_contains: String
+
+ """All values starting with the given string."""
+ password_starts_with: String
+
+ """All values not starting with the given string."""
+ password_not_starts_with: String
+
+ """All values ending with the given string."""
+ password_ends_with: String
+
+ """All values not ending with the given string."""
+ password_not_ends_with: String
+ resetToken: String
+
+ """All values that are not equal to given value."""
+ resetToken_not: String
+
+ """All values that are contained in given list."""
+ resetToken_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetToken_not_in: [String!]
+
+ """All values less than the given value."""
+ resetToken_lt: String
+
+ """All values less than or equal the given value."""
+ resetToken_lte: String
+
+ """All values greater than the given value."""
+ resetToken_gt: String
+
+ """All values greater than or equal the given value."""
+ resetToken_gte: String
+
+ """All values containing the given string."""
+ resetToken_contains: String
+
+ """All values not containing the given string."""
+ resetToken_not_contains: String
+
+ """All values starting with the given string."""
+ resetToken_starts_with: String
+
+ """All values not starting with the given string."""
+ resetToken_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetToken_ends_with: String
+
+ """All values not ending with the given string."""
+ resetToken_not_ends_with: String
+ resetTokenExpiry: String
+
+ """All values that are not equal to given value."""
+ resetTokenExpiry_not: String
+
+ """All values that are contained in given list."""
+ resetTokenExpiry_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetTokenExpiry_not_in: [String!]
+
+ """All values less than the given value."""
+ resetTokenExpiry_lt: String
+
+ """All values less than or equal the given value."""
+ resetTokenExpiry_lte: String
+
+ """All values greater than the given value."""
+ resetTokenExpiry_gt: String
+
+ """All values greater than or equal the given value."""
+ resetTokenExpiry_gte: String
+
+ """All values containing the given string."""
+ resetTokenExpiry_contains: String
+
+ """All values not containing the given string."""
+ resetTokenExpiry_not_contains: String
+
+ """All values starting with the given string."""
+ resetTokenExpiry_starts_with: String
+
+ """All values not starting with the given string."""
+ resetTokenExpiry_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetTokenExpiry_ends_with: String
+
+ """All values not ending with the given string."""
+ resetTokenExpiry_not_ends_with: String
+ cart_every: CartItemWhereInput
+ cart_some: CartItemWhereInput
+ cart_none: CartItemWhereInput
+}
+
+input UserWhereUniqueInput {
+ id: ID
+ email: String
+}
diff --git a/stepped-solutions/41/backend/src/resolvers/Mutation.js b/stepped-solutions/41/backend/src/resolvers/Mutation.js
new file mode 100755
index 0000000..5c16172
--- /dev/null
+++ b/stepped-solutions/41/backend/src/resolvers/Mutation.js
@@ -0,0 +1,254 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+const { randomBytes } = require('crypto');
+const { promisify } = require('util');
+const { transport, makeANiceEmail } = require('../mail');
+const { hasPermission } = require('../utils');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in to do that!');
+ }
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ // This is how to create a relationship between the Item and the User
+ user: {
+ connect: {
+ id: ctx.request.userId,
+ },
+ },
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title user { id }}`);
+ // 2. Check if they own that item, or have the permissions
+ const ownsItem = item.user.id === ctx.request.userId;
+ const hasPermissions = ctx.request.user.permissions.some(permission =>
+ ['ADMIN', 'ITEMDELETE'].includes(permission)
+ );
+
+ if (!ownsItem && hasPermissions) {
+ throw new Error("You don't have permission to do that!");
+ }
+
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+ signout(parent, args, ctx, info) {
+ ctx.response.clearCookie('token');
+ return { message: 'Goodbye!' };
+ },
+ async requestReset(parent, args, ctx, info) {
+ // 1. Check if this is a real user
+ const user = await ctx.db.query.user({ where: { email: args.email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${args.email}`);
+ }
+ // 2. Set a reset token and expiry on that user
+ const randomBytesPromiseified = promisify(randomBytes);
+ const resetToken = (await randomBytesPromiseified(20)).toString('hex');
+ const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now
+ const res = await ctx.db.mutation.updateUser({
+ where: { email: args.email },
+ data: { resetToken, resetTokenExpiry },
+ });
+ // 3. Email them that reset token
+ const mailRes = await transport.sendMail({
+ from: 'wes@wesbos.com',
+ to: user.email,
+ subject: 'Your Password Reset Token',
+ html: makeANiceEmail(`Your Password Reset Token is here!
+ \n\n
+ <a href="${process.env
+ .FRONTEND_URL}/reset?resetToken=${resetToken}">Click Here to Reset</a>`),
+ });
+
+ // 4. Return the message
+ return { message: 'Thanks!' };
+ },
+ async resetPassword(parent, args, ctx, info) {
+ // 1. check if the passwords match
+ if (args.password !== args.confirmPassword) {
+ throw new Error("Yo Passwords don't match!");
+ }
+ // 2. check if its a legit reset token
+ // 3. Check if its expired
+ const [user] = await ctx.db.query.users({
+ where: {
+ resetToken: args.resetToken,
+ resetTokenExpiry_gte: Date.now() - 3600000,
+ },
+ });
+ if (!user) {
+ throw new Error('This token is either invalid or expired!');
+ }
+ // 4. Hash their new password
+ const password = await bcrypt.hash(args.password, 10);
+ // 5. Save the new password to the user and remove old resetToken fields
+ const updatedUser = await ctx.db.mutation.updateUser({
+ where: { email: user.email },
+ data: {
+ password,
+ resetToken: null,
+ resetTokenExpiry: null,
+ },
+ });
+ // 6. Generate JWT
+ const token = jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET);
+ // 7. Set the JWT cookie
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 8. return the new user
+ return updatedUser;
+ },
+ async updatePermissions(parent, args, ctx, info) {
+ // 1. Check if they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in!');
+ }
+ // 2. Query the current user
+ const currentUser = await ctx.db.query.user(
+ {
+ where: {
+ id: ctx.request.userId,
+ },
+ },
+ info
+ );
+ // 3. Check if they have permissions to do this
+ hasPermission(currentUser, ['ADMIN', 'PERMISSIONUPDATE']);
+ // 4. Update the permissions
+ return ctx.db.mutation.updateUser(
+ {
+ data: {
+ permissions: {
+ set: args.permissions,
+ },
+ },
+ where: {
+ id: args.userId,
+ },
+ },
+ info
+ );
+ },
+ async addToCart(parent, args, ctx, info) {
+ // 1. Make sure they are signed in
+ const { userId } = ctx.request;
+ if (!userId) {
+ throw new Error('You must be signed in soooon');
+ }
+ // 2. Query the users current cart
+ const [existingCartItem] = await ctx.db.query.cartItems({
+ where: {
+ user: { id: userId },
+ item: { id: args.id },
+ },
+ });
+ // 3. Check if that item is already in their cart and increment by 1 if it is
+ if (existingCartItem) {
+ console.log('This item is already in their cart');
+ return ctx.db.mutation.updateCartItem(
+ {
+ where: { id: existingCartItem.id },
+ data: { quantity: existingCartItem.quantity + 1 },
+ },
+ info
+ );
+ }
+ // 4. If its not, create a fresh CartItem for that user!
+ return ctx.db.mutation.createCartItem(
+ {
+ data: {
+ user: {
+ connect: { id: userId },
+ },
+ item: {
+ connect: { id: args.id },
+ },
+ },
+ },
+ info
+ );
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/41/backend/src/schema.graphql b/stepped-solutions/41/backend/src/schema.graphql
new file mode 100755
index 0000000..864396c
--- /dev/null
+++ b/stepped-solutions/41/backend/src/schema.graphql
@@ -0,0 +1,34 @@
+# import * from './generated/prisma.graphql'
+
+type SuccessMessage {
+ message: String
+}
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+ signin(email: String!, password: String!): User!
+ signout: SuccessMessage
+ requestReset(email: String!): SuccessMessage
+ resetPassword(resetToken: String!, password: String!, confirmPassword: String!): User!
+ updatePermissions(permissions: [Permission], userId: ID!): User
+ addToCart(id: ID!): CartItem
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+ users: [User]!
+}
+
+type User{
+ id: ID!
+ name: String!
+ email: String!
+ permissions: [Permission!]!
+ cart: [CartItem!]!
+}
diff --git a/stepped-solutions/41/frontend/components/AddToCart.js b/stepped-solutions/41/frontend/components/AddToCart.js
new file mode 100755
index 0000000..0625a9c
--- /dev/null
+++ b/stepped-solutions/41/frontend/components/AddToCart.js
@@ -0,0 +1,29 @@
+import React from 'react';
+import { Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+
+const ADD_TO_CART_MUTATION = gql`
+ mutation addToCart($id: ID!) {
+ addToCart(id: $id) {
+ id
+ quantity
+ }
+ }
+`;
+
+class AddToCart extends React.Component {
+ render() {
+ const { id } = this.props;
+ return (
+ <Mutation
+ mutation={ADD_TO_CART_MUTATION}
+ variables={{
+ id,
+ }}
+ >
+ {addToCart => <button onClick={addToCart}>Add To Cart 🛒</button>}
+ </Mutation>
+ );
+ }
+}
+export default AddToCart;
diff --git a/stepped-solutions/41/frontend/components/Item.js b/stepped-solutions/41/frontend/components/Item.js
new file mode 100755
index 0000000..2741dcf
--- /dev/null
+++ b/stepped-solutions/41/frontend/components/Item.js
@@ -0,0 +1,50 @@
+import React, { Component } from 'react';
+import PropTypes from 'prop-types';
+import Link from 'next/link';
+import Title from './styles/Title';
+import ItemStyles from './styles/ItemStyles';
+import PriceTag from './styles/PriceTag';
+import formatMoney from '../lib/formatMoney';
+import DeleteItem from './DeleteItem';
+import AddToCart from './AddToCart';
+
+export default class Item extends Component {
+ static propTypes = {
+ item: PropTypes.object.isRequired,
+ };
+
+ render() {
+ const { item } = this.props;
+ return (
+ <ItemStyles>
+ {item.image && <img src={item.image} alt={item.title} />}
+
+ <Title>
+ <Link
+ href={{
+ pathname: '/item',
+ query: { id: item.id },
+ }}
+ >
+ <a>{item.title}</a>
+ </Link>
+ </Title>
+ <PriceTag>{formatMoney(item.price)}</PriceTag>
+ <p>{item.description}</p>
+
+ <div className="buttonList">
+ <Link
+ href={{
+ pathname: 'update',
+ query: { id: item.id },
+ }}
+ >
+ <a>Edit ✏️</a>
+ </Link>
+ <AddToCart id={item.id} />
+ <DeleteItem id={item.id}>Delete This Item</DeleteItem>
+ </div>
+ </ItemStyles>
+ );
+ }
+}
diff --git a/stepped-solutions/42/frontend/components/AddToCart.js b/stepped-solutions/42/frontend/components/AddToCart.js
new file mode 100755
index 0000000..3e2842b
--- /dev/null
+++ b/stepped-solutions/42/frontend/components/AddToCart.js
@@ -0,0 +1,35 @@
+import React from 'react';
+import { Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import { CURRENT_USER_QUERY } from './User';
+
+const ADD_TO_CART_MUTATION = gql`
+ mutation addToCart($id: ID!) {
+ addToCart(id: $id) {
+ id
+ quantity
+ }
+ }
+`;
+
+class AddToCart extends React.Component {
+ render() {
+ const { id } = this.props;
+ return (
+ <Mutation
+ mutation={ADD_TO_CART_MUTATION}
+ variables={{
+ id,
+ }}
+ refetchQueries={[{ query: CURRENT_USER_QUERY }]}
+ >
+ {(addToCart, { loading }) => (
+ <button disabled={loading} onClick={addToCart}>
+ Add{loading && 'ing'} To Cart 🛒
+ </button>
+ )}
+ </Mutation>
+ );
+ }
+}
+export default AddToCart;
diff --git a/stepped-solutions/42/frontend/components/Cart.js b/stepped-solutions/42/frontend/components/Cart.js
new file mode 100755
index 0000000..1895235
--- /dev/null
+++ b/stepped-solutions/42/frontend/components/Cart.js
@@ -0,0 +1,63 @@
+import React from 'react';
+import { Query, Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import User from './User';
+import CartStyles from './styles/CartStyles';
+import Supreme from './styles/Supreme';
+import CloseButton from './styles/CloseButton';
+import SickButton from './styles/SickButton';
+import CartItem from './CartItem';
+import calcTotalPrice from '../lib/calcTotalPrice';
+import formatMoney from '../lib/formatMoney';
+
+const LOCAL_STATE_QUERY = gql`
+ query {
+ cartOpen @client
+ }
+`;
+
+const TOGGLE_CART_MUTATION = gql`
+ mutation {
+ toggleCart @client
+ }
+`;
+
+const Cart = () => (
+ <User>
+ {({ data: { me } }) => {
+ if (!me) return null;
+ console.log(me);
+ return (
+ <Mutation mutation={TOGGLE_CART_MUTATION}>
+ {toggleCart => (
+ <Query query={LOCAL_STATE_QUERY}>
+ {({ data }) => (
+ <CartStyles open={data.cartOpen}>
+ <header>
+ <CloseButton onClick={toggleCart} title="close">
+ &times;
+ </CloseButton>
+ <Supreme>{me.name}'s Cart</Supreme>
+ <p>
+ You Have {me.cart.length} Item{me.cart.length === 1 ? '' : 's'} in your cart.
+ </p>
+ </header>
+ <ul>
+ {me.cart.map(cartItem => <CartItem key={cartItem.id} cartItem={cartItem} />)}
+ </ul>
+ <footer>
+ <p>{formatMoney(calcTotalPrice(me.cart))}</p>
+ <SickButton>Checkout</SickButton>
+ </footer>
+ </CartStyles>
+ )}
+ </Query>
+ )}
+ </Mutation>
+ );
+ }}
+ </User>
+);
+
+export default Cart;
+export { LOCAL_STATE_QUERY, TOGGLE_CART_MUTATION };
diff --git a/stepped-solutions/42/frontend/components/CartItem.js b/stepped-solutions/42/frontend/components/CartItem.js
new file mode 100755
index 0000000..8f6a099
--- /dev/null
+++ b/stepped-solutions/42/frontend/components/CartItem.js
@@ -0,0 +1,41 @@
+import React from 'react';
+import styled from 'styled-components';
+import PropTypes from 'prop-types';
+import formatMoney from '../lib/formatMoney';
+
+const CartItemStyles = styled.li`
+ padding: 1rem 0;
+ border-bottom: 1px solid ${props => props.theme.lightgrey};
+ display: grid;
+ align-items: center;
+ grid-template-columns: auto 1fr auto;
+ img {
+ margin-right: 10px;
+ }
+ h3,
+ p {
+ margin: 0;
+ }
+`;
+
+const CartItem = ({ cartItem }) => (
+ <CartItemStyles>
+ <img width="100" src={cartItem.item.image} alt={cartItem.item.title} />
+ <div className="cart-item-details">
+ <h3>{cartItem.item.title}</h3>
+ <p>
+ {formatMoney(cartItem.item.price * cartItem.quantity)}
+ {' - '}
+ <em>
+ {cartItem.quantity} &times; {formatMoney(cartItem.item.price)} each
+ </em>
+ </p>
+ </div>
+ </CartItemStyles>
+);
+
+CartItem.propTypes = {
+ cartItem: PropTypes.object.isRequired,
+};
+
+export default CartItem;
diff --git a/stepped-solutions/42/frontend/components/User.js b/stepped-solutions/42/frontend/components/User.js
new file mode 100755
index 0000000..429bb25
--- /dev/null
+++ b/stepped-solutions/42/frontend/components/User.js
@@ -0,0 +1,38 @@
+import { Query } from 'react-apollo';
+import gql from 'graphql-tag';
+import PropTypes from 'prop-types';
+
+const CURRENT_USER_QUERY = gql`
+ query {
+ me {
+ id
+ email
+ name
+ permissions
+ cart {
+ id
+ quantity
+ item {
+ id
+ price
+ image
+ title
+ description
+ }
+ }
+ }
+ }
+`;
+
+const User = props => (
+ <Query {...props} query={CURRENT_USER_QUERY}>
+ {payload => props.children(payload)}
+ </Query>
+);
+
+User.propTypes = {
+ children: PropTypes.func.isRequired,
+};
+
+export default User;
+export { CURRENT_USER_QUERY };
diff --git a/stepped-solutions/43/backend/src/resolvers/Mutation.js b/stepped-solutions/43/backend/src/resolvers/Mutation.js
new file mode 100755
index 0000000..5586edf
--- /dev/null
+++ b/stepped-solutions/43/backend/src/resolvers/Mutation.js
@@ -0,0 +1,278 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+const { randomBytes } = require('crypto');
+const { promisify } = require('util');
+const { transport, makeANiceEmail } = require('../mail');
+const { hasPermission } = require('../utils');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in to do that!');
+ }
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ // This is how to create a relationship between the Item and the User
+ user: {
+ connect: {
+ id: ctx.request.userId,
+ },
+ },
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title user { id }}`);
+ // 2. Check if they own that item, or have the permissions
+ const ownsItem = item.user.id === ctx.request.userId;
+ const hasPermissions = ctx.request.user.permissions.some(permission =>
+ ['ADMIN', 'ITEMDELETE'].includes(permission)
+ );
+
+ if (!ownsItem && hasPermissions) {
+ throw new Error("You don't have permission to do that!");
+ }
+
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+ signout(parent, args, ctx, info) {
+ ctx.response.clearCookie('token');
+ return { message: 'Goodbye!' };
+ },
+ async requestReset(parent, args, ctx, info) {
+ // 1. Check if this is a real user
+ const user = await ctx.db.query.user({ where: { email: args.email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${args.email}`);
+ }
+ // 2. Set a reset token and expiry on that user
+ const randomBytesPromiseified = promisify(randomBytes);
+ const resetToken = (await randomBytesPromiseified(20)).toString('hex');
+ const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now
+ const res = await ctx.db.mutation.updateUser({
+ where: { email: args.email },
+ data: { resetToken, resetTokenExpiry },
+ });
+ // 3. Email them that reset token
+ const mailRes = await transport.sendMail({
+ from: 'wes@wesbos.com',
+ to: user.email,
+ subject: 'Your Password Reset Token',
+ html: makeANiceEmail(`Your Password Reset Token is here!
+ \n\n
+ <a href="${process.env
+ .FRONTEND_URL}/reset?resetToken=${resetToken}">Click Here to Reset</a>`),
+ });
+
+ // 4. Return the message
+ return { message: 'Thanks!' };
+ },
+ async resetPassword(parent, args, ctx, info) {
+ // 1. check if the passwords match
+ if (args.password !== args.confirmPassword) {
+ throw new Error("Yo Passwords don't match!");
+ }
+ // 2. check if its a legit reset token
+ // 3. Check if its expired
+ const [user] = await ctx.db.query.users({
+ where: {
+ resetToken: args.resetToken,
+ resetTokenExpiry_gte: Date.now() - 3600000,
+ },
+ });
+ if (!user) {
+ throw new Error('This token is either invalid or expired!');
+ }
+ // 4. Hash their new password
+ const password = await bcrypt.hash(args.password, 10);
+ // 5. Save the new password to the user and remove old resetToken fields
+ const updatedUser = await ctx.db.mutation.updateUser({
+ where: { email: user.email },
+ data: {
+ password,
+ resetToken: null,
+ resetTokenExpiry: null,
+ },
+ });
+ // 6. Generate JWT
+ const token = jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET);
+ // 7. Set the JWT cookie
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 8. return the new user
+ return updatedUser;
+ },
+ async updatePermissions(parent, args, ctx, info) {
+ // 1. Check if they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in!');
+ }
+ // 2. Query the current user
+ const currentUser = await ctx.db.query.user(
+ {
+ where: {
+ id: ctx.request.userId,
+ },
+ },
+ info
+ );
+ // 3. Check if they have permissions to do this
+ hasPermission(currentUser, ['ADMIN', 'PERMISSIONUPDATE']);
+ // 4. Update the permissions
+ return ctx.db.mutation.updateUser(
+ {
+ data: {
+ permissions: {
+ set: args.permissions,
+ },
+ },
+ where: {
+ id: args.userId,
+ },
+ },
+ info
+ );
+ },
+ async addToCart(parent, args, ctx, info) {
+ // 1. Make sure they are signed in
+ const { userId } = ctx.request;
+ if (!userId) {
+ throw new Error('You must be signed in soooon');
+ }
+ // 2. Query the users current cart
+ const [existingCartItem] = await ctx.db.query.cartItems({
+ where: {
+ user: { id: userId },
+ item: { id: args.id },
+ },
+ });
+ // 3. Check if that item is already in their cart and increment by 1 if it is
+ if (existingCartItem) {
+ console.log('This item is already in their cart');
+ return ctx.db.mutation.updateCartItem(
+ {
+ where: { id: existingCartItem.id },
+ data: { quantity: existingCartItem.quantity + 1 },
+ },
+ info
+ );
+ }
+ // 4. If its not, create a fresh CartItem for that user!
+ return ctx.db.mutation.createCartItem(
+ {
+ data: {
+ user: {
+ connect: { id: userId },
+ },
+ item: {
+ connect: { id: args.id },
+ },
+ },
+ },
+ info
+ );
+ },
+ async removeFromCart(parent, args, ctx, info) {
+ // 1. Find the cart item
+ const cartItem = await ctx.db.query.cartItem(
+ {
+ where: {
+ id: args.id,
+ },
+ },
+ `{ id, user { id }}`
+ );
+ // 1.5 Make sure we found an item
+ if (!cartItem) throw new Error('No CartItem Found!');
+ // 2. Make sure they own that cart item
+ if (cartItem.user.id !== ctx.request.userId) {
+ throw new Error('Cheatin huhhhh');
+ }
+ // 3. Delete that cart item
+ return ctx.db.mutation.deleteCartItem(
+ {
+ where: { id: args.id },
+ },
+ info
+ );
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/43/backend/src/schema.graphql b/stepped-solutions/43/backend/src/schema.graphql
new file mode 100755
index 0000000..4d5efb4
--- /dev/null
+++ b/stepped-solutions/43/backend/src/schema.graphql
@@ -0,0 +1,35 @@
+# import * from './generated/prisma.graphql'
+
+type SuccessMessage {
+ message: String
+}
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+ signin(email: String!, password: String!): User!
+ signout: SuccessMessage
+ requestReset(email: String!): SuccessMessage
+ resetPassword(resetToken: String!, password: String!, confirmPassword: String!): User!
+ updatePermissions(permissions: [Permission], userId: ID!): User
+ addToCart(id: ID!): CartItem
+ removeFromCart(id: ID!): CartItem
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+ users: [User]!
+}
+
+type User{
+ id: ID!
+ name: String!
+ email: String!
+ permissions: [Permission!]!
+ cart: [CartItem!]!
+}
diff --git a/stepped-solutions/43/frontend/components/CartItem.js b/stepped-solutions/43/frontend/components/CartItem.js
new file mode 100755
index 0000000..1be2128
--- /dev/null
+++ b/stepped-solutions/43/frontend/components/CartItem.js
@@ -0,0 +1,43 @@
+import React from 'react';
+import styled from 'styled-components';
+import PropTypes from 'prop-types';
+import formatMoney from '../lib/formatMoney';
+import RemoveFromCart from './RemoveFromCart';
+
+const CartItemStyles = styled.li`
+ padding: 1rem 0;
+ border-bottom: 1px solid ${props => props.theme.lightgrey};
+ display: grid;
+ align-items: center;
+ grid-template-columns: auto 1fr auto;
+ img {
+ margin-right: 10px;
+ }
+ h3,
+ p {
+ margin: 0;
+ }
+`;
+
+const CartItem = ({ cartItem }) => (
+ <CartItemStyles>
+ <img width="100" src={cartItem.item.image} alt={cartItem.item.title} />
+ <div className="cart-item-details">
+ <h3>{cartItem.item.title}</h3>
+ <p>
+ {formatMoney(cartItem.item.price * cartItem.quantity)}
+ {' - '}
+ <em>
+ {cartItem.quantity} &times; {formatMoney(cartItem.item.price)} each
+ </em>
+ </p>
+ </div>
+ <RemoveFromCart id={cartItem.id} />
+ </CartItemStyles>
+);
+
+CartItem.propTypes = {
+ cartItem: PropTypes.object.isRequired,
+};
+
+export default CartItem;
diff --git a/stepped-solutions/43/frontend/components/RemoveFromCart.js b/stepped-solutions/43/frontend/components/RemoveFromCart.js
new file mode 100755
index 0000000..b716e92
--- /dev/null
+++ b/stepped-solutions/43/frontend/components/RemoveFromCart.js
@@ -0,0 +1,49 @@
+import React from 'react';
+import { Mutation } from 'react-apollo';
+import styled from 'styled-components';
+import PropTypes from 'prop-types';
+import gql from 'graphql-tag';
+import { CURRENT_USER_QUERY } from './User';
+
+const REMOVE_FROM_CART_MUTATION = gql`
+ mutation removeFromCart($id: ID!) {
+ removeFromCart(id: $id) {
+ id
+ }
+ }
+`;
+
+const BigButton = styled.button`
+ font-size: 3rem;
+ background: none;
+ border: 0;
+ &:hover {
+ color: ${props => props.theme.red};
+ cursor: pointer;
+ }
+`;
+
+class RemoveFromCart extends React.Component {
+ static propTypes = {
+ id: PropTypes.string.isRequired,
+ };
+ render() {
+ return (
+ <Mutation mutation={REMOVE_FROM_CART_MUTATION} variables={{ id: this.props.id }}>
+ {(removeFromCart, { loading, error }) => (
+ <BigButton
+ disabled={loading}
+ onClick={() => {
+ removeFromCart().catch(err => alert(err.message));
+ }}
+ title="Delete Item"
+ >
+ &times;
+ </BigButton>
+ )}
+ </Mutation>
+ );
+ }
+}
+
+export default RemoveFromCart;
diff --git a/stepped-solutions/44/frontend/components/RemoveFromCart.js b/stepped-solutions/44/frontend/components/RemoveFromCart.js
new file mode 100755
index 0000000..065235a
--- /dev/null
+++ b/stepped-solutions/44/frontend/components/RemoveFromCart.js
@@ -0,0 +1,72 @@
+import React from 'react';
+import { Mutation } from 'react-apollo';
+import styled from 'styled-components';
+import PropTypes from 'prop-types';
+import gql from 'graphql-tag';
+import { CURRENT_USER_QUERY } from './User';
+
+const REMOVE_FROM_CART_MUTATION = gql`
+ mutation removeFromCart($id: ID!) {
+ removeFromCart(id: $id) {
+ id
+ }
+ }
+`;
+
+const BigButton = styled.button`
+ font-size: 3rem;
+ background: none;
+ border: 0;
+ &:hover {
+ color: ${props => props.theme.red};
+ cursor: pointer;
+ }
+`;
+
+class RemoveFromCart extends React.Component {
+ static propTypes = {
+ id: PropTypes.string.isRequired,
+ };
+ // This gets called as soon as we get a response back from the server after a mutation has been performed
+ update = (cache, payload) => {
+ console.log('Running remove from cart update fn');
+ // 1. first read the cache
+ const data = cache.readQuery({ query: CURRENT_USER_QUERY });
+ console.log(data);
+ // 2. remove that item from the cart
+ const cartItemId = payload.data.removeFromCart.id;
+ data.me.cart = data.me.cart.filter(cartItem => cartItem.id !== cartItemId);
+ // 3. write it back to the cache
+ cache.writeQuery({ query: CURRENT_USER_QUERY, data });
+ };
+ render() {
+ return (
+ <Mutation
+ mutation={REMOVE_FROM_CART_MUTATION}
+ variables={{ id: this.props.id }}
+ update={this.update}
+ optimisticResponse={{
+ __typename: 'Mutation',
+ removeFromCart: {
+ __typename: 'CartItem',
+ id: this.props.id,
+ },
+ }}
+ >
+ {(removeFromCart, { loading, error }) => (
+ <BigButton
+ disabled={loading}
+ onClick={() => {
+ removeFromCart().catch(err => alert(err.message));
+ }}
+ title="Delete Item"
+ >
+ &times;
+ </BigButton>
+ )}
+ </Mutation>
+ );
+ }
+}
+
+export default RemoveFromCart;
diff --git a/stepped-solutions/45/frontend/components/CartCount.js b/stepped-solutions/45/frontend/components/CartCount.js
new file mode 100755
index 0000000..c202d74
--- /dev/null
+++ b/stepped-solutions/45/frontend/components/CartCount.js
@@ -0,0 +1,60 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { TransitionGroup, CSSTransition } from 'react-transition-group';
+import styled from 'styled-components';
+
+const AnimationStyles = styled.span`
+ position: relative;
+ .count {
+ display: block;
+ position: relative;
+ transition: all 0.4s;
+ backface-visibility: hidden;
+ }
+ /* Intial State of the entered Dot */
+ .count-enter {
+ transform: scale(4) rotateX(0.5turn);
+ }
+ .count-enter-active {
+ transform: rotateX(0);
+ }
+ .count-exit {
+ top: 0;
+ position: absolute;
+ transform: rotateX(0);
+ }
+ .count-exit-active {
+ transform: scale(4) rotateX(0.5turn);
+ }
+`;
+
+const Dot = styled.div`
+ background: ${props => props.theme.red};
+ color: white;
+ border-radius: 50%;
+ padding: 0.5rem;
+ line-height: 2rem;
+ min-width: 3rem;
+ margin-left: 1rem;
+ font-weight: 100;
+ font-feature-settings: 'tnum';
+ font-variant-numeric: tabular-nums;
+`;
+
+const CartCount = ({ count }) => (
+ <AnimationStyles>
+ <TransitionGroup>
+ <CSSTransition
+ unmountOnExit
+ className="count"
+ classNames="count"
+ key={count}
+ timeout={{ enter: 400, exit: 400 }}
+ >
+ <Dot>{count}</Dot>
+ </CSSTransition>
+ </TransitionGroup>
+ </AnimationStyles>
+);
+
+export default CartCount;
diff --git a/stepped-solutions/45/frontend/components/Nav.js b/stepped-solutions/45/frontend/components/Nav.js
new file mode 100755
index 0000000..594d048
--- /dev/null
+++ b/stepped-solutions/45/frontend/components/Nav.js
@@ -0,0 +1,49 @@
+import Link from 'next/link';
+import { Mutation } from 'react-apollo';
+import { TOGGLE_CART_MUTATION } from './Cart';
+import NavStyles from './styles/NavStyles';
+import User from './User';
+import CartCount from './CartCount';
+import Signout from './Signout';
+
+const Nav = () => (
+ <User>
+ {({ data: { me } }) => (
+ <NavStyles>
+ <Link href="/items">
+ <a>Shop</a>
+ </Link>
+ {me && (
+ <>
+ <Link href="/sell">
+ <a>Sell</a>
+ </Link>
+ <Link href="/orders">
+ <a>Orders</a>
+ </Link>
+ <Link href="/me">
+ <a>Account</a>
+ </Link>
+ <Signout />
+ <Mutation mutation={TOGGLE_CART_MUTATION}>
+ {(toggleCart) => (
+ <button onClick={toggleCart}>
+ My Cart
+ <CartCount count={me.cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0)}></CartCount>
+ </button>
+ )}
+ </Mutation>
+ </>
+ )}
+ {!me && (
+ <Link href="/signup">
+ <a>Sign In</a>
+ </Link>
+
+ )}
+ </NavStyles>
+ )}
+ </User>
+);
+
+export default Nav;
diff --git a/stepped-solutions/46/backend/datamodel.graphql b/stepped-solutions/46/backend/datamodel.graphql
new file mode 100755
index 0000000..9786a4b
--- /dev/null
+++ b/stepped-solutions/46/backend/datamodel.graphql
@@ -0,0 +1,37 @@
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type User {
+ id: ID! @unique
+ name: String!
+ email: String! @unique
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission]
+ cart: [CartItem!]!
+}
+
+type Item {
+ id: ID! @unique
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: User!
+}
+
+
+type CartItem {
+ id: ID! @unique
+ quantity: Int! @default(value: 1)
+ item: Item # relationship to Item
+ user: User! # relationship to User
+}
diff --git a/stepped-solutions/46/backend/src/generated/prisma.graphql b/stepped-solutions/46/backend/src/generated/prisma.graphql
new file mode 100755
index 0000000..b9dbc95
--- /dev/null
+++ b/stepped-solutions/46/backend/src/generated/prisma.graphql
@@ -0,0 +1,1142 @@
+# source: https://us1.prisma.sh/wesbos/siccccccccck-fits/dev
+# timestamp: Tue Aug 21 2018 10:13:27 GMT-0400 (EDT)
+
+type AggregateCartItem {
+ count: Int!
+}
+
+type AggregateItem {
+ count: Int!
+}
+
+type AggregateUser {
+ count: Int!
+}
+
+type BatchPayload {
+ """The number of nodes that have been affected by the Batch operation."""
+ count: Long!
+}
+
+type CartItem implements Node {
+ id: ID!
+ quantity: Int!
+ item(where: ItemWhereInput): Item
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type CartItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [CartItemEdge]!
+ aggregate: AggregateCartItem!
+}
+
+input CartItemCreateInput {
+ quantity: Int
+ item: ItemCreateOneInput
+ user: UserCreateOneWithoutCartInput!
+}
+
+input CartItemCreateManyWithoutUserInput {
+ create: [CartItemCreateWithoutUserInput!]
+ connect: [CartItemWhereUniqueInput!]
+}
+
+input CartItemCreateWithoutUserInput {
+ quantity: Int
+ item: ItemCreateOneInput
+}
+
+"""An edge in a connection."""
+type CartItemEdge {
+ """The item at the end of the edge."""
+ node: CartItem!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum CartItemOrderByInput {
+ id_ASC
+ id_DESC
+ quantity_ASC
+ quantity_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type CartItemPreviousValues {
+ id: ID!
+ quantity: Int!
+}
+
+type CartItemSubscriptionPayload {
+ mutation: MutationType!
+ node: CartItem
+ updatedFields: [String!]
+ previousValues: CartItemPreviousValues
+}
+
+input CartItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [CartItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [CartItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [CartItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: CartItemWhereInput
+}
+
+input CartItemUpdateInput {
+ quantity: Int
+ item: ItemUpdateOneInput
+ user: UserUpdateOneWithoutCartInput
+}
+
+input CartItemUpdateManyWithoutUserInput {
+ create: [CartItemCreateWithoutUserInput!]
+ connect: [CartItemWhereUniqueInput!]
+ disconnect: [CartItemWhereUniqueInput!]
+ delete: [CartItemWhereUniqueInput!]
+ update: [CartItemUpdateWithWhereUniqueWithoutUserInput!]
+ upsert: [CartItemUpsertWithWhereUniqueWithoutUserInput!]
+}
+
+input CartItemUpdateWithoutUserDataInput {
+ quantity: Int
+ item: ItemUpdateOneInput
+}
+
+input CartItemUpdateWithWhereUniqueWithoutUserInput {
+ where: CartItemWhereUniqueInput!
+ data: CartItemUpdateWithoutUserDataInput!
+}
+
+input CartItemUpsertWithWhereUniqueWithoutUserInput {
+ where: CartItemWhereUniqueInput!
+ update: CartItemUpdateWithoutUserDataInput!
+ create: CartItemCreateWithoutUserInput!
+}
+
+input CartItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [CartItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [CartItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [CartItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ quantity: Int
+
+ """All values that are not equal to given value."""
+ quantity_not: Int
+
+ """All values that are contained in given list."""
+ quantity_in: [Int!]
+
+ """All values that are not contained in given list."""
+ quantity_not_in: [Int!]
+
+ """All values less than the given value."""
+ quantity_lt: Int
+
+ """All values less than or equal the given value."""
+ quantity_lte: Int
+
+ """All values greater than the given value."""
+ quantity_gt: Int
+
+ """All values greater than or equal the given value."""
+ quantity_gte: Int
+ item: ItemWhereInput
+ user: UserWhereInput
+}
+
+input CartItemWhereUniqueInput {
+ id: ID
+}
+
+type Item implements Node {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type ItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [ItemEdge]!
+ aggregate: AggregateItem!
+}
+
+input ItemCreateInput {
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: UserCreateOneInput!
+}
+
+input ItemCreateOneInput {
+ create: ItemCreateInput
+ connect: ItemWhereUniqueInput
+}
+
+"""An edge in a connection."""
+type ItemEdge {
+ """The item at the end of the edge."""
+ node: Item!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum ItemOrderByInput {
+ id_ASC
+ id_DESC
+ title_ASC
+ title_DESC
+ description_ASC
+ description_DESC
+ image_ASC
+ image_DESC
+ largeImage_ASC
+ largeImage_DESC
+ price_ASC
+ price_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type ItemPreviousValues {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+}
+
+type ItemSubscriptionPayload {
+ mutation: MutationType!
+ node: Item
+ updatedFields: [String!]
+ previousValues: ItemPreviousValues
+}
+
+input ItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: ItemWhereInput
+}
+
+input ItemUpdateDataInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneInput
+}
+
+input ItemUpdateInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneInput
+}
+
+input ItemUpdateOneInput {
+ create: ItemCreateInput
+ connect: ItemWhereUniqueInput
+ disconnect: Boolean
+ delete: Boolean
+ update: ItemUpdateDataInput
+ upsert: ItemUpsertNestedInput
+}
+
+input ItemUpsertNestedInput {
+ update: ItemUpdateDataInput!
+ create: ItemCreateInput!
+}
+
+input ItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ title: String
+
+ """All values that are not equal to given value."""
+ title_not: String
+
+ """All values that are contained in given list."""
+ title_in: [String!]
+
+ """All values that are not contained in given list."""
+ title_not_in: [String!]
+
+ """All values less than the given value."""
+ title_lt: String
+
+ """All values less than or equal the given value."""
+ title_lte: String
+
+ """All values greater than the given value."""
+ title_gt: String
+
+ """All values greater than or equal the given value."""
+ title_gte: String
+
+ """All values containing the given string."""
+ title_contains: String
+
+ """All values not containing the given string."""
+ title_not_contains: String
+
+ """All values starting with the given string."""
+ title_starts_with: String
+
+ """All values not starting with the given string."""
+ title_not_starts_with: String
+
+ """All values ending with the given string."""
+ title_ends_with: String
+
+ """All values not ending with the given string."""
+ title_not_ends_with: String
+ description: String
+
+ """All values that are not equal to given value."""
+ description_not: String
+
+ """All values that are contained in given list."""
+ description_in: [String!]
+
+ """All values that are not contained in given list."""
+ description_not_in: [String!]
+
+ """All values less than the given value."""
+ description_lt: String
+
+ """All values less than or equal the given value."""
+ description_lte: String
+
+ """All values greater than the given value."""
+ description_gt: String
+
+ """All values greater than or equal the given value."""
+ description_gte: String
+
+ """All values containing the given string."""
+ description_contains: String
+
+ """All values not containing the given string."""
+ description_not_contains: String
+
+ """All values starting with the given string."""
+ description_starts_with: String
+
+ """All values not starting with the given string."""
+ description_not_starts_with: String
+
+ """All values ending with the given string."""
+ description_ends_with: String
+
+ """All values not ending with the given string."""
+ description_not_ends_with: String
+ image: String
+
+ """All values that are not equal to given value."""
+ image_not: String
+
+ """All values that are contained in given list."""
+ image_in: [String!]
+
+ """All values that are not contained in given list."""
+ image_not_in: [String!]
+
+ """All values less than the given value."""
+ image_lt: String
+
+ """All values less than or equal the given value."""
+ image_lte: String
+
+ """All values greater than the given value."""
+ image_gt: String
+
+ """All values greater than or equal the given value."""
+ image_gte: String
+
+ """All values containing the given string."""
+ image_contains: String
+
+ """All values not containing the given string."""
+ image_not_contains: String
+
+ """All values starting with the given string."""
+ image_starts_with: String
+
+ """All values not starting with the given string."""
+ image_not_starts_with: String
+
+ """All values ending with the given string."""
+ image_ends_with: String
+
+ """All values not ending with the given string."""
+ image_not_ends_with: String
+ largeImage: String
+
+ """All values that are not equal to given value."""
+ largeImage_not: String
+
+ """All values that are contained in given list."""
+ largeImage_in: [String!]
+
+ """All values that are not contained in given list."""
+ largeImage_not_in: [String!]
+
+ """All values less than the given value."""
+ largeImage_lt: String
+
+ """All values less than or equal the given value."""
+ largeImage_lte: String
+
+ """All values greater than the given value."""
+ largeImage_gt: String
+
+ """All values greater than or equal the given value."""
+ largeImage_gte: String
+
+ """All values containing the given string."""
+ largeImage_contains: String
+
+ """All values not containing the given string."""
+ largeImage_not_contains: String
+
+ """All values starting with the given string."""
+ largeImage_starts_with: String
+
+ """All values not starting with the given string."""
+ largeImage_not_starts_with: String
+
+ """All values ending with the given string."""
+ largeImage_ends_with: String
+
+ """All values not ending with the given string."""
+ largeImage_not_ends_with: String
+ price: Int
+
+ """All values that are not equal to given value."""
+ price_not: Int
+
+ """All values that are contained in given list."""
+ price_in: [Int!]
+
+ """All values that are not contained in given list."""
+ price_not_in: [Int!]
+
+ """All values less than the given value."""
+ price_lt: Int
+
+ """All values less than or equal the given value."""
+ price_lte: Int
+
+ """All values greater than the given value."""
+ price_gt: Int
+
+ """All values greater than or equal the given value."""
+ price_gte: Int
+ user: UserWhereInput
+}
+
+input ItemWhereUniqueInput {
+ id: ID
+}
+
+"""
+The `Long` scalar type represents non-fractional signed whole numeric values.
+Long can represent values between -(2^63) and 2^63 - 1.
+"""
+scalar Long
+
+type Mutation {
+ createCartItem(data: CartItemCreateInput!): CartItem!
+ createItem(data: ItemCreateInput!): Item!
+ createUser(data: UserCreateInput!): User!
+ updateCartItem(data: CartItemUpdateInput!, where: CartItemWhereUniqueInput!): CartItem
+ updateItem(data: ItemUpdateInput!, where: ItemWhereUniqueInput!): Item
+ updateUser(data: UserUpdateInput!, where: UserWhereUniqueInput!): User
+ deleteCartItem(where: CartItemWhereUniqueInput!): CartItem
+ deleteItem(where: ItemWhereUniqueInput!): Item
+ deleteUser(where: UserWhereUniqueInput!): User
+ upsertCartItem(where: CartItemWhereUniqueInput!, create: CartItemCreateInput!, update: CartItemUpdateInput!): CartItem!
+ upsertItem(where: ItemWhereUniqueInput!, create: ItemCreateInput!, update: ItemUpdateInput!): Item!
+ upsertUser(where: UserWhereUniqueInput!, create: UserCreateInput!, update: UserUpdateInput!): User!
+ updateManyCartItems(data: CartItemUpdateInput!, where: CartItemWhereInput): BatchPayload!
+ updateManyItems(data: ItemUpdateInput!, where: ItemWhereInput): BatchPayload!
+ updateManyUsers(data: UserUpdateInput!, where: UserWhereInput): BatchPayload!
+ deleteManyCartItems(where: CartItemWhereInput): BatchPayload!
+ deleteManyItems(where: ItemWhereInput): BatchPayload!
+ deleteManyUsers(where: UserWhereInput): BatchPayload!
+}
+
+enum MutationType {
+ CREATED
+ UPDATED
+ DELETED
+}
+
+"""An object with an ID"""
+interface Node {
+ """The id of the object."""
+ id: ID!
+}
+
+"""Information about pagination in a connection."""
+type PageInfo {
+ """When paginating forwards, are there more items?"""
+ hasNextPage: Boolean!
+
+ """When paginating backwards, are there more items?"""
+ hasPreviousPage: Boolean!
+
+ """When paginating backwards, the cursor to continue."""
+ startCursor: String
+
+ """When paginating forwards, the cursor to continue."""
+ endCursor: String
+}
+
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type Query {
+ cartItems(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [CartItem]!
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Item]!
+ users(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [User]!
+ cartItem(where: CartItemWhereUniqueInput!): CartItem
+ item(where: ItemWhereUniqueInput!): Item
+ user(where: UserWhereUniqueInput!): User
+ cartItemsConnection(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): CartItemConnection!
+ itemsConnection(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): ItemConnection!
+ usersConnection(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): UserConnection!
+
+ """Fetches an object given its ID"""
+ node(
+ """The ID of an object"""
+ id: ID!
+ ): Node
+}
+
+type Subscription {
+ cartItem(where: CartItemSubscriptionWhereInput): CartItemSubscriptionPayload
+ item(where: ItemSubscriptionWhereInput): ItemSubscriptionPayload
+ user(where: UserSubscriptionWhereInput): UserSubscriptionPayload
+}
+
+type User implements Node {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+ cart(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [CartItem!]
+}
+
+"""A connection to a list of items."""
+type UserConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [UserEdge]!
+ aggregate: AggregateUser!
+}
+
+input UserCreateInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+ cart: CartItemCreateManyWithoutUserInput
+}
+
+input UserCreateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreateOneWithoutCartInput {
+ create: UserCreateWithoutCartInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserCreateWithoutCartInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+}
+
+"""An edge in a connection."""
+type UserEdge {
+ """The item at the end of the edge."""
+ node: User!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum UserOrderByInput {
+ id_ASC
+ id_DESC
+ name_ASC
+ name_DESC
+ email_ASC
+ email_DESC
+ password_ASC
+ password_DESC
+ resetToken_ASC
+ resetToken_DESC
+ resetTokenExpiry_ASC
+ resetTokenExpiry_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type UserPreviousValues {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+}
+
+type UserSubscriptionPayload {
+ mutation: MutationType!
+ node: User
+ updatedFields: [String!]
+ previousValues: UserPreviousValues
+}
+
+input UserSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: UserWhereInput
+}
+
+input UserUpdateDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+ cart: CartItemUpdateManyWithoutUserInput
+}
+
+input UserUpdateInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+ cart: CartItemUpdateManyWithoutUserInput
+}
+
+input UserUpdateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+ delete: Boolean
+ update: UserUpdateDataInput
+ upsert: UserUpsertNestedInput
+}
+
+input UserUpdateOneWithoutCartInput {
+ create: UserCreateWithoutCartInput
+ connect: UserWhereUniqueInput
+ delete: Boolean
+ update: UserUpdateWithoutCartDataInput
+ upsert: UserUpsertWithoutCartInput
+}
+
+input UserUpdatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserUpdateWithoutCartDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+}
+
+input UserUpsertNestedInput {
+ update: UserUpdateDataInput!
+ create: UserCreateInput!
+}
+
+input UserUpsertWithoutCartInput {
+ update: UserUpdateWithoutCartDataInput!
+ create: UserCreateWithoutCartInput!
+}
+
+input UserWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ name: String
+
+ """All values that are not equal to given value."""
+ name_not: String
+
+ """All values that are contained in given list."""
+ name_in: [String!]
+
+ """All values that are not contained in given list."""
+ name_not_in: [String!]
+
+ """All values less than the given value."""
+ name_lt: String
+
+ """All values less than or equal the given value."""
+ name_lte: String
+
+ """All values greater than the given value."""
+ name_gt: String
+
+ """All values greater than or equal the given value."""
+ name_gte: String
+
+ """All values containing the given string."""
+ name_contains: String
+
+ """All values not containing the given string."""
+ name_not_contains: String
+
+ """All values starting with the given string."""
+ name_starts_with: String
+
+ """All values not starting with the given string."""
+ name_not_starts_with: String
+
+ """All values ending with the given string."""
+ name_ends_with: String
+
+ """All values not ending with the given string."""
+ name_not_ends_with: String
+ email: String
+
+ """All values that are not equal to given value."""
+ email_not: String
+
+ """All values that are contained in given list."""
+ email_in: [String!]
+
+ """All values that are not contained in given list."""
+ email_not_in: [String!]
+
+ """All values less than the given value."""
+ email_lt: String
+
+ """All values less than or equal the given value."""
+ email_lte: String
+
+ """All values greater than the given value."""
+ email_gt: String
+
+ """All values greater than or equal the given value."""
+ email_gte: String
+
+ """All values containing the given string."""
+ email_contains: String
+
+ """All values not containing the given string."""
+ email_not_contains: String
+
+ """All values starting with the given string."""
+ email_starts_with: String
+
+ """All values not starting with the given string."""
+ email_not_starts_with: String
+
+ """All values ending with the given string."""
+ email_ends_with: String
+
+ """All values not ending with the given string."""
+ email_not_ends_with: String
+ password: String
+
+ """All values that are not equal to given value."""
+ password_not: String
+
+ """All values that are contained in given list."""
+ password_in: [String!]
+
+ """All values that are not contained in given list."""
+ password_not_in: [String!]
+
+ """All values less than the given value."""
+ password_lt: String
+
+ """All values less than or equal the given value."""
+ password_lte: String
+
+ """All values greater than the given value."""
+ password_gt: String
+
+ """All values greater than or equal the given value."""
+ password_gte: String
+
+ """All values containing the given string."""
+ password_contains: String
+
+ """All values not containing the given string."""
+ password_not_contains: String
+
+ """All values starting with the given string."""
+ password_starts_with: String
+
+ """All values not starting with the given string."""
+ password_not_starts_with: String
+
+ """All values ending with the given string."""
+ password_ends_with: String
+
+ """All values not ending with the given string."""
+ password_not_ends_with: String
+ resetToken: String
+
+ """All values that are not equal to given value."""
+ resetToken_not: String
+
+ """All values that are contained in given list."""
+ resetToken_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetToken_not_in: [String!]
+
+ """All values less than the given value."""
+ resetToken_lt: String
+
+ """All values less than or equal the given value."""
+ resetToken_lte: String
+
+ """All values greater than the given value."""
+ resetToken_gt: String
+
+ """All values greater than or equal the given value."""
+ resetToken_gte: String
+
+ """All values containing the given string."""
+ resetToken_contains: String
+
+ """All values not containing the given string."""
+ resetToken_not_contains: String
+
+ """All values starting with the given string."""
+ resetToken_starts_with: String
+
+ """All values not starting with the given string."""
+ resetToken_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetToken_ends_with: String
+
+ """All values not ending with the given string."""
+ resetToken_not_ends_with: String
+ resetTokenExpiry: String
+
+ """All values that are not equal to given value."""
+ resetTokenExpiry_not: String
+
+ """All values that are contained in given list."""
+ resetTokenExpiry_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetTokenExpiry_not_in: [String!]
+
+ """All values less than the given value."""
+ resetTokenExpiry_lt: String
+
+ """All values less than or equal the given value."""
+ resetTokenExpiry_lte: String
+
+ """All values greater than the given value."""
+ resetTokenExpiry_gt: String
+
+ """All values greater than or equal the given value."""
+ resetTokenExpiry_gte: String
+
+ """All values containing the given string."""
+ resetTokenExpiry_contains: String
+
+ """All values not containing the given string."""
+ resetTokenExpiry_not_contains: String
+
+ """All values starting with the given string."""
+ resetTokenExpiry_starts_with: String
+
+ """All values not starting with the given string."""
+ resetTokenExpiry_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetTokenExpiry_ends_with: String
+
+ """All values not ending with the given string."""
+ resetTokenExpiry_not_ends_with: String
+ cart_every: CartItemWhereInput
+ cart_some: CartItemWhereInput
+ cart_none: CartItemWhereInput
+}
+
+input UserWhereUniqueInput {
+ id: ID
+ email: String
+}
diff --git a/stepped-solutions/46/frontend/components/CartItem.js b/stepped-solutions/46/frontend/components/CartItem.js
new file mode 100755
index 0000000..b0ce62e
--- /dev/null
+++ b/stepped-solutions/46/frontend/components/CartItem.js
@@ -0,0 +1,53 @@
+import React from 'react';
+import styled from 'styled-components';
+import PropTypes from 'prop-types';
+import formatMoney from '../lib/formatMoney';
+import RemoveFromCart from './RemoveFromCart';
+
+const CartItemStyles = styled.li`
+ padding: 1rem 0;
+ border-bottom: 1px solid ${props => props.theme.lightgrey};
+ display: grid;
+ align-items: center;
+ grid-template-columns: auto 1fr auto;
+ img {
+ margin-right: 10px;
+ }
+ h3,
+ p {
+ margin: 0;
+ }
+`;
+
+const CartItem = ({ cartItem }) => {
+ // first check if that item exists
+ if (!cartItem.item)
+ return (
+ <CartItemStyles>
+ <p>This Item has been removed</p>
+ <RemoveFromCart id={cartItem.id} />
+ </CartItemStyles>
+ );
+ return (
+ <CartItemStyles>
+ <img width="100" src={cartItem.item.image} alt={cartItem.item.title} />
+ <div className="cart-item-details">
+ <h3>{cartItem.item.title}</h3>
+ <p>
+ {formatMoney(cartItem.item.price * cartItem.quantity)}
+ {' - '}
+ <em>
+ {cartItem.quantity} &times; {formatMoney(cartItem.item.price)} each
+ </em>
+ </p>
+ </div>
+ <RemoveFromCart id={cartItem.id} />
+ </CartItemStyles>
+ );
+};
+
+CartItem.propTypes = {
+ cartItem: PropTypes.object.isRequired,
+};
+
+export default CartItem;
diff --git a/stepped-solutions/47/frontend/components/Cart.js b/stepped-solutions/47/frontend/components/Cart.js
new file mode 100755
index 0000000..e4eb375
--- /dev/null
+++ b/stepped-solutions/47/frontend/components/Cart.js
@@ -0,0 +1,61 @@
+import React from 'react';
+import { Query, Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import { adopt } from 'react-adopt';
+import User from './User';
+import CartStyles from './styles/CartStyles';
+import Supreme from './styles/Supreme';
+import CloseButton from './styles/CloseButton';
+import SickButton from './styles/SickButton';
+import CartItem from './CartItem';
+import calcTotalPrice from '../lib/calcTotalPrice';
+import formatMoney from '../lib/formatMoney';
+
+const LOCAL_STATE_QUERY = gql`
+ query {
+ cartOpen @client
+ }
+`;
+
+const TOGGLE_CART_MUTATION = gql`
+ mutation {
+ toggleCart @client
+ }
+`;
+/* eslint-disable */
+const Composed = adopt({
+ user: ({ render }) => <User>{render}</User>,
+ toggleCart: ({ render }) => <Mutation mutation={TOGGLE_CART_MUTATION}>{render}</Mutation>,
+ localState: ({ render }) => <Query query={LOCAL_STATE_QUERY}>{render}</Query>,
+});
+/* eslint-enable */
+
+const Cart = () => (
+ <Composed>
+ {({ user, toggleCart, localState }) => {
+ const me = user.data.me;
+ if (!me) return null;
+ return (
+ <CartStyles open={localState.data.cartOpen}>
+ <header>
+ <CloseButton onClick={toggleCart} title="close">
+ &times;
+ </CloseButton>
+ <Supreme>{me.name}'s Cart</Supreme>
+ <p>
+ You Have {me.cart.length} Item{me.cart.length === 1 ? '' : 's'} in your cart.
+ </p>
+ </header>
+ <ul>{me.cart.map(cartItem => <CartItem key={cartItem.id} cartItem={cartItem} />)}</ul>
+ <footer>
+ <p>{formatMoney(calcTotalPrice(me.cart))}</p>
+ <SickButton>Checkout</SickButton>
+ </footer>
+ </CartStyles>
+ );
+ }}
+ </Composed>
+);
+
+export default Cart;
+export { LOCAL_STATE_QUERY, TOGGLE_CART_MUTATION };
diff --git a/stepped-solutions/48/frontend/components/Header.js b/stepped-solutions/48/frontend/components/Header.js
new file mode 100755
index 0000000..797eb8e
--- /dev/null
+++ b/stepped-solutions/48/frontend/components/Header.js
@@ -0,0 +1,75 @@
+import Link from 'next/link';
+import styled from 'styled-components';
+import NProgress from 'nprogress';
+import Router from 'next/router';
+import Nav from './Nav';
+import Cart from './Cart';
+import Search from './Search';
+
+Router.onRouteChangeStart = () => {
+ NProgress.start();
+};
+Router.onRouteChangeComplete = () => {
+ NProgress.done();
+};
+
+Router.onRouteChangeError = () => {
+ NProgress.done();
+};
+
+const Logo = styled.h1`
+ font-size: 4rem;
+ margin-left: 2rem;
+ position: relative;
+ z-index: 2;
+ transform: skew(-7deg);
+ a {
+ padding: 0.5rem 1rem;
+ background: ${props => props.theme.red};
+ color: white;
+ text-transform: uppercase;
+ text-decoration: none;
+ }
+ @media (max-width: 1300px) {
+ margin: 0;
+ text-align: center;
+ }
+`;
+
+const StyledHeader = styled.header`
+ .bar {
+ border-bottom: 10px solid ${props => props.theme.black};
+ display: grid;
+ grid-template-columns: auto 1fr;
+ justify-content: space-between;
+ align-items: stretch;
+ @media (max-width: 1300px) {
+ grid-template-columns: 1fr;
+ justify-content: center;
+ }
+ }
+ .sub-bar {
+ display: grid;
+ grid-template-columns: 1fr auto;
+ border-bottom: 1px solid ${props => props.theme.lightgrey};
+ }
+`;
+
+const Header = () => (
+ <StyledHeader>
+ <div className="bar">
+ <Logo>
+ <Link href="/">
+ <a>Sick Fits</a>
+ </Link>
+ </Logo>
+ <Nav />
+ </div>
+ <div className="sub-bar">
+ <Search />
+ </div>
+ <Cart />
+ </StyledHeader>
+);
+
+export default Header;
diff --git a/stepped-solutions/48/frontend/components/Search.js b/stepped-solutions/48/frontend/components/Search.js
new file mode 100755
index 0000000..a725630
--- /dev/null
+++ b/stepped-solutions/48/frontend/components/Search.js
@@ -0,0 +1,67 @@
+import React from 'react';
+import Downshift from 'downshift';
+import Router from 'next/router';
+import { ApolloConsumer } from 'react-apollo';
+import gql from 'graphql-tag';
+import debounce from 'lodash.debounce';
+import { DropDown, DropDownItem, SearchStyles } from './styles/DropDown';
+
+const SEARCH_ITEMS_QUERY = gql`
+ query SEARCH_ITEMS_QUERY($searchTerm: String!) {
+ items(where: { OR: [{ title_contains: $searchTerm }, { description_contains: $searchTerm }] }) {
+ id
+ image
+ title
+ }
+ }
+`;
+
+class AutoComplete extends React.Component {
+ state = {
+ items: [],
+ loading: false,
+ };
+ onChange = debounce(async (e, client) => {
+ console.log('Searching...');
+ // turn loading on
+ this.setState({ loading: true });
+ // Manually query apollo client
+ const res = await client.query({
+ query: SEARCH_ITEMS_QUERY,
+ variables: { searchTerm: e.target.value },
+ });
+ this.setState({
+ items: res.data.items,
+ loading: false,
+ });
+ }, 350);
+ render() {
+ return (
+ <SearchStyles>
+ <div>
+ <ApolloConsumer>
+ {client => (
+ <input
+ type="search"
+ onChange={e => {
+ e.persist();
+ this.onChange(e, client);
+ }}
+ />
+ )}
+ </ApolloConsumer>
+ <DropDown>
+ {this.state.items.map(item => (
+ <DropDownItem key={item.id}>
+ <img width="50" src={item.image} alt={item.title} />
+ {item.title}
+ </DropDownItem>
+ ))}
+ </DropDown>
+ </div>
+ </SearchStyles>
+ );
+ }
+}
+
+export default AutoComplete;
diff --git a/stepped-solutions/49/frontend/components/Search.js b/stepped-solutions/49/frontend/components/Search.js
new file mode 100755
index 0000000..a520f33
--- /dev/null
+++ b/stepped-solutions/49/frontend/components/Search.js
@@ -0,0 +1,93 @@
+import React from 'react';
+import Downshift from 'downshift';
+import Router from 'next/router';
+import { ApolloConsumer } from 'react-apollo';
+import gql from 'graphql-tag';
+import debounce from 'lodash.debounce';
+import { DropDown, DropDownItem, SearchStyles } from './styles/DropDown';
+
+const SEARCH_ITEMS_QUERY = gql`
+ query SEARCH_ITEMS_QUERY($searchTerm: String!) {
+ items(where: { OR: [{ title_contains: $searchTerm }, { description_contains: $searchTerm }] }) {
+ id
+ image
+ title
+ }
+ }
+`;
+
+function routeToItem(item) {
+ Router.push({
+ pathname: '/item',
+ query: {
+ id: item.id,
+ },
+ });
+}
+
+class AutoComplete extends React.Component {
+ state = {
+ items: [],
+ loading: false,
+ };
+ onChange = debounce(async (e, client) => {
+ console.log('Searching...');
+ // turn loading on
+ this.setState({ loading: true });
+ // Manually query apollo client
+ const res = await client.query({
+ query: SEARCH_ITEMS_QUERY,
+ variables: { searchTerm: e.target.value },
+ });
+ this.setState({
+ items: res.data.items,
+ loading: false,
+ });
+ }, 350);
+ render() {
+ return (
+ <SearchStyles>
+ <Downshift onChange={routeToItem} itemToString={item => (item === null ? '' : item.title)}>
+ {({ getInputProps, getItemProps, isOpen, inputValue, highlightedIndex }) => (
+ <div>
+ <ApolloConsumer>
+ {client => (
+ <input
+ {...getInputProps({
+ type: 'search',
+ placeholder: 'Search For An Item',
+ id: 'search',
+ className: this.state.loading ? 'loading' : '',
+ onChange: e => {
+ e.persist();
+ this.onChange(e, client);
+ },
+ })}
+ />
+ )}
+ </ApolloConsumer>
+ {isOpen && (
+ <DropDown>
+ {this.state.items.map((item, index) => (
+ <DropDownItem
+ {...getItemProps({ item })}
+ key={item.id}
+ highlighted={index === highlightedIndex}
+ >
+ <img width="50" src={item.image} alt={item.title} />
+ {item.title}
+ </DropDownItem>
+ ))}
+ {!this.state.items.length &&
+ !this.state.loading && <DropDownItem> Nothing Found {inputValue}</DropDownItem>}
+ </DropDown>
+ )}
+ </div>
+ )}
+ </Downshift>
+ </SearchStyles>
+ );
+ }
+}
+
+export default AutoComplete;
diff --git a/stepped-solutions/49/frontend/lib/withData.js b/stepped-solutions/49/frontend/lib/withData.js
new file mode 100755
index 0000000..27571e7
--- /dev/null
+++ b/stepped-solutions/49/frontend/lib/withData.js
@@ -0,0 +1,42 @@
+import withApollo from 'next-with-apollo';
+import ApolloClient from 'apollo-boost';
+import { endpoint } from '../config';
+import { LOCAL_STATE_QUERY } from '../components/Cart';
+
+function createClient({ headers }) {
+ return new ApolloClient({
+ uri: process.env.NODE_ENV === 'development' ? endpoint : endpoint,
+ request: operation => {
+ operation.setContext({
+ fetchOptions: {
+ credentials: 'include',
+ },
+ headers,
+ });
+ },
+ // local data
+ clientState: {
+ resolvers: {
+ Mutation: {
+ toggleCart(_, variables, { cache }) {
+ // read the cartOpen value from the cache
+ const { cartOpen } = cache.readQuery({
+ query: LOCAL_STATE_QUERY,
+ });
+ // Write the cart State to the opposite
+ const data = {
+ data: { cartOpen: !cartOpen },
+ };
+ cache.writeData(data);
+ return data;
+ },
+ },
+ },
+ defaults: {
+ cartOpen: false,
+ },
+ },
+ });
+}
+
+export default withApollo(createClient);
diff --git a/stepped-solutions/50/frontend/components/Cart.js b/stepped-solutions/50/frontend/components/Cart.js
new file mode 100755
index 0000000..7dafeef
--- /dev/null
+++ b/stepped-solutions/50/frontend/components/Cart.js
@@ -0,0 +1,64 @@
+import React from 'react';
+import { Query, Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import { adopt } from 'react-adopt';
+import User from './User';
+import CartStyles from './styles/CartStyles';
+import Supreme from './styles/Supreme';
+import CloseButton from './styles/CloseButton';
+import SickButton from './styles/SickButton';
+import CartItem from './CartItem';
+import calcTotalPrice from '../lib/calcTotalPrice';
+import formatMoney from '../lib/formatMoney';
+import TakeMyMoney from './TakeMyMoney';
+
+const LOCAL_STATE_QUERY = gql`
+ query {
+ cartOpen @client
+ }
+`;
+
+const TOGGLE_CART_MUTATION = gql`
+ mutation {
+ toggleCart @client
+ }
+`;
+/* eslint-disable */
+const Composed = adopt({
+ user: ({ render }) => <User>{render}</User>,
+ toggleCart: ({ render }) => <Mutation mutation={TOGGLE_CART_MUTATION}>{render}</Mutation>,
+ localState: ({ render }) => <Query query={LOCAL_STATE_QUERY}>{render}</Query>,
+});
+/* eslint-enable */
+
+const Cart = () => (
+ <Composed>
+ {({ user, toggleCart, localState }) => {
+ const me = user.data.me;
+ if (!me) return null;
+ return (
+ <CartStyles open={localState.data.cartOpen}>
+ <header>
+ <CloseButton onClick={toggleCart} title="close">
+ &times;
+ </CloseButton>
+ <Supreme>{me.name}'s Cart</Supreme>
+ <p>
+ You Have {me.cart.length} Item{me.cart.length === 1 ? '' : 's'} in your cart.
+ </p>
+ </header>
+ <ul>{me.cart.map(cartItem => <CartItem key={cartItem.id} cartItem={cartItem} />)}</ul>
+ <footer>
+ <p>{formatMoney(calcTotalPrice(me.cart))}</p>
+ <TakeMyMoney>
+ <SickButton>Checkout</SickButton>
+ </TakeMyMoney>
+ </footer>
+ </CartStyles>
+ );
+ }}
+ </Composed>
+);
+
+export default Cart;
+export { LOCAL_STATE_QUERY, TOGGLE_CART_MUTATION };
diff --git a/stepped-solutions/50/frontend/components/TakeMyMoney.js b/stepped-solutions/50/frontend/components/TakeMyMoney.js
new file mode 100755
index 0000000..424b024
--- /dev/null
+++ b/stepped-solutions/50/frontend/components/TakeMyMoney.js
@@ -0,0 +1,43 @@
+import React from 'react';
+import StripeCheckout from 'react-stripe-checkout';
+import { Mutation } from 'react-apollo';
+import Router from 'next/router';
+import NProgress from 'nprogress';
+import PropTypes from 'prop-types';
+import gql from 'graphql-tag';
+import calcTotalPrice from '../lib/calcTotalPrice';
+import Error from './ErrorMessage';
+import User, { CURRENT_USER_QUERY } from './User';
+
+function totalItems(cart) {
+ return cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0);
+}
+
+class TakeMyMoney extends React.Component {
+ onToken = res => {
+ console.log('On Token Called!');
+ console.log(res.id);
+ };
+ render() {
+ return (
+ <User>
+ {({ data: { me } }) => (
+ <StripeCheckout
+ amount={calcTotalPrice(me.cart)}
+ name="Sick Fits"
+ description={`Order of ${totalItems(me.cart)} items!`}
+ image={me.cart[0].item && me.cart[0].item.image}
+ stripeKey="pk_test_Vtknn6vSdcZWSG2JWvEiWSqC"
+ currency="USD"
+ email={me.email}
+ token={res => this.onToken(res)}
+ >
+ {this.props.children}
+ </StripeCheckout>
+ )}
+ </User>
+ );
+ }
+}
+
+export default TakeMyMoney;
diff --git a/stepped-solutions/51/backend/datamodel.graphql b/stepped-solutions/51/backend/datamodel.graphql
new file mode 100755
index 0000000..b556d36
--- /dev/null
+++ b/stepped-solutions/51/backend/datamodel.graphql
@@ -0,0 +1,55 @@
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type User {
+ id: ID! @unique
+ name: String!
+ email: String! @unique
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission]
+ cart: [CartItem!]!
+}
+
+type Item {
+ id: ID! @unique
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: User!
+}
+
+type CartItem {
+ id: ID! @unique
+ quantity: Int! @default(value: 1)
+ item: Item # relationship to Item
+ user: User! # relationship to User
+}
+
+type OrderItem {
+ id: ID! @unique
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int! @default(value: 1)
+ user: User
+}
+
+type Order {
+ id: ID! @unique
+ items: [OrderItem!]!
+ total: Int!
+ user: User!
+ charge: String!
+}
diff --git a/stepped-solutions/51/backend/src/generated/prisma.graphql b/stepped-solutions/51/backend/src/generated/prisma.graphql
new file mode 100755
index 0000000..c9dd405
--- /dev/null
+++ b/stepped-solutions/51/backend/src/generated/prisma.graphql
@@ -0,0 +1,1805 @@
+# source: https://us1.prisma.sh/wesbos/siccccccccck-fits/dev
+# timestamp: Wed Aug 22 2018 14:34:48 GMT-0400 (EDT)
+
+type AggregateCartItem {
+ count: Int!
+}
+
+type AggregateItem {
+ count: Int!
+}
+
+type AggregateOrder {
+ count: Int!
+}
+
+type AggregateOrderItem {
+ count: Int!
+}
+
+type AggregateUser {
+ count: Int!
+}
+
+type BatchPayload {
+ """The number of nodes that have been affected by the Batch operation."""
+ count: Long!
+}
+
+type CartItem implements Node {
+ id: ID!
+ quantity: Int!
+ item(where: ItemWhereInput): Item
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type CartItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [CartItemEdge]!
+ aggregate: AggregateCartItem!
+}
+
+input CartItemCreateInput {
+ quantity: Int
+ item: ItemCreateOneInput
+ user: UserCreateOneWithoutCartInput!
+}
+
+input CartItemCreateManyWithoutUserInput {
+ create: [CartItemCreateWithoutUserInput!]
+ connect: [CartItemWhereUniqueInput!]
+}
+
+input CartItemCreateWithoutUserInput {
+ quantity: Int
+ item: ItemCreateOneInput
+}
+
+"""An edge in a connection."""
+type CartItemEdge {
+ """The item at the end of the edge."""
+ node: CartItem!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum CartItemOrderByInput {
+ id_ASC
+ id_DESC
+ quantity_ASC
+ quantity_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type CartItemPreviousValues {
+ id: ID!
+ quantity: Int!
+}
+
+type CartItemSubscriptionPayload {
+ mutation: MutationType!
+ node: CartItem
+ updatedFields: [String!]
+ previousValues: CartItemPreviousValues
+}
+
+input CartItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [CartItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [CartItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [CartItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: CartItemWhereInput
+}
+
+input CartItemUpdateInput {
+ quantity: Int
+ item: ItemUpdateOneInput
+ user: UserUpdateOneWithoutCartInput
+}
+
+input CartItemUpdateManyWithoutUserInput {
+ create: [CartItemCreateWithoutUserInput!]
+ connect: [CartItemWhereUniqueInput!]
+ disconnect: [CartItemWhereUniqueInput!]
+ delete: [CartItemWhereUniqueInput!]
+ update: [CartItemUpdateWithWhereUniqueWithoutUserInput!]
+ upsert: [CartItemUpsertWithWhereUniqueWithoutUserInput!]
+}
+
+input CartItemUpdateWithoutUserDataInput {
+ quantity: Int
+ item: ItemUpdateOneInput
+}
+
+input CartItemUpdateWithWhereUniqueWithoutUserInput {
+ where: CartItemWhereUniqueInput!
+ data: CartItemUpdateWithoutUserDataInput!
+}
+
+input CartItemUpsertWithWhereUniqueWithoutUserInput {
+ where: CartItemWhereUniqueInput!
+ update: CartItemUpdateWithoutUserDataInput!
+ create: CartItemCreateWithoutUserInput!
+}
+
+input CartItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [CartItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [CartItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [CartItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ quantity: Int
+
+ """All values that are not equal to given value."""
+ quantity_not: Int
+
+ """All values that are contained in given list."""
+ quantity_in: [Int!]
+
+ """All values that are not contained in given list."""
+ quantity_not_in: [Int!]
+
+ """All values less than the given value."""
+ quantity_lt: Int
+
+ """All values less than or equal the given value."""
+ quantity_lte: Int
+
+ """All values greater than the given value."""
+ quantity_gt: Int
+
+ """All values greater than or equal the given value."""
+ quantity_gte: Int
+ item: ItemWhereInput
+ user: UserWhereInput
+}
+
+input CartItemWhereUniqueInput {
+ id: ID
+}
+
+type Item implements Node {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type ItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [ItemEdge]!
+ aggregate: AggregateItem!
+}
+
+input ItemCreateInput {
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: UserCreateOneInput!
+}
+
+input ItemCreateOneInput {
+ create: ItemCreateInput
+ connect: ItemWhereUniqueInput
+}
+
+"""An edge in a connection."""
+type ItemEdge {
+ """The item at the end of the edge."""
+ node: Item!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum ItemOrderByInput {
+ id_ASC
+ id_DESC
+ title_ASC
+ title_DESC
+ description_ASC
+ description_DESC
+ image_ASC
+ image_DESC
+ largeImage_ASC
+ largeImage_DESC
+ price_ASC
+ price_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type ItemPreviousValues {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+}
+
+type ItemSubscriptionPayload {
+ mutation: MutationType!
+ node: Item
+ updatedFields: [String!]
+ previousValues: ItemPreviousValues
+}
+
+input ItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: ItemWhereInput
+}
+
+input ItemUpdateDataInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneInput
+}
+
+input ItemUpdateInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneInput
+}
+
+input ItemUpdateOneInput {
+ create: ItemCreateInput
+ connect: ItemWhereUniqueInput
+ disconnect: Boolean
+ delete: Boolean
+ update: ItemUpdateDataInput
+ upsert: ItemUpsertNestedInput
+}
+
+input ItemUpsertNestedInput {
+ update: ItemUpdateDataInput!
+ create: ItemCreateInput!
+}
+
+input ItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ title: String
+
+ """All values that are not equal to given value."""
+ title_not: String
+
+ """All values that are contained in given list."""
+ title_in: [String!]
+
+ """All values that are not contained in given list."""
+ title_not_in: [String!]
+
+ """All values less than the given value."""
+ title_lt: String
+
+ """All values less than or equal the given value."""
+ title_lte: String
+
+ """All values greater than the given value."""
+ title_gt: String
+
+ """All values greater than or equal the given value."""
+ title_gte: String
+
+ """All values containing the given string."""
+ title_contains: String
+
+ """All values not containing the given string."""
+ title_not_contains: String
+
+ """All values starting with the given string."""
+ title_starts_with: String
+
+ """All values not starting with the given string."""
+ title_not_starts_with: String
+
+ """All values ending with the given string."""
+ title_ends_with: String
+
+ """All values not ending with the given string."""
+ title_not_ends_with: String
+ description: String
+
+ """All values that are not equal to given value."""
+ description_not: String
+
+ """All values that are contained in given list."""
+ description_in: [String!]
+
+ """All values that are not contained in given list."""
+ description_not_in: [String!]
+
+ """All values less than the given value."""
+ description_lt: String
+
+ """All values less than or equal the given value."""
+ description_lte: String
+
+ """All values greater than the given value."""
+ description_gt: String
+
+ """All values greater than or equal the given value."""
+ description_gte: String
+
+ """All values containing the given string."""
+ description_contains: String
+
+ """All values not containing the given string."""
+ description_not_contains: String
+
+ """All values starting with the given string."""
+ description_starts_with: String
+
+ """All values not starting with the given string."""
+ description_not_starts_with: String
+
+ """All values ending with the given string."""
+ description_ends_with: String
+
+ """All values not ending with the given string."""
+ description_not_ends_with: String
+ image: String
+
+ """All values that are not equal to given value."""
+ image_not: String
+
+ """All values that are contained in given list."""
+ image_in: [String!]
+
+ """All values that are not contained in given list."""
+ image_not_in: [String!]
+
+ """All values less than the given value."""
+ image_lt: String
+
+ """All values less than or equal the given value."""
+ image_lte: String
+
+ """All values greater than the given value."""
+ image_gt: String
+
+ """All values greater than or equal the given value."""
+ image_gte: String
+
+ """All values containing the given string."""
+ image_contains: String
+
+ """All values not containing the given string."""
+ image_not_contains: String
+
+ """All values starting with the given string."""
+ image_starts_with: String
+
+ """All values not starting with the given string."""
+ image_not_starts_with: String
+
+ """All values ending with the given string."""
+ image_ends_with: String
+
+ """All values not ending with the given string."""
+ image_not_ends_with: String
+ largeImage: String
+
+ """All values that are not equal to given value."""
+ largeImage_not: String
+
+ """All values that are contained in given list."""
+ largeImage_in: [String!]
+
+ """All values that are not contained in given list."""
+ largeImage_not_in: [String!]
+
+ """All values less than the given value."""
+ largeImage_lt: String
+
+ """All values less than or equal the given value."""
+ largeImage_lte: String
+
+ """All values greater than the given value."""
+ largeImage_gt: String
+
+ """All values greater than or equal the given value."""
+ largeImage_gte: String
+
+ """All values containing the given string."""
+ largeImage_contains: String
+
+ """All values not containing the given string."""
+ largeImage_not_contains: String
+
+ """All values starting with the given string."""
+ largeImage_starts_with: String
+
+ """All values not starting with the given string."""
+ largeImage_not_starts_with: String
+
+ """All values ending with the given string."""
+ largeImage_ends_with: String
+
+ """All values not ending with the given string."""
+ largeImage_not_ends_with: String
+ price: Int
+
+ """All values that are not equal to given value."""
+ price_not: Int
+
+ """All values that are contained in given list."""
+ price_in: [Int!]
+
+ """All values that are not contained in given list."""
+ price_not_in: [Int!]
+
+ """All values less than the given value."""
+ price_lt: Int
+
+ """All values less than or equal the given value."""
+ price_lte: Int
+
+ """All values greater than the given value."""
+ price_gt: Int
+
+ """All values greater than or equal the given value."""
+ price_gte: Int
+ user: UserWhereInput
+}
+
+input ItemWhereUniqueInput {
+ id: ID
+}
+
+"""
+The `Long` scalar type represents non-fractional signed whole numeric values.
+Long can represent values between -(2^63) and 2^63 - 1.
+"""
+scalar Long
+
+type Mutation {
+ createCartItem(data: CartItemCreateInput!): CartItem!
+ createOrder(data: OrderCreateInput!): Order!
+ createItem(data: ItemCreateInput!): Item!
+ createOrderItem(data: OrderItemCreateInput!): OrderItem!
+ createUser(data: UserCreateInput!): User!
+ updateCartItem(data: CartItemUpdateInput!, where: CartItemWhereUniqueInput!): CartItem
+ updateOrder(data: OrderUpdateInput!, where: OrderWhereUniqueInput!): Order
+ updateItem(data: ItemUpdateInput!, where: ItemWhereUniqueInput!): Item
+ updateOrderItem(data: OrderItemUpdateInput!, where: OrderItemWhereUniqueInput!): OrderItem
+ updateUser(data: UserUpdateInput!, where: UserWhereUniqueInput!): User
+ deleteCartItem(where: CartItemWhereUniqueInput!): CartItem
+ deleteOrder(where: OrderWhereUniqueInput!): Order
+ deleteItem(where: ItemWhereUniqueInput!): Item
+ deleteOrderItem(where: OrderItemWhereUniqueInput!): OrderItem
+ deleteUser(where: UserWhereUniqueInput!): User
+ upsertCartItem(where: CartItemWhereUniqueInput!, create: CartItemCreateInput!, update: CartItemUpdateInput!): CartItem!
+ upsertOrder(where: OrderWhereUniqueInput!, create: OrderCreateInput!, update: OrderUpdateInput!): Order!
+ upsertItem(where: ItemWhereUniqueInput!, create: ItemCreateInput!, update: ItemUpdateInput!): Item!
+ upsertOrderItem(where: OrderItemWhereUniqueInput!, create: OrderItemCreateInput!, update: OrderItemUpdateInput!): OrderItem!
+ upsertUser(where: UserWhereUniqueInput!, create: UserCreateInput!, update: UserUpdateInput!): User!
+ updateManyCartItems(data: CartItemUpdateInput!, where: CartItemWhereInput): BatchPayload!
+ updateManyOrders(data: OrderUpdateInput!, where: OrderWhereInput): BatchPayload!
+ updateManyItems(data: ItemUpdateInput!, where: ItemWhereInput): BatchPayload!
+ updateManyOrderItems(data: OrderItemUpdateInput!, where: OrderItemWhereInput): BatchPayload!
+ updateManyUsers(data: UserUpdateInput!, where: UserWhereInput): BatchPayload!
+ deleteManyCartItems(where: CartItemWhereInput): BatchPayload!
+ deleteManyOrders(where: OrderWhereInput): BatchPayload!
+ deleteManyItems(where: ItemWhereInput): BatchPayload!
+ deleteManyOrderItems(where: OrderItemWhereInput): BatchPayload!
+ deleteManyUsers(where: UserWhereInput): BatchPayload!
+}
+
+enum MutationType {
+ CREATED
+ UPDATED
+ DELETED
+}
+
+"""An object with an ID"""
+interface Node {
+ """The id of the object."""
+ id: ID!
+}
+
+type Order implements Node {
+ id: ID!
+ items(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [OrderItem!]
+ total: Int!
+ user(where: UserWhereInput): User!
+ charge: String!
+}
+
+"""A connection to a list of items."""
+type OrderConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [OrderEdge]!
+ aggregate: AggregateOrder!
+}
+
+input OrderCreateInput {
+ total: Int!
+ charge: String!
+ items: OrderItemCreateManyInput
+ user: UserCreateOneInput!
+}
+
+"""An edge in a connection."""
+type OrderEdge {
+ """The item at the end of the edge."""
+ node: Order!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+type OrderItem implements Node {
+ id: ID!
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int!
+ user(where: UserWhereInput): User
+}
+
+"""A connection to a list of items."""
+type OrderItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [OrderItemEdge]!
+ aggregate: AggregateOrderItem!
+}
+
+input OrderItemCreateInput {
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int
+ user: UserCreateOneInput
+}
+
+input OrderItemCreateManyInput {
+ create: [OrderItemCreateInput!]
+ connect: [OrderItemWhereUniqueInput!]
+}
+
+"""An edge in a connection."""
+type OrderItemEdge {
+ """The item at the end of the edge."""
+ node: OrderItem!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum OrderItemOrderByInput {
+ id_ASC
+ id_DESC
+ title_ASC
+ title_DESC
+ description_ASC
+ description_DESC
+ image_ASC
+ image_DESC
+ largeImage_ASC
+ largeImage_DESC
+ price_ASC
+ price_DESC
+ quantity_ASC
+ quantity_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type OrderItemPreviousValues {
+ id: ID!
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int!
+}
+
+type OrderItemSubscriptionPayload {
+ mutation: MutationType!
+ node: OrderItem
+ updatedFields: [String!]
+ previousValues: OrderItemPreviousValues
+}
+
+input OrderItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: OrderItemWhereInput
+}
+
+input OrderItemUpdateDataInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ quantity: Int
+ user: UserUpdateOneInput
+}
+
+input OrderItemUpdateInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ quantity: Int
+ user: UserUpdateOneInput
+}
+
+input OrderItemUpdateManyInput {
+ create: [OrderItemCreateInput!]
+ connect: [OrderItemWhereUniqueInput!]
+ disconnect: [OrderItemWhereUniqueInput!]
+ delete: [OrderItemWhereUniqueInput!]
+ update: [OrderItemUpdateWithWhereUniqueNestedInput!]
+ upsert: [OrderItemUpsertWithWhereUniqueNestedInput!]
+}
+
+input OrderItemUpdateWithWhereUniqueNestedInput {
+ where: OrderItemWhereUniqueInput!
+ data: OrderItemUpdateDataInput!
+}
+
+input OrderItemUpsertWithWhereUniqueNestedInput {
+ where: OrderItemWhereUniqueInput!
+ update: OrderItemUpdateDataInput!
+ create: OrderItemCreateInput!
+}
+
+input OrderItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ title: String
+
+ """All values that are not equal to given value."""
+ title_not: String
+
+ """All values that are contained in given list."""
+ title_in: [String!]
+
+ """All values that are not contained in given list."""
+ title_not_in: [String!]
+
+ """All values less than the given value."""
+ title_lt: String
+
+ """All values less than or equal the given value."""
+ title_lte: String
+
+ """All values greater than the given value."""
+ title_gt: String
+
+ """All values greater than or equal the given value."""
+ title_gte: String
+
+ """All values containing the given string."""
+ title_contains: String
+
+ """All values not containing the given string."""
+ title_not_contains: String
+
+ """All values starting with the given string."""
+ title_starts_with: String
+
+ """All values not starting with the given string."""
+ title_not_starts_with: String
+
+ """All values ending with the given string."""
+ title_ends_with: String
+
+ """All values not ending with the given string."""
+ title_not_ends_with: String
+ description: String
+
+ """All values that are not equal to given value."""
+ description_not: String
+
+ """All values that are contained in given list."""
+ description_in: [String!]
+
+ """All values that are not contained in given list."""
+ description_not_in: [String!]
+
+ """All values less than the given value."""
+ description_lt: String
+
+ """All values less than or equal the given value."""
+ description_lte: String
+
+ """All values greater than the given value."""
+ description_gt: String
+
+ """All values greater than or equal the given value."""
+ description_gte: String
+
+ """All values containing the given string."""
+ description_contains: String
+
+ """All values not containing the given string."""
+ description_not_contains: String
+
+ """All values starting with the given string."""
+ description_starts_with: String
+
+ """All values not starting with the given string."""
+ description_not_starts_with: String
+
+ """All values ending with the given string."""
+ description_ends_with: String
+
+ """All values not ending with the given string."""
+ description_not_ends_with: String
+ image: String
+
+ """All values that are not equal to given value."""
+ image_not: String
+
+ """All values that are contained in given list."""
+ image_in: [String!]
+
+ """All values that are not contained in given list."""
+ image_not_in: [String!]
+
+ """All values less than the given value."""
+ image_lt: String
+
+ """All values less than or equal the given value."""
+ image_lte: String
+
+ """All values greater than the given value."""
+ image_gt: String
+
+ """All values greater than or equal the given value."""
+ image_gte: String
+
+ """All values containing the given string."""
+ image_contains: String
+
+ """All values not containing the given string."""
+ image_not_contains: String
+
+ """All values starting with the given string."""
+ image_starts_with: String
+
+ """All values not starting with the given string."""
+ image_not_starts_with: String
+
+ """All values ending with the given string."""
+ image_ends_with: String
+
+ """All values not ending with the given string."""
+ image_not_ends_with: String
+ largeImage: String
+
+ """All values that are not equal to given value."""
+ largeImage_not: String
+
+ """All values that are contained in given list."""
+ largeImage_in: [String!]
+
+ """All values that are not contained in given list."""
+ largeImage_not_in: [String!]
+
+ """All values less than the given value."""
+ largeImage_lt: String
+
+ """All values less than or equal the given value."""
+ largeImage_lte: String
+
+ """All values greater than the given value."""
+ largeImage_gt: String
+
+ """All values greater than or equal the given value."""
+ largeImage_gte: String
+
+ """All values containing the given string."""
+ largeImage_contains: String
+
+ """All values not containing the given string."""
+ largeImage_not_contains: String
+
+ """All values starting with the given string."""
+ largeImage_starts_with: String
+
+ """All values not starting with the given string."""
+ largeImage_not_starts_with: String
+
+ """All values ending with the given string."""
+ largeImage_ends_with: String
+
+ """All values not ending with the given string."""
+ largeImage_not_ends_with: String
+ price: Int
+
+ """All values that are not equal to given value."""
+ price_not: Int
+
+ """All values that are contained in given list."""
+ price_in: [Int!]
+
+ """All values that are not contained in given list."""
+ price_not_in: [Int!]
+
+ """All values less than the given value."""
+ price_lt: Int
+
+ """All values less than or equal the given value."""
+ price_lte: Int
+
+ """All values greater than the given value."""
+ price_gt: Int
+
+ """All values greater than or equal the given value."""
+ price_gte: Int
+ quantity: Int
+
+ """All values that are not equal to given value."""
+ quantity_not: Int
+
+ """All values that are contained in given list."""
+ quantity_in: [Int!]
+
+ """All values that are not contained in given list."""
+ quantity_not_in: [Int!]
+
+ """All values less than the given value."""
+ quantity_lt: Int
+
+ """All values less than or equal the given value."""
+ quantity_lte: Int
+
+ """All values greater than the given value."""
+ quantity_gt: Int
+
+ """All values greater than or equal the given value."""
+ quantity_gte: Int
+ user: UserWhereInput
+}
+
+input OrderItemWhereUniqueInput {
+ id: ID
+}
+
+enum OrderOrderByInput {
+ id_ASC
+ id_DESC
+ total_ASC
+ total_DESC
+ charge_ASC
+ charge_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type OrderPreviousValues {
+ id: ID!
+ total: Int!
+ charge: String!
+}
+
+type OrderSubscriptionPayload {
+ mutation: MutationType!
+ node: Order
+ updatedFields: [String!]
+ previousValues: OrderPreviousValues
+}
+
+input OrderSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: OrderWhereInput
+}
+
+input OrderUpdateInput {
+ total: Int
+ charge: String
+ items: OrderItemUpdateManyInput
+ user: UserUpdateOneInput
+}
+
+input OrderWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ total: Int
+
+ """All values that are not equal to given value."""
+ total_not: Int
+
+ """All values that are contained in given list."""
+ total_in: [Int!]
+
+ """All values that are not contained in given list."""
+ total_not_in: [Int!]
+
+ """All values less than the given value."""
+ total_lt: Int
+
+ """All values less than or equal the given value."""
+ total_lte: Int
+
+ """All values greater than the given value."""
+ total_gt: Int
+
+ """All values greater than or equal the given value."""
+ total_gte: Int
+ charge: String
+
+ """All values that are not equal to given value."""
+ charge_not: String
+
+ """All values that are contained in given list."""
+ charge_in: [String!]
+
+ """All values that are not contained in given list."""
+ charge_not_in: [String!]
+
+ """All values less than the given value."""
+ charge_lt: String
+
+ """All values less than or equal the given value."""
+ charge_lte: String
+
+ """All values greater than the given value."""
+ charge_gt: String
+
+ """All values greater than or equal the given value."""
+ charge_gte: String
+
+ """All values containing the given string."""
+ charge_contains: String
+
+ """All values not containing the given string."""
+ charge_not_contains: String
+
+ """All values starting with the given string."""
+ charge_starts_with: String
+
+ """All values not starting with the given string."""
+ charge_not_starts_with: String
+
+ """All values ending with the given string."""
+ charge_ends_with: String
+
+ """All values not ending with the given string."""
+ charge_not_ends_with: String
+ items_every: OrderItemWhereInput
+ items_some: OrderItemWhereInput
+ items_none: OrderItemWhereInput
+ user: UserWhereInput
+}
+
+input OrderWhereUniqueInput {
+ id: ID
+}
+
+"""Information about pagination in a connection."""
+type PageInfo {
+ """When paginating forwards, are there more items?"""
+ hasNextPage: Boolean!
+
+ """When paginating backwards, are there more items?"""
+ hasPreviousPage: Boolean!
+
+ """When paginating backwards, the cursor to continue."""
+ startCursor: String
+
+ """When paginating forwards, the cursor to continue."""
+ endCursor: String
+}
+
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type Query {
+ cartItems(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [CartItem]!
+ orders(where: OrderWhereInput, orderBy: OrderOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Order]!
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Item]!
+ orderItems(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [OrderItem]!
+ users(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [User]!
+ cartItem(where: CartItemWhereUniqueInput!): CartItem
+ order(where: OrderWhereUniqueInput!): Order
+ item(where: ItemWhereUniqueInput!): Item
+ orderItem(where: OrderItemWhereUniqueInput!): OrderItem
+ user(where: UserWhereUniqueInput!): User
+ cartItemsConnection(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): CartItemConnection!
+ ordersConnection(where: OrderWhereInput, orderBy: OrderOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): OrderConnection!
+ itemsConnection(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): ItemConnection!
+ orderItemsConnection(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): OrderItemConnection!
+ usersConnection(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): UserConnection!
+
+ """Fetches an object given its ID"""
+ node(
+ """The ID of an object"""
+ id: ID!
+ ): Node
+}
+
+type Subscription {
+ cartItem(where: CartItemSubscriptionWhereInput): CartItemSubscriptionPayload
+ order(where: OrderSubscriptionWhereInput): OrderSubscriptionPayload
+ item(where: ItemSubscriptionWhereInput): ItemSubscriptionPayload
+ orderItem(where: OrderItemSubscriptionWhereInput): OrderItemSubscriptionPayload
+ user(where: UserSubscriptionWhereInput): UserSubscriptionPayload
+}
+
+type User implements Node {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+ cart(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [CartItem!]
+}
+
+"""A connection to a list of items."""
+type UserConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [UserEdge]!
+ aggregate: AggregateUser!
+}
+
+input UserCreateInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+ cart: CartItemCreateManyWithoutUserInput
+}
+
+input UserCreateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreateOneWithoutCartInput {
+ create: UserCreateWithoutCartInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserCreateWithoutCartInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+}
+
+"""An edge in a connection."""
+type UserEdge {
+ """The item at the end of the edge."""
+ node: User!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum UserOrderByInput {
+ id_ASC
+ id_DESC
+ name_ASC
+ name_DESC
+ email_ASC
+ email_DESC
+ password_ASC
+ password_DESC
+ resetToken_ASC
+ resetToken_DESC
+ resetTokenExpiry_ASC
+ resetTokenExpiry_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type UserPreviousValues {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+}
+
+type UserSubscriptionPayload {
+ mutation: MutationType!
+ node: User
+ updatedFields: [String!]
+ previousValues: UserPreviousValues
+}
+
+input UserSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: UserWhereInput
+}
+
+input UserUpdateDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+ cart: CartItemUpdateManyWithoutUserInput
+}
+
+input UserUpdateInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+ cart: CartItemUpdateManyWithoutUserInput
+}
+
+input UserUpdateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+ delete: Boolean
+ update: UserUpdateDataInput
+ upsert: UserUpsertNestedInput
+}
+
+input UserUpdateOneWithoutCartInput {
+ create: UserCreateWithoutCartInput
+ connect: UserWhereUniqueInput
+ delete: Boolean
+ update: UserUpdateWithoutCartDataInput
+ upsert: UserUpsertWithoutCartInput
+}
+
+input UserUpdatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserUpdateWithoutCartDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+}
+
+input UserUpsertNestedInput {
+ update: UserUpdateDataInput!
+ create: UserCreateInput!
+}
+
+input UserUpsertWithoutCartInput {
+ update: UserUpdateWithoutCartDataInput!
+ create: UserCreateWithoutCartInput!
+}
+
+input UserWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ name: String
+
+ """All values that are not equal to given value."""
+ name_not: String
+
+ """All values that are contained in given list."""
+ name_in: [String!]
+
+ """All values that are not contained in given list."""
+ name_not_in: [String!]
+
+ """All values less than the given value."""
+ name_lt: String
+
+ """All values less than or equal the given value."""
+ name_lte: String
+
+ """All values greater than the given value."""
+ name_gt: String
+
+ """All values greater than or equal the given value."""
+ name_gte: String
+
+ """All values containing the given string."""
+ name_contains: String
+
+ """All values not containing the given string."""
+ name_not_contains: String
+
+ """All values starting with the given string."""
+ name_starts_with: String
+
+ """All values not starting with the given string."""
+ name_not_starts_with: String
+
+ """All values ending with the given string."""
+ name_ends_with: String
+
+ """All values not ending with the given string."""
+ name_not_ends_with: String
+ email: String
+
+ """All values that are not equal to given value."""
+ email_not: String
+
+ """All values that are contained in given list."""
+ email_in: [String!]
+
+ """All values that are not contained in given list."""
+ email_not_in: [String!]
+
+ """All values less than the given value."""
+ email_lt: String
+
+ """All values less than or equal the given value."""
+ email_lte: String
+
+ """All values greater than the given value."""
+ email_gt: String
+
+ """All values greater than or equal the given value."""
+ email_gte: String
+
+ """All values containing the given string."""
+ email_contains: String
+
+ """All values not containing the given string."""
+ email_not_contains: String
+
+ """All values starting with the given string."""
+ email_starts_with: String
+
+ """All values not starting with the given string."""
+ email_not_starts_with: String
+
+ """All values ending with the given string."""
+ email_ends_with: String
+
+ """All values not ending with the given string."""
+ email_not_ends_with: String
+ password: String
+
+ """All values that are not equal to given value."""
+ password_not: String
+
+ """All values that are contained in given list."""
+ password_in: [String!]
+
+ """All values that are not contained in given list."""
+ password_not_in: [String!]
+
+ """All values less than the given value."""
+ password_lt: String
+
+ """All values less than or equal the given value."""
+ password_lte: String
+
+ """All values greater than the given value."""
+ password_gt: String
+
+ """All values greater than or equal the given value."""
+ password_gte: String
+
+ """All values containing the given string."""
+ password_contains: String
+
+ """All values not containing the given string."""
+ password_not_contains: String
+
+ """All values starting with the given string."""
+ password_starts_with: String
+
+ """All values not starting with the given string."""
+ password_not_starts_with: String
+
+ """All values ending with the given string."""
+ password_ends_with: String
+
+ """All values not ending with the given string."""
+ password_not_ends_with: String
+ resetToken: String
+
+ """All values that are not equal to given value."""
+ resetToken_not: String
+
+ """All values that are contained in given list."""
+ resetToken_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetToken_not_in: [String!]
+
+ """All values less than the given value."""
+ resetToken_lt: String
+
+ """All values less than or equal the given value."""
+ resetToken_lte: String
+
+ """All values greater than the given value."""
+ resetToken_gt: String
+
+ """All values greater than or equal the given value."""
+ resetToken_gte: String
+
+ """All values containing the given string."""
+ resetToken_contains: String
+
+ """All values not containing the given string."""
+ resetToken_not_contains: String
+
+ """All values starting with the given string."""
+ resetToken_starts_with: String
+
+ """All values not starting with the given string."""
+ resetToken_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetToken_ends_with: String
+
+ """All values not ending with the given string."""
+ resetToken_not_ends_with: String
+ resetTokenExpiry: String
+
+ """All values that are not equal to given value."""
+ resetTokenExpiry_not: String
+
+ """All values that are contained in given list."""
+ resetTokenExpiry_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetTokenExpiry_not_in: [String!]
+
+ """All values less than the given value."""
+ resetTokenExpiry_lt: String
+
+ """All values less than or equal the given value."""
+ resetTokenExpiry_lte: String
+
+ """All values greater than the given value."""
+ resetTokenExpiry_gt: String
+
+ """All values greater than or equal the given value."""
+ resetTokenExpiry_gte: String
+
+ """All values containing the given string."""
+ resetTokenExpiry_contains: String
+
+ """All values not containing the given string."""
+ resetTokenExpiry_not_contains: String
+
+ """All values starting with the given string."""
+ resetTokenExpiry_starts_with: String
+
+ """All values not starting with the given string."""
+ resetTokenExpiry_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetTokenExpiry_ends_with: String
+
+ """All values not ending with the given string."""
+ resetTokenExpiry_not_ends_with: String
+ cart_every: CartItemWhereInput
+ cart_some: CartItemWhereInput
+ cart_none: CartItemWhereInput
+}
+
+input UserWhereUniqueInput {
+ id: ID
+ email: String
+}
diff --git a/stepped-solutions/51/backend/src/resolvers/Mutation.js b/stepped-solutions/51/backend/src/resolvers/Mutation.js
new file mode 100755
index 0000000..5a75caf
--- /dev/null
+++ b/stepped-solutions/51/backend/src/resolvers/Mutation.js
@@ -0,0 +1,312 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+const { randomBytes } = require('crypto');
+const { promisify } = require('util');
+const { transport, makeANiceEmail } = require('../mail');
+const { hasPermission } = require('../utils');
+const stripe = require('../stripe');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in to do that!');
+ }
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ // This is how to create a relationship between the Item and the User
+ user: {
+ connect: {
+ id: ctx.request.userId,
+ },
+ },
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title user { id }}`);
+ // 2. Check if they own that item, or have the permissions
+ const ownsItem = item.user.id === ctx.request.userId;
+ const hasPermissions = ctx.request.user.permissions.some(permission =>
+ ['ADMIN', 'ITEMDELETE'].includes(permission)
+ );
+
+ if (!ownsItem && hasPermissions) {
+ throw new Error("You don't have permission to do that!");
+ }
+
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+ signout(parent, args, ctx, info) {
+ ctx.response.clearCookie('token');
+ return { message: 'Goodbye!' };
+ },
+ async requestReset(parent, args, ctx, info) {
+ // 1. Check if this is a real user
+ const user = await ctx.db.query.user({ where: { email: args.email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${args.email}`);
+ }
+ // 2. Set a reset token and expiry on that user
+ const randomBytesPromiseified = promisify(randomBytes);
+ const resetToken = (await randomBytesPromiseified(20)).toString('hex');
+ const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now
+ const res = await ctx.db.mutation.updateUser({
+ where: { email: args.email },
+ data: { resetToken, resetTokenExpiry },
+ });
+ // 3. Email them that reset token
+ const mailRes = await transport.sendMail({
+ from: 'wes@wesbos.com',
+ to: user.email,
+ subject: 'Your Password Reset Token',
+ html: makeANiceEmail(`Your Password Reset Token is here!
+ \n\n
+ <a href="${process.env
+ .FRONTEND_URL}/reset?resetToken=${resetToken}">Click Here to Reset</a>`),
+ });
+
+ // 4. Return the message
+ return { message: 'Thanks!' };
+ },
+ async resetPassword(parent, args, ctx, info) {
+ // 1. check if the passwords match
+ if (args.password !== args.confirmPassword) {
+ throw new Error("Yo Passwords don't match!");
+ }
+ // 2. check if its a legit reset token
+ // 3. Check if its expired
+ const [user] = await ctx.db.query.users({
+ where: {
+ resetToken: args.resetToken,
+ resetTokenExpiry_gte: Date.now() - 3600000,
+ },
+ });
+ if (!user) {
+ throw new Error('This token is either invalid or expired!');
+ }
+ // 4. Hash their new password
+ const password = await bcrypt.hash(args.password, 10);
+ // 5. Save the new password to the user and remove old resetToken fields
+ const updatedUser = await ctx.db.mutation.updateUser({
+ where: { email: user.email },
+ data: {
+ password,
+ resetToken: null,
+ resetTokenExpiry: null,
+ },
+ });
+ // 6. Generate JWT
+ const token = jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET);
+ // 7. Set the JWT cookie
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 8. return the new user
+ return updatedUser;
+ },
+ async updatePermissions(parent, args, ctx, info) {
+ // 1. Check if they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in!');
+ }
+ // 2. Query the current user
+ const currentUser = await ctx.db.query.user(
+ {
+ where: {
+ id: ctx.request.userId,
+ },
+ },
+ info
+ );
+ // 3. Check if they have permissions to do this
+ hasPermission(currentUser, ['ADMIN', 'PERMISSIONUPDATE']);
+ // 4. Update the permissions
+ return ctx.db.mutation.updateUser(
+ {
+ data: {
+ permissions: {
+ set: args.permissions,
+ },
+ },
+ where: {
+ id: args.userId,
+ },
+ },
+ info
+ );
+ },
+ async addToCart(parent, args, ctx, info) {
+ // 1. Make sure they are signed in
+ const { userId } = ctx.request;
+ if (!userId) {
+ throw new Error('You must be signed in soooon');
+ }
+ // 2. Query the users current cart
+ const [existingCartItem] = await ctx.db.query.cartItems({
+ where: {
+ user: { id: userId },
+ item: { id: args.id },
+ },
+ });
+ // 3. Check if that item is already in their cart and increment by 1 if it is
+ if (existingCartItem) {
+ console.log('This item is already in their cart');
+ return ctx.db.mutation.updateCartItem(
+ {
+ where: { id: existingCartItem.id },
+ data: { quantity: existingCartItem.quantity + 1 },
+ },
+ info
+ );
+ }
+ // 4. If its not, create a fresh CartItem for that user!
+ return ctx.db.mutation.createCartItem(
+ {
+ data: {
+ user: {
+ connect: { id: userId },
+ },
+ item: {
+ connect: { id: args.id },
+ },
+ },
+ },
+ info
+ );
+ },
+ async removeFromCart(parent, args, ctx, info) {
+ // 1. Find the cart item
+ const cartItem = await ctx.db.query.cartItem(
+ {
+ where: {
+ id: args.id,
+ },
+ },
+ `{ id, user { id }}`
+ );
+ // 1.5 Make sure we found an item
+ if (!cartItem) throw new Error('No CartItem Found!');
+ // 2. Make sure they own that cart item
+ if (cartItem.user.id !== ctx.request.userId) {
+ throw new Error('Cheatin huhhhh');
+ }
+ // 3. Delete that cart item
+ return ctx.db.mutation.deleteCartItem(
+ {
+ where: { id: args.id },
+ },
+ info
+ );
+ },
+ async createOrder(parent, args, ctx, info) {
+ // 1. Query the current user and make sure they are signed in
+ const { userId } = ctx.request;
+ if (!userId) throw new Error('You must be signed in to complete this order.');
+ const user = await ctx.db.query.user(
+ { where: { id: userId } },
+ `{
+ id
+ name
+ email
+ cart {
+ id
+ quantity
+ item { title price id description image }
+ }}`
+ );
+ // 2. recalculate the total for the price
+ const amount = user.cart.reduce(
+ (tally, cartItem) => tally + cartItem.item.price * cartItem.quantity,
+ 0
+ );
+ console.log(`Going to charge for a total of ${amount}`);
+ // 3. Create the stripe charge (turn token into $$$)
+ const charge = await stripe.charges.create({
+ amount,
+ currency: 'USD',
+ source: args.token,
+ });
+ // 4. Convert the CartItems to OrderItems
+ // 5. create the Order
+ // 6. Clean up - clear the users cart, delete cartItems
+ // 7. Return the Order to the client
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/51/backend/src/schema.graphql b/stepped-solutions/51/backend/src/schema.graphql
new file mode 100755
index 0000000..8b14185
--- /dev/null
+++ b/stepped-solutions/51/backend/src/schema.graphql
@@ -0,0 +1,36 @@
+# import * from './generated/prisma.graphql'
+
+type SuccessMessage {
+ message: String
+}
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+ signin(email: String!, password: String!): User!
+ signout: SuccessMessage
+ requestReset(email: String!): SuccessMessage
+ resetPassword(resetToken: String!, password: String!, confirmPassword: String!): User!
+ updatePermissions(permissions: [Permission], userId: ID!): User
+ addToCart(id: ID!): CartItem
+ removeFromCart(id: ID!): CartItem
+ createOrder(token: String!): Order!
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+ users: [User]!
+}
+
+type User{
+ id: ID!
+ name: String!
+ email: String!
+ permissions: [Permission!]!
+ cart: [CartItem!]!
+}
diff --git a/stepped-solutions/51/frontend/components/TakeMyMoney.js b/stepped-solutions/51/frontend/components/TakeMyMoney.js
new file mode 100755
index 0000000..be37df5
--- /dev/null
+++ b/stepped-solutions/51/frontend/components/TakeMyMoney.js
@@ -0,0 +1,72 @@
+import React from 'react';
+import StripeCheckout from 'react-stripe-checkout';
+import { Mutation } from 'react-apollo';
+import Router from 'next/router';
+import NProgress from 'nprogress';
+import PropTypes from 'prop-types';
+import gql from 'graphql-tag';
+import calcTotalPrice from '../lib/calcTotalPrice';
+import Error from './ErrorMessage';
+import User, { CURRENT_USER_QUERY } from './User';
+
+const CREATE_ORDER_MUTATION = gql`
+ mutation createOrder($token: String!) {
+ createOrder(token: $token) {
+ id
+ charge
+ total
+ items {
+ id
+ title
+ }
+ }
+ }
+`;
+
+function totalItems(cart) {
+ return cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0);
+}
+
+class TakeMyMoney extends React.Component {
+ onToken = (res, createOrder) => {
+ console.log('On Token Called!');
+ console.log(res.id);
+ // manually call the mutation once we have the stripe token
+ createOrder({
+ variables: {
+ token: res.id,
+ },
+ }).catch(err => {
+ alert(err.message);
+ });
+ };
+ render() {
+ return (
+ <User>
+ {({ data: { me } }) => (
+ <Mutation
+ mutation={CREATE_ORDER_MUTATION}
+ refetchQueries={[{ query: CURRENT_USER_QUERY }]}
+ >
+ {createOrder => (
+ <StripeCheckout
+ amount={calcTotalPrice(me.cart)}
+ name="Sick Fits"
+ description={`Order of ${totalItems(me.cart)} items!`}
+ image={me.cart[0].item && me.cart[0].item.image}
+ stripeKey="pk_test_Vtknn6vSdcZWSG2JWvEiWSqC"
+ currency="USD"
+ email={me.email}
+ token={res => this.onToken(res, createOrder)}
+ >
+ {this.props.children}
+ </StripeCheckout>
+ )}
+ </Mutation>
+ )}
+ </User>
+ );
+ }
+}
+
+export default TakeMyMoney;
diff --git a/stepped-solutions/52/backend/src/resolvers/Mutation.js b/stepped-solutions/52/backend/src/resolvers/Mutation.js
new file mode 100755
index 0000000..f0ea6a8
--- /dev/null
+++ b/stepped-solutions/52/backend/src/resolvers/Mutation.js
@@ -0,0 +1,337 @@
+const bcrypt = require('bcryptjs');
+const jwt = require('jsonwebtoken');
+const { randomBytes } = require('crypto');
+const { promisify } = require('util');
+const { transport, makeANiceEmail } = require('../mail');
+const { hasPermission } = require('../utils');
+const stripe = require('../stripe');
+
+const Mutations = {
+ async createItem(parent, args, ctx, info) {
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in to do that!');
+ }
+
+ const item = await ctx.db.mutation.createItem(
+ {
+ data: {
+ // This is how to create a relationship between the Item and the User
+ user: {
+ connect: {
+ id: ctx.request.userId,
+ },
+ },
+ ...args,
+ },
+ },
+ info
+ );
+
+ console.log(item);
+
+ return item;
+ },
+ updateItem(parent, args, ctx, info) {
+ // first take a copy of the updates
+ const updates = { ...args };
+ // remove the ID from the updates
+ delete updates.id;
+ // run the update method
+ return ctx.db.mutation.updateItem(
+ {
+ data: updates,
+ where: {
+ id: args.id,
+ },
+ },
+ info
+ );
+ },
+ async deleteItem(parent, args, ctx, info) {
+ const where = { id: args.id };
+ // 1. find the item
+ const item = await ctx.db.query.item({ where }, `{ id title user { id }}`);
+ // 2. Check if they own that item, or have the permissions
+ const ownsItem = item.user.id === ctx.request.userId;
+ const hasPermissions = ctx.request.user.permissions.some(permission =>
+ ['ADMIN', 'ITEMDELETE'].includes(permission)
+ );
+
+ if (!ownsItem && hasPermissions) {
+ throw new Error("You don't have permission to do that!");
+ }
+
+ // 3. Delete it!
+ return ctx.db.mutation.deleteItem({ where }, info);
+ },
+ async signup(parent, args, ctx, info) {
+ // lowercase their email
+ args.email = args.email.toLowerCase();
+ // hash their password
+ const password = await bcrypt.hash(args.password, 10);
+ // create the user in the database
+ const user = await ctx.db.mutation.createUser(
+ {
+ data: {
+ ...args,
+ password,
+ permissions: { set: ['USER'] },
+ },
+ },
+ info
+ );
+ // create the JWT token for them
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // We set the jwt as a cookie on the response
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365, // 1 year cookie
+ });
+ // Finalllllly we return the user to the browser
+ return user;
+ },
+ async signin(parent, { email, password }, ctx, info) {
+ // 1. check if there is a user with that email
+ const user = await ctx.db.query.user({ where: { email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${email}`);
+ }
+ // 2. Check if their password is correct
+ const valid = await bcrypt.compare(password, user.password);
+ if (!valid) {
+ throw new Error('Invalid Password!');
+ }
+ // 3. generate the JWT Token
+ const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
+ // 4. Set the cookie with the token
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 5. Return the user
+ return user;
+ },
+ signout(parent, args, ctx, info) {
+ ctx.response.clearCookie('token');
+ return { message: 'Goodbye!' };
+ },
+ async requestReset(parent, args, ctx, info) {
+ // 1. Check if this is a real user
+ const user = await ctx.db.query.user({ where: { email: args.email } });
+ if (!user) {
+ throw new Error(`No such user found for email ${args.email}`);
+ }
+ // 2. Set a reset token and expiry on that user
+ const randomBytesPromiseified = promisify(randomBytes);
+ const resetToken = (await randomBytesPromiseified(20)).toString('hex');
+ const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now
+ const res = await ctx.db.mutation.updateUser({
+ where: { email: args.email },
+ data: { resetToken, resetTokenExpiry },
+ });
+ // 3. Email them that reset token
+ const mailRes = await transport.sendMail({
+ from: 'wes@wesbos.com',
+ to: user.email,
+ subject: 'Your Password Reset Token',
+ html: makeANiceEmail(`Your Password Reset Token is here!
+ \n\n
+ <a href="${process.env
+ .FRONTEND_URL}/reset?resetToken=${resetToken}">Click Here to Reset</a>`),
+ });
+
+ // 4. Return the message
+ return { message: 'Thanks!' };
+ },
+ async resetPassword(parent, args, ctx, info) {
+ // 1. check if the passwords match
+ if (args.password !== args.confirmPassword) {
+ throw new Error("Yo Passwords don't match!");
+ }
+ // 2. check if its a legit reset token
+ // 3. Check if its expired
+ const [user] = await ctx.db.query.users({
+ where: {
+ resetToken: args.resetToken,
+ resetTokenExpiry_gte: Date.now() - 3600000,
+ },
+ });
+ if (!user) {
+ throw new Error('This token is either invalid or expired!');
+ }
+ // 4. Hash their new password
+ const password = await bcrypt.hash(args.password, 10);
+ // 5. Save the new password to the user and remove old resetToken fields
+ const updatedUser = await ctx.db.mutation.updateUser({
+ where: { email: user.email },
+ data: {
+ password,
+ resetToken: null,
+ resetTokenExpiry: null,
+ },
+ });
+ // 6. Generate JWT
+ const token = jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET);
+ // 7. Set the JWT cookie
+ ctx.response.cookie('token', token, {
+ httpOnly: true,
+ maxAge: 1000 * 60 * 60 * 24 * 365,
+ });
+ // 8. return the new user
+ return updatedUser;
+ },
+ async updatePermissions(parent, args, ctx, info) {
+ // 1. Check if they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in!');
+ }
+ // 2. Query the current user
+ const currentUser = await ctx.db.query.user(
+ {
+ where: {
+ id: ctx.request.userId,
+ },
+ },
+ info
+ );
+ // 3. Check if they have permissions to do this
+ hasPermission(currentUser, ['ADMIN', 'PERMISSIONUPDATE']);
+ // 4. Update the permissions
+ return ctx.db.mutation.updateUser(
+ {
+ data: {
+ permissions: {
+ set: args.permissions,
+ },
+ },
+ where: {
+ id: args.userId,
+ },
+ },
+ info
+ );
+ },
+ async addToCart(parent, args, ctx, info) {
+ // 1. Make sure they are signed in
+ const { userId } = ctx.request;
+ if (!userId) {
+ throw new Error('You must be signed in soooon');
+ }
+ // 2. Query the users current cart
+ const [existingCartItem] = await ctx.db.query.cartItems({
+ where: {
+ user: { id: userId },
+ item: { id: args.id },
+ },
+ });
+ // 3. Check if that item is already in their cart and increment by 1 if it is
+ if (existingCartItem) {
+ console.log('This item is already in their cart');
+ return ctx.db.mutation.updateCartItem(
+ {
+ where: { id: existingCartItem.id },
+ data: { quantity: existingCartItem.quantity + 1 },
+ },
+ info
+ );
+ }
+ // 4. If its not, create a fresh CartItem for that user!
+ return ctx.db.mutation.createCartItem(
+ {
+ data: {
+ user: {
+ connect: { id: userId },
+ },
+ item: {
+ connect: { id: args.id },
+ },
+ },
+ },
+ info
+ );
+ },
+ async removeFromCart(parent, args, ctx, info) {
+ // 1. Find the cart item
+ const cartItem = await ctx.db.query.cartItem(
+ {
+ where: {
+ id: args.id,
+ },
+ },
+ `{ id, user { id }}`
+ );
+ // 1.5 Make sure we found an item
+ if (!cartItem) throw new Error('No CartItem Found!');
+ // 2. Make sure they own that cart item
+ if (cartItem.user.id !== ctx.request.userId) {
+ throw new Error('Cheatin huhhhh');
+ }
+ // 3. Delete that cart item
+ return ctx.db.mutation.deleteCartItem(
+ {
+ where: { id: args.id },
+ },
+ info
+ );
+ },
+ async createOrder(parent, args, ctx, info) {
+ // 1. Query the current user and make sure they are signed in
+ const { userId } = ctx.request;
+ if (!userId) throw new Error('You must be signed in to complete this order.');
+ const user = await ctx.db.query.user(
+ { where: { id: userId } },
+ `{
+ id
+ name
+ email
+ cart {
+ id
+ quantity
+ item { title price id description image largeImage }
+ }}`
+ );
+ // 2. recalculate the total for the price
+ const amount = user.cart.reduce(
+ (tally, cartItem) => tally + cartItem.item.price * cartItem.quantity,
+ 0
+ );
+ console.log(`Going to charge for a total of ${amount}`);
+ // 3. Create the stripe charge (turn token into $$$)
+ const charge = await stripe.charges.create({
+ amount,
+ currency: 'USD',
+ source: args.token,
+ });
+ // 4. Convert the CartItems to OrderItems
+ const orderItems = user.cart.map(cartItem => {
+ const orderItem = {
+ ...cartItem.item,
+ quantity: cartItem.quantity,
+ user: { connect: { id: userId } },
+ };
+ delete orderItem.id;
+ return orderItem;
+ });
+
+ // 5. create the Order
+ const order = await ctx.db.mutation.createOrder({
+ data: {
+ total: charge.amount,
+ charge: charge.id,
+ items: { create: orderItems },
+ user: { connect: { id: userId } },
+ },
+ });
+ // 6. Clean up - clear the users cart, delete cartItems
+ const cartItemIds = user.cart.map(cartItem => cartItem.id);
+ await ctx.db.mutation.deleteManyCartItems({
+ where: {
+ id_in: cartItemIds,
+ },
+ });
+ // 7. Return the Order to the client
+ return order;
+ },
+};
+
+module.exports = Mutations;
diff --git a/stepped-solutions/52/frontend/components/TakeMyMoney.js b/stepped-solutions/52/frontend/components/TakeMyMoney.js
new file mode 100755
index 0000000..6135db5
--- /dev/null
+++ b/stepped-solutions/52/frontend/components/TakeMyMoney.js
@@ -0,0 +1,73 @@
+import React from 'react';
+import StripeCheckout from 'react-stripe-checkout';
+import { Mutation } from 'react-apollo';
+import Router from 'next/router';
+import NProgress from 'nprogress';
+import PropTypes from 'prop-types';
+import gql from 'graphql-tag';
+import calcTotalPrice from '../lib/calcTotalPrice';
+import Error from './ErrorMessage';
+import User, { CURRENT_USER_QUERY } from './User';
+
+const CREATE_ORDER_MUTATION = gql`
+ mutation createOrder($token: String!) {
+ createOrder(token: $token) {
+ id
+ charge
+ total
+ items {
+ id
+ title
+ }
+ }
+ }
+`;
+
+function totalItems(cart) {
+ return cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0);
+}
+
+class TakeMyMoney extends React.Component {
+ onToken = async (res, createOrder) => {
+ console.log('On Token Called!');
+ console.log(res.id);
+ // manually call the mutation once we have the stripe token
+ const order = await createOrder({
+ variables: {
+ token: res.id,
+ },
+ }).catch(err => {
+ alert(err.message);
+ });
+ console.log(order);
+ };
+ render() {
+ return (
+ <User>
+ {({ data: { me } }) => (
+ <Mutation
+ mutation={CREATE_ORDER_MUTATION}
+ refetchQueries={[{ query: CURRENT_USER_QUERY }]}
+ >
+ {createOrder => (
+ <StripeCheckout
+ amount={calcTotalPrice(me.cart)}
+ name="Sick Fits"
+ description={`Order of ${totalItems(me.cart)} items!`}
+ image={me.cart.length && me.cart[0].item && me.cart[0].item.image}
+ stripeKey="pk_test_Vtknn6vSdcZWSG2JWvEiWSqC"
+ currency="USD"
+ email={me.email}
+ token={res => this.onToken(res, createOrder)}
+ >
+ {this.props.children}
+ </StripeCheckout>
+ )}
+ </Mutation>
+ )}
+ </User>
+ );
+ }
+}
+
+export default TakeMyMoney;
diff --git a/stepped-solutions/53/backend/datamodel.graphql b/stepped-solutions/53/backend/datamodel.graphql
new file mode 100755
index 0000000..ce9ae38
--- /dev/null
+++ b/stepped-solutions/53/backend/datamodel.graphql
@@ -0,0 +1,57 @@
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type User {
+ id: ID! @unique
+ name: String!
+ email: String! @unique
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission]
+ cart: [CartItem!]!
+}
+
+type Item {
+ id: ID! @unique
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: User!
+}
+
+type CartItem {
+ id: ID! @unique
+ quantity: Int! @default(value: 1)
+ item: Item # relationship to Item
+ user: User! # relationship to User
+}
+
+type OrderItem {
+ id: ID! @unique
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int! @default(value: 1)
+ user: User
+}
+
+type Order {
+ id: ID! @unique
+ items: [OrderItem!]!
+ total: Int!
+ user: User!
+ charge: String!
+ createdAt: DateTime!
+ updatedAt: DateTime!
+}
diff --git a/stepped-solutions/53/backend/src/generated/prisma.graphql b/stepped-solutions/53/backend/src/generated/prisma.graphql
new file mode 100755
index 0000000..067c87e
--- /dev/null
+++ b/stepped-solutions/53/backend/src/generated/prisma.graphql
@@ -0,0 +1,1855 @@
+# source: https://us1.prisma.sh/wesbos/siccccccccck-fits/dev
+# timestamp: Fri Aug 24 2018 14:33:54 GMT-0400 (EDT)
+
+type AggregateCartItem {
+ count: Int!
+}
+
+type AggregateItem {
+ count: Int!
+}
+
+type AggregateOrder {
+ count: Int!
+}
+
+type AggregateOrderItem {
+ count: Int!
+}
+
+type AggregateUser {
+ count: Int!
+}
+
+type BatchPayload {
+ """The number of nodes that have been affected by the Batch operation."""
+ count: Long!
+}
+
+type CartItem implements Node {
+ id: ID!
+ quantity: Int!
+ item(where: ItemWhereInput): Item
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type CartItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [CartItemEdge]!
+ aggregate: AggregateCartItem!
+}
+
+input CartItemCreateInput {
+ quantity: Int
+ item: ItemCreateOneInput
+ user: UserCreateOneWithoutCartInput!
+}
+
+input CartItemCreateManyWithoutUserInput {
+ create: [CartItemCreateWithoutUserInput!]
+ connect: [CartItemWhereUniqueInput!]
+}
+
+input CartItemCreateWithoutUserInput {
+ quantity: Int
+ item: ItemCreateOneInput
+}
+
+"""An edge in a connection."""
+type CartItemEdge {
+ """The item at the end of the edge."""
+ node: CartItem!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum CartItemOrderByInput {
+ id_ASC
+ id_DESC
+ quantity_ASC
+ quantity_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type CartItemPreviousValues {
+ id: ID!
+ quantity: Int!
+}
+
+type CartItemSubscriptionPayload {
+ mutation: MutationType!
+ node: CartItem
+ updatedFields: [String!]
+ previousValues: CartItemPreviousValues
+}
+
+input CartItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [CartItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [CartItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [CartItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: CartItemWhereInput
+}
+
+input CartItemUpdateInput {
+ quantity: Int
+ item: ItemUpdateOneInput
+ user: UserUpdateOneWithoutCartInput
+}
+
+input CartItemUpdateManyWithoutUserInput {
+ create: [CartItemCreateWithoutUserInput!]
+ connect: [CartItemWhereUniqueInput!]
+ disconnect: [CartItemWhereUniqueInput!]
+ delete: [CartItemWhereUniqueInput!]
+ update: [CartItemUpdateWithWhereUniqueWithoutUserInput!]
+ upsert: [CartItemUpsertWithWhereUniqueWithoutUserInput!]
+}
+
+input CartItemUpdateWithoutUserDataInput {
+ quantity: Int
+ item: ItemUpdateOneInput
+}
+
+input CartItemUpdateWithWhereUniqueWithoutUserInput {
+ where: CartItemWhereUniqueInput!
+ data: CartItemUpdateWithoutUserDataInput!
+}
+
+input CartItemUpsertWithWhereUniqueWithoutUserInput {
+ where: CartItemWhereUniqueInput!
+ update: CartItemUpdateWithoutUserDataInput!
+ create: CartItemCreateWithoutUserInput!
+}
+
+input CartItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [CartItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [CartItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [CartItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ quantity: Int
+
+ """All values that are not equal to given value."""
+ quantity_not: Int
+
+ """All values that are contained in given list."""
+ quantity_in: [Int!]
+
+ """All values that are not contained in given list."""
+ quantity_not_in: [Int!]
+
+ """All values less than the given value."""
+ quantity_lt: Int
+
+ """All values less than or equal the given value."""
+ quantity_lte: Int
+
+ """All values greater than the given value."""
+ quantity_gt: Int
+
+ """All values greater than or equal the given value."""
+ quantity_gte: Int
+ item: ItemWhereInput
+ user: UserWhereInput
+}
+
+input CartItemWhereUniqueInput {
+ id: ID
+}
+
+scalar DateTime
+
+type Item implements Node {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type ItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [ItemEdge]!
+ aggregate: AggregateItem!
+}
+
+input ItemCreateInput {
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: UserCreateOneInput!
+}
+
+input ItemCreateOneInput {
+ create: ItemCreateInput
+ connect: ItemWhereUniqueInput
+}
+
+"""An edge in a connection."""
+type ItemEdge {
+ """The item at the end of the edge."""
+ node: Item!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum ItemOrderByInput {
+ id_ASC
+ id_DESC
+ title_ASC
+ title_DESC
+ description_ASC
+ description_DESC
+ image_ASC
+ image_DESC
+ largeImage_ASC
+ largeImage_DESC
+ price_ASC
+ price_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type ItemPreviousValues {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+}
+
+type ItemSubscriptionPayload {
+ mutation: MutationType!
+ node: Item
+ updatedFields: [String!]
+ previousValues: ItemPreviousValues
+}
+
+input ItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: ItemWhereInput
+}
+
+input ItemUpdateDataInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneInput
+}
+
+input ItemUpdateInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneInput
+}
+
+input ItemUpdateOneInput {
+ create: ItemCreateInput
+ connect: ItemWhereUniqueInput
+ disconnect: Boolean
+ delete: Boolean
+ update: ItemUpdateDataInput
+ upsert: ItemUpsertNestedInput
+}
+
+input ItemUpsertNestedInput {
+ update: ItemUpdateDataInput!
+ create: ItemCreateInput!
+}
+
+input ItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ title: String
+
+ """All values that are not equal to given value."""
+ title_not: String
+
+ """All values that are contained in given list."""
+ title_in: [String!]
+
+ """All values that are not contained in given list."""
+ title_not_in: [String!]
+
+ """All values less than the given value."""
+ title_lt: String
+
+ """All values less than or equal the given value."""
+ title_lte: String
+
+ """All values greater than the given value."""
+ title_gt: String
+
+ """All values greater than or equal the given value."""
+ title_gte: String
+
+ """All values containing the given string."""
+ title_contains: String
+
+ """All values not containing the given string."""
+ title_not_contains: String
+
+ """All values starting with the given string."""
+ title_starts_with: String
+
+ """All values not starting with the given string."""
+ title_not_starts_with: String
+
+ """All values ending with the given string."""
+ title_ends_with: String
+
+ """All values not ending with the given string."""
+ title_not_ends_with: String
+ description: String
+
+ """All values that are not equal to given value."""
+ description_not: String
+
+ """All values that are contained in given list."""
+ description_in: [String!]
+
+ """All values that are not contained in given list."""
+ description_not_in: [String!]
+
+ """All values less than the given value."""
+ description_lt: String
+
+ """All values less than or equal the given value."""
+ description_lte: String
+
+ """All values greater than the given value."""
+ description_gt: String
+
+ """All values greater than or equal the given value."""
+ description_gte: String
+
+ """All values containing the given string."""
+ description_contains: String
+
+ """All values not containing the given string."""
+ description_not_contains: String
+
+ """All values starting with the given string."""
+ description_starts_with: String
+
+ """All values not starting with the given string."""
+ description_not_starts_with: String
+
+ """All values ending with the given string."""
+ description_ends_with: String
+
+ """All values not ending with the given string."""
+ description_not_ends_with: String
+ image: String
+
+ """All values that are not equal to given value."""
+ image_not: String
+
+ """All values that are contained in given list."""
+ image_in: [String!]
+
+ """All values that are not contained in given list."""
+ image_not_in: [String!]
+
+ """All values less than the given value."""
+ image_lt: String
+
+ """All values less than or equal the given value."""
+ image_lte: String
+
+ """All values greater than the given value."""
+ image_gt: String
+
+ """All values greater than or equal the given value."""
+ image_gte: String
+
+ """All values containing the given string."""
+ image_contains: String
+
+ """All values not containing the given string."""
+ image_not_contains: String
+
+ """All values starting with the given string."""
+ image_starts_with: String
+
+ """All values not starting with the given string."""
+ image_not_starts_with: String
+
+ """All values ending with the given string."""
+ image_ends_with: String
+
+ """All values not ending with the given string."""
+ image_not_ends_with: String
+ largeImage: String
+
+ """All values that are not equal to given value."""
+ largeImage_not: String
+
+ """All values that are contained in given list."""
+ largeImage_in: [String!]
+
+ """All values that are not contained in given list."""
+ largeImage_not_in: [String!]
+
+ """All values less than the given value."""
+ largeImage_lt: String
+
+ """All values less than or equal the given value."""
+ largeImage_lte: String
+
+ """All values greater than the given value."""
+ largeImage_gt: String
+
+ """All values greater than or equal the given value."""
+ largeImage_gte: String
+
+ """All values containing the given string."""
+ largeImage_contains: String
+
+ """All values not containing the given string."""
+ largeImage_not_contains: String
+
+ """All values starting with the given string."""
+ largeImage_starts_with: String
+
+ """All values not starting with the given string."""
+ largeImage_not_starts_with: String
+
+ """All values ending with the given string."""
+ largeImage_ends_with: String
+
+ """All values not ending with the given string."""
+ largeImage_not_ends_with: String
+ price: Int
+
+ """All values that are not equal to given value."""
+ price_not: Int
+
+ """All values that are contained in given list."""
+ price_in: [Int!]
+
+ """All values that are not contained in given list."""
+ price_not_in: [Int!]
+
+ """All values less than the given value."""
+ price_lt: Int
+
+ """All values less than or equal the given value."""
+ price_lte: Int
+
+ """All values greater than the given value."""
+ price_gt: Int
+
+ """All values greater than or equal the given value."""
+ price_gte: Int
+ user: UserWhereInput
+}
+
+input ItemWhereUniqueInput {
+ id: ID
+}
+
+"""
+The `Long` scalar type represents non-fractional signed whole numeric values.
+Long can represent values between -(2^63) and 2^63 - 1.
+"""
+scalar Long
+
+type Mutation {
+ createCartItem(data: CartItemCreateInput!): CartItem!
+ createOrder(data: OrderCreateInput!): Order!
+ createItem(data: ItemCreateInput!): Item!
+ createOrderItem(data: OrderItemCreateInput!): OrderItem!
+ createUser(data: UserCreateInput!): User!
+ updateCartItem(data: CartItemUpdateInput!, where: CartItemWhereUniqueInput!): CartItem
+ updateOrder(data: OrderUpdateInput!, where: OrderWhereUniqueInput!): Order
+ updateItem(data: ItemUpdateInput!, where: ItemWhereUniqueInput!): Item
+ updateOrderItem(data: OrderItemUpdateInput!, where: OrderItemWhereUniqueInput!): OrderItem
+ updateUser(data: UserUpdateInput!, where: UserWhereUniqueInput!): User
+ deleteCartItem(where: CartItemWhereUniqueInput!): CartItem
+ deleteOrder(where: OrderWhereUniqueInput!): Order
+ deleteItem(where: ItemWhereUniqueInput!): Item
+ deleteOrderItem(where: OrderItemWhereUniqueInput!): OrderItem
+ deleteUser(where: UserWhereUniqueInput!): User
+ upsertCartItem(where: CartItemWhereUniqueInput!, create: CartItemCreateInput!, update: CartItemUpdateInput!): CartItem!
+ upsertOrder(where: OrderWhereUniqueInput!, create: OrderCreateInput!, update: OrderUpdateInput!): Order!
+ upsertItem(where: ItemWhereUniqueInput!, create: ItemCreateInput!, update: ItemUpdateInput!): Item!
+ upsertOrderItem(where: OrderItemWhereUniqueInput!, create: OrderItemCreateInput!, update: OrderItemUpdateInput!): OrderItem!
+ upsertUser(where: UserWhereUniqueInput!, create: UserCreateInput!, update: UserUpdateInput!): User!
+ updateManyCartItems(data: CartItemUpdateInput!, where: CartItemWhereInput): BatchPayload!
+ updateManyOrders(data: OrderUpdateInput!, where: OrderWhereInput): BatchPayload!
+ updateManyItems(data: ItemUpdateInput!, where: ItemWhereInput): BatchPayload!
+ updateManyOrderItems(data: OrderItemUpdateInput!, where: OrderItemWhereInput): BatchPayload!
+ updateManyUsers(data: UserUpdateInput!, where: UserWhereInput): BatchPayload!
+ deleteManyCartItems(where: CartItemWhereInput): BatchPayload!
+ deleteManyOrders(where: OrderWhereInput): BatchPayload!
+ deleteManyItems(where: ItemWhereInput): BatchPayload!
+ deleteManyOrderItems(where: OrderItemWhereInput): BatchPayload!
+ deleteManyUsers(where: UserWhereInput): BatchPayload!
+}
+
+enum MutationType {
+ CREATED
+ UPDATED
+ DELETED
+}
+
+"""An object with an ID"""
+interface Node {
+ """The id of the object."""
+ id: ID!
+}
+
+type Order implements Node {
+ id: ID!
+ items(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [OrderItem!]
+ total: Int!
+ user(where: UserWhereInput): User!
+ charge: String!
+ createdAt: DateTime!
+ updatedAt: DateTime!
+}
+
+"""A connection to a list of items."""
+type OrderConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [OrderEdge]!
+ aggregate: AggregateOrder!
+}
+
+input OrderCreateInput {
+ total: Int!
+ charge: String!
+ items: OrderItemCreateManyInput
+ user: UserCreateOneInput!
+}
+
+"""An edge in a connection."""
+type OrderEdge {
+ """The item at the end of the edge."""
+ node: Order!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+type OrderItem implements Node {
+ id: ID!
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int!
+ user(where: UserWhereInput): User
+}
+
+"""A connection to a list of items."""
+type OrderItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [OrderItemEdge]!
+ aggregate: AggregateOrderItem!
+}
+
+input OrderItemCreateInput {
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int
+ user: UserCreateOneInput
+}
+
+input OrderItemCreateManyInput {
+ create: [OrderItemCreateInput!]
+ connect: [OrderItemWhereUniqueInput!]
+}
+
+"""An edge in a connection."""
+type OrderItemEdge {
+ """The item at the end of the edge."""
+ node: OrderItem!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum OrderItemOrderByInput {
+ id_ASC
+ id_DESC
+ title_ASC
+ title_DESC
+ description_ASC
+ description_DESC
+ image_ASC
+ image_DESC
+ largeImage_ASC
+ largeImage_DESC
+ price_ASC
+ price_DESC
+ quantity_ASC
+ quantity_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type OrderItemPreviousValues {
+ id: ID!
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int!
+}
+
+type OrderItemSubscriptionPayload {
+ mutation: MutationType!
+ node: OrderItem
+ updatedFields: [String!]
+ previousValues: OrderItemPreviousValues
+}
+
+input OrderItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: OrderItemWhereInput
+}
+
+input OrderItemUpdateDataInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ quantity: Int
+ user: UserUpdateOneInput
+}
+
+input OrderItemUpdateInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ quantity: Int
+ user: UserUpdateOneInput
+}
+
+input OrderItemUpdateManyInput {
+ create: [OrderItemCreateInput!]
+ connect: [OrderItemWhereUniqueInput!]
+ disconnect: [OrderItemWhereUniqueInput!]
+ delete: [OrderItemWhereUniqueInput!]
+ update: [OrderItemUpdateWithWhereUniqueNestedInput!]
+ upsert: [OrderItemUpsertWithWhereUniqueNestedInput!]
+}
+
+input OrderItemUpdateWithWhereUniqueNestedInput {
+ where: OrderItemWhereUniqueInput!
+ data: OrderItemUpdateDataInput!
+}
+
+input OrderItemUpsertWithWhereUniqueNestedInput {
+ where: OrderItemWhereUniqueInput!
+ update: OrderItemUpdateDataInput!
+ create: OrderItemCreateInput!
+}
+
+input OrderItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ title: String
+
+ """All values that are not equal to given value."""
+ title_not: String
+
+ """All values that are contained in given list."""
+ title_in: [String!]
+
+ """All values that are not contained in given list."""
+ title_not_in: [String!]
+
+ """All values less than the given value."""
+ title_lt: String
+
+ """All values less than or equal the given value."""
+ title_lte: String
+
+ """All values greater than the given value."""
+ title_gt: String
+
+ """All values greater than or equal the given value."""
+ title_gte: String
+
+ """All values containing the given string."""
+ title_contains: String
+
+ """All values not containing the given string."""
+ title_not_contains: String
+
+ """All values starting with the given string."""
+ title_starts_with: String
+
+ """All values not starting with the given string."""
+ title_not_starts_with: String
+
+ """All values ending with the given string."""
+ title_ends_with: String
+
+ """All values not ending with the given string."""
+ title_not_ends_with: String
+ description: String
+
+ """All values that are not equal to given value."""
+ description_not: String
+
+ """All values that are contained in given list."""
+ description_in: [String!]
+
+ """All values that are not contained in given list."""
+ description_not_in: [String!]
+
+ """All values less than the given value."""
+ description_lt: String
+
+ """All values less than or equal the given value."""
+ description_lte: String
+
+ """All values greater than the given value."""
+ description_gt: String
+
+ """All values greater than or equal the given value."""
+ description_gte: String
+
+ """All values containing the given string."""
+ description_contains: String
+
+ """All values not containing the given string."""
+ description_not_contains: String
+
+ """All values starting with the given string."""
+ description_starts_with: String
+
+ """All values not starting with the given string."""
+ description_not_starts_with: String
+
+ """All values ending with the given string."""
+ description_ends_with: String
+
+ """All values not ending with the given string."""
+ description_not_ends_with: String
+ image: String
+
+ """All values that are not equal to given value."""
+ image_not: String
+
+ """All values that are contained in given list."""
+ image_in: [String!]
+
+ """All values that are not contained in given list."""
+ image_not_in: [String!]
+
+ """All values less than the given value."""
+ image_lt: String
+
+ """All values less than or equal the given value."""
+ image_lte: String
+
+ """All values greater than the given value."""
+ image_gt: String
+
+ """All values greater than or equal the given value."""
+ image_gte: String
+
+ """All values containing the given string."""
+ image_contains: String
+
+ """All values not containing the given string."""
+ image_not_contains: String
+
+ """All values starting with the given string."""
+ image_starts_with: String
+
+ """All values not starting with the given string."""
+ image_not_starts_with: String
+
+ """All values ending with the given string."""
+ image_ends_with: String
+
+ """All values not ending with the given string."""
+ image_not_ends_with: String
+ largeImage: String
+
+ """All values that are not equal to given value."""
+ largeImage_not: String
+
+ """All values that are contained in given list."""
+ largeImage_in: [String!]
+
+ """All values that are not contained in given list."""
+ largeImage_not_in: [String!]
+
+ """All values less than the given value."""
+ largeImage_lt: String
+
+ """All values less than or equal the given value."""
+ largeImage_lte: String
+
+ """All values greater than the given value."""
+ largeImage_gt: String
+
+ """All values greater than or equal the given value."""
+ largeImage_gte: String
+
+ """All values containing the given string."""
+ largeImage_contains: String
+
+ """All values not containing the given string."""
+ largeImage_not_contains: String
+
+ """All values starting with the given string."""
+ largeImage_starts_with: String
+
+ """All values not starting with the given string."""
+ largeImage_not_starts_with: String
+
+ """All values ending with the given string."""
+ largeImage_ends_with: String
+
+ """All values not ending with the given string."""
+ largeImage_not_ends_with: String
+ price: Int
+
+ """All values that are not equal to given value."""
+ price_not: Int
+
+ """All values that are contained in given list."""
+ price_in: [Int!]
+
+ """All values that are not contained in given list."""
+ price_not_in: [Int!]
+
+ """All values less than the given value."""
+ price_lt: Int
+
+ """All values less than or equal the given value."""
+ price_lte: Int
+
+ """All values greater than the given value."""
+ price_gt: Int
+
+ """All values greater than or equal the given value."""
+ price_gte: Int
+ quantity: Int
+
+ """All values that are not equal to given value."""
+ quantity_not: Int
+
+ """All values that are contained in given list."""
+ quantity_in: [Int!]
+
+ """All values that are not contained in given list."""
+ quantity_not_in: [Int!]
+
+ """All values less than the given value."""
+ quantity_lt: Int
+
+ """All values less than or equal the given value."""
+ quantity_lte: Int
+
+ """All values greater than the given value."""
+ quantity_gt: Int
+
+ """All values greater than or equal the given value."""
+ quantity_gte: Int
+ user: UserWhereInput
+}
+
+input OrderItemWhereUniqueInput {
+ id: ID
+}
+
+enum OrderOrderByInput {
+ id_ASC
+ id_DESC
+ total_ASC
+ total_DESC
+ charge_ASC
+ charge_DESC
+ createdAt_ASC
+ createdAt_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+}
+
+type OrderPreviousValues {
+ id: ID!
+ total: Int!
+ charge: String!
+ createdAt: DateTime!
+ updatedAt: DateTime!
+}
+
+type OrderSubscriptionPayload {
+ mutation: MutationType!
+ node: Order
+ updatedFields: [String!]
+ previousValues: OrderPreviousValues
+}
+
+input OrderSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: OrderWhereInput
+}
+
+input OrderUpdateInput {
+ total: Int
+ charge: String
+ items: OrderItemUpdateManyInput
+ user: UserUpdateOneInput
+}
+
+input OrderWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ total: Int
+
+ """All values that are not equal to given value."""
+ total_not: Int
+
+ """All values that are contained in given list."""
+ total_in: [Int!]
+
+ """All values that are not contained in given list."""
+ total_not_in: [Int!]
+
+ """All values less than the given value."""
+ total_lt: Int
+
+ """All values less than or equal the given value."""
+ total_lte: Int
+
+ """All values greater than the given value."""
+ total_gt: Int
+
+ """All values greater than or equal the given value."""
+ total_gte: Int
+ charge: String
+
+ """All values that are not equal to given value."""
+ charge_not: String
+
+ """All values that are contained in given list."""
+ charge_in: [String!]
+
+ """All values that are not contained in given list."""
+ charge_not_in: [String!]
+
+ """All values less than the given value."""
+ charge_lt: String
+
+ """All values less than or equal the given value."""
+ charge_lte: String
+
+ """All values greater than the given value."""
+ charge_gt: String
+
+ """All values greater than or equal the given value."""
+ charge_gte: String
+
+ """All values containing the given string."""
+ charge_contains: String
+
+ """All values not containing the given string."""
+ charge_not_contains: String
+
+ """All values starting with the given string."""
+ charge_starts_with: String
+
+ """All values not starting with the given string."""
+ charge_not_starts_with: String
+
+ """All values ending with the given string."""
+ charge_ends_with: String
+
+ """All values not ending with the given string."""
+ charge_not_ends_with: String
+ createdAt: DateTime
+
+ """All values that are not equal to given value."""
+ createdAt_not: DateTime
+
+ """All values that are contained in given list."""
+ createdAt_in: [DateTime!]
+
+ """All values that are not contained in given list."""
+ createdAt_not_in: [DateTime!]
+
+ """All values less than the given value."""
+ createdAt_lt: DateTime
+
+ """All values less than or equal the given value."""
+ createdAt_lte: DateTime
+
+ """All values greater than the given value."""
+ createdAt_gt: DateTime
+
+ """All values greater than or equal the given value."""
+ createdAt_gte: DateTime
+ updatedAt: DateTime
+
+ """All values that are not equal to given value."""
+ updatedAt_not: DateTime
+
+ """All values that are contained in given list."""
+ updatedAt_in: [DateTime!]
+
+ """All values that are not contained in given list."""
+ updatedAt_not_in: [DateTime!]
+
+ """All values less than the given value."""
+ updatedAt_lt: DateTime
+
+ """All values less than or equal the given value."""
+ updatedAt_lte: DateTime
+
+ """All values greater than the given value."""
+ updatedAt_gt: DateTime
+
+ """All values greater than or equal the given value."""
+ updatedAt_gte: DateTime
+ items_every: OrderItemWhereInput
+ items_some: OrderItemWhereInput
+ items_none: OrderItemWhereInput
+ user: UserWhereInput
+}
+
+input OrderWhereUniqueInput {
+ id: ID
+}
+
+"""Information about pagination in a connection."""
+type PageInfo {
+ """When paginating forwards, are there more items?"""
+ hasNextPage: Boolean!
+
+ """When paginating backwards, are there more items?"""
+ hasPreviousPage: Boolean!
+
+ """When paginating backwards, the cursor to continue."""
+ startCursor: String
+
+ """When paginating forwards, the cursor to continue."""
+ endCursor: String
+}
+
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type Query {
+ cartItems(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [CartItem]!
+ orders(where: OrderWhereInput, orderBy: OrderOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Order]!
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Item]!
+ orderItems(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [OrderItem]!
+ users(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [User]!
+ cartItem(where: CartItemWhereUniqueInput!): CartItem
+ order(where: OrderWhereUniqueInput!): Order
+ item(where: ItemWhereUniqueInput!): Item
+ orderItem(where: OrderItemWhereUniqueInput!): OrderItem
+ user(where: UserWhereUniqueInput!): User
+ cartItemsConnection(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): CartItemConnection!
+ ordersConnection(where: OrderWhereInput, orderBy: OrderOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): OrderConnection!
+ itemsConnection(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): ItemConnection!
+ orderItemsConnection(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): OrderItemConnection!
+ usersConnection(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): UserConnection!
+
+ """Fetches an object given its ID"""
+ node(
+ """The ID of an object"""
+ id: ID!
+ ): Node
+}
+
+type Subscription {
+ cartItem(where: CartItemSubscriptionWhereInput): CartItemSubscriptionPayload
+ order(where: OrderSubscriptionWhereInput): OrderSubscriptionPayload
+ item(where: ItemSubscriptionWhereInput): ItemSubscriptionPayload
+ orderItem(where: OrderItemSubscriptionWhereInput): OrderItemSubscriptionPayload
+ user(where: UserSubscriptionWhereInput): UserSubscriptionPayload
+}
+
+type User implements Node {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+ cart(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [CartItem!]
+}
+
+"""A connection to a list of items."""
+type UserConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [UserEdge]!
+ aggregate: AggregateUser!
+}
+
+input UserCreateInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+ cart: CartItemCreateManyWithoutUserInput
+}
+
+input UserCreateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreateOneWithoutCartInput {
+ create: UserCreateWithoutCartInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserCreateWithoutCartInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+}
+
+"""An edge in a connection."""
+type UserEdge {
+ """The item at the end of the edge."""
+ node: User!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum UserOrderByInput {
+ id_ASC
+ id_DESC
+ name_ASC
+ name_DESC
+ email_ASC
+ email_DESC
+ password_ASC
+ password_DESC
+ resetToken_ASC
+ resetToken_DESC
+ resetTokenExpiry_ASC
+ resetTokenExpiry_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type UserPreviousValues {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+}
+
+type UserSubscriptionPayload {
+ mutation: MutationType!
+ node: User
+ updatedFields: [String!]
+ previousValues: UserPreviousValues
+}
+
+input UserSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: UserWhereInput
+}
+
+input UserUpdateDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+ cart: CartItemUpdateManyWithoutUserInput
+}
+
+input UserUpdateInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+ cart: CartItemUpdateManyWithoutUserInput
+}
+
+input UserUpdateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+ delete: Boolean
+ update: UserUpdateDataInput
+ upsert: UserUpsertNestedInput
+}
+
+input UserUpdateOneWithoutCartInput {
+ create: UserCreateWithoutCartInput
+ connect: UserWhereUniqueInput
+ delete: Boolean
+ update: UserUpdateWithoutCartDataInput
+ upsert: UserUpsertWithoutCartInput
+}
+
+input UserUpdatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserUpdateWithoutCartDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+}
+
+input UserUpsertNestedInput {
+ update: UserUpdateDataInput!
+ create: UserCreateInput!
+}
+
+input UserUpsertWithoutCartInput {
+ update: UserUpdateWithoutCartDataInput!
+ create: UserCreateWithoutCartInput!
+}
+
+input UserWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ name: String
+
+ """All values that are not equal to given value."""
+ name_not: String
+
+ """All values that are contained in given list."""
+ name_in: [String!]
+
+ """All values that are not contained in given list."""
+ name_not_in: [String!]
+
+ """All values less than the given value."""
+ name_lt: String
+
+ """All values less than or equal the given value."""
+ name_lte: String
+
+ """All values greater than the given value."""
+ name_gt: String
+
+ """All values greater than or equal the given value."""
+ name_gte: String
+
+ """All values containing the given string."""
+ name_contains: String
+
+ """All values not containing the given string."""
+ name_not_contains: String
+
+ """All values starting with the given string."""
+ name_starts_with: String
+
+ """All values not starting with the given string."""
+ name_not_starts_with: String
+
+ """All values ending with the given string."""
+ name_ends_with: String
+
+ """All values not ending with the given string."""
+ name_not_ends_with: String
+ email: String
+
+ """All values that are not equal to given value."""
+ email_not: String
+
+ """All values that are contained in given list."""
+ email_in: [String!]
+
+ """All values that are not contained in given list."""
+ email_not_in: [String!]
+
+ """All values less than the given value."""
+ email_lt: String
+
+ """All values less than or equal the given value."""
+ email_lte: String
+
+ """All values greater than the given value."""
+ email_gt: String
+
+ """All values greater than or equal the given value."""
+ email_gte: String
+
+ """All values containing the given string."""
+ email_contains: String
+
+ """All values not containing the given string."""
+ email_not_contains: String
+
+ """All values starting with the given string."""
+ email_starts_with: String
+
+ """All values not starting with the given string."""
+ email_not_starts_with: String
+
+ """All values ending with the given string."""
+ email_ends_with: String
+
+ """All values not ending with the given string."""
+ email_not_ends_with: String
+ password: String
+
+ """All values that are not equal to given value."""
+ password_not: String
+
+ """All values that are contained in given list."""
+ password_in: [String!]
+
+ """All values that are not contained in given list."""
+ password_not_in: [String!]
+
+ """All values less than the given value."""
+ password_lt: String
+
+ """All values less than or equal the given value."""
+ password_lte: String
+
+ """All values greater than the given value."""
+ password_gt: String
+
+ """All values greater than or equal the given value."""
+ password_gte: String
+
+ """All values containing the given string."""
+ password_contains: String
+
+ """All values not containing the given string."""
+ password_not_contains: String
+
+ """All values starting with the given string."""
+ password_starts_with: String
+
+ """All values not starting with the given string."""
+ password_not_starts_with: String
+
+ """All values ending with the given string."""
+ password_ends_with: String
+
+ """All values not ending with the given string."""
+ password_not_ends_with: String
+ resetToken: String
+
+ """All values that are not equal to given value."""
+ resetToken_not: String
+
+ """All values that are contained in given list."""
+ resetToken_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetToken_not_in: [String!]
+
+ """All values less than the given value."""
+ resetToken_lt: String
+
+ """All values less than or equal the given value."""
+ resetToken_lte: String
+
+ """All values greater than the given value."""
+ resetToken_gt: String
+
+ """All values greater than or equal the given value."""
+ resetToken_gte: String
+
+ """All values containing the given string."""
+ resetToken_contains: String
+
+ """All values not containing the given string."""
+ resetToken_not_contains: String
+
+ """All values starting with the given string."""
+ resetToken_starts_with: String
+
+ """All values not starting with the given string."""
+ resetToken_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetToken_ends_with: String
+
+ """All values not ending with the given string."""
+ resetToken_not_ends_with: String
+ resetTokenExpiry: String
+
+ """All values that are not equal to given value."""
+ resetTokenExpiry_not: String
+
+ """All values that are contained in given list."""
+ resetTokenExpiry_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetTokenExpiry_not_in: [String!]
+
+ """All values less than the given value."""
+ resetTokenExpiry_lt: String
+
+ """All values less than or equal the given value."""
+ resetTokenExpiry_lte: String
+
+ """All values greater than the given value."""
+ resetTokenExpiry_gt: String
+
+ """All values greater than or equal the given value."""
+ resetTokenExpiry_gte: String
+
+ """All values containing the given string."""
+ resetTokenExpiry_contains: String
+
+ """All values not containing the given string."""
+ resetTokenExpiry_not_contains: String
+
+ """All values starting with the given string."""
+ resetTokenExpiry_starts_with: String
+
+ """All values not starting with the given string."""
+ resetTokenExpiry_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetTokenExpiry_ends_with: String
+
+ """All values not ending with the given string."""
+ resetTokenExpiry_not_ends_with: String
+ cart_every: CartItemWhereInput
+ cart_some: CartItemWhereInput
+ cart_none: CartItemWhereInput
+}
+
+input UserWhereUniqueInput {
+ id: ID
+ email: String
+}
diff --git a/stepped-solutions/53/backend/src/resolvers/Query.js b/stepped-solutions/53/backend/src/resolvers/Query.js
new file mode 100755
index 0000000..8e0f169
--- /dev/null
+++ b/stepped-solutions/53/backend/src/resolvers/Query.js
@@ -0,0 +1,55 @@
+const { forwardTo } = require('prisma-binding');
+const { hasPermission } = require('../utils');
+
+const Query = {
+ items: forwardTo('db'),
+ item: forwardTo('db'),
+ itemsConnection: forwardTo('db'),
+ me(parent, args, ctx, info) {
+ // check if there is a current user ID
+ if (!ctx.request.userId) {
+ return null;
+ }
+ return ctx.db.query.user(
+ {
+ where: { id: ctx.request.userId },
+ },
+ info
+ );
+ },
+ async users(parent, args, ctx, info) {
+ // 1. Check if they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in!');
+ }
+ console.log(ctx.request.userId);
+ // 2. Check if the user has the permissions to query all the users
+ hasPermission(ctx.request.user, ['ADMIN', 'PERMISSIONUPDATE']);
+
+ // 2. if they do, query all the users!
+ return ctx.db.query.users({}, info);
+ },
+ async order(parent, args, ctx, info) {
+ // 1. Make sure they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You arent logged in!');
+ }
+ // 2. Query the current order
+ const order = await ctx.db.query.order(
+ {
+ where: { id: args.id },
+ },
+ info
+ );
+ // 3. Check if the have the permissions to see this order
+ const ownsOrder = order.user.id === ctx.request.userId;
+ const hasPermissionToSeeOrder = ctx.request.user.permissions.includes('ADMIN');
+ if (!ownsOrder || !hasPermission) {
+ throw new Error('You cant see this buddd');
+ }
+ // 4. Return the order
+ return order;
+ },
+};
+
+module.exports = Query;
diff --git a/stepped-solutions/53/backend/src/schema.graphql b/stepped-solutions/53/backend/src/schema.graphql
new file mode 100755
index 0000000..15d119b
--- /dev/null
+++ b/stepped-solutions/53/backend/src/schema.graphql
@@ -0,0 +1,37 @@
+# import * from './generated/prisma.graphql'
+
+type SuccessMessage {
+ message: String
+}
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+ signin(email: String!, password: String!): User!
+ signout: SuccessMessage
+ requestReset(email: String!): SuccessMessage
+ resetPassword(resetToken: String!, password: String!, confirmPassword: String!): User!
+ updatePermissions(permissions: [Permission], userId: ID!): User
+ addToCart(id: ID!): CartItem
+ removeFromCart(id: ID!): CartItem
+ createOrder(token: String!): Order!
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+ users: [User]!
+ order(id: ID!): Order
+}
+
+type User{
+ id: ID!
+ name: String!
+ email: String!
+ permissions: [Permission!]!
+ cart: [CartItem!]!
+}
diff --git a/stepped-solutions/53/frontend/components/Cart.js b/stepped-solutions/53/frontend/components/Cart.js
new file mode 100755
index 0000000..2a72b38
--- /dev/null
+++ b/stepped-solutions/53/frontend/components/Cart.js
@@ -0,0 +1,66 @@
+import React from 'react';
+import { Query, Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import { adopt } from 'react-adopt';
+import User from './User';
+import CartStyles from './styles/CartStyles';
+import Supreme from './styles/Supreme';
+import CloseButton from './styles/CloseButton';
+import SickButton from './styles/SickButton';
+import CartItem from './CartItem';
+import calcTotalPrice from '../lib/calcTotalPrice';
+import formatMoney from '../lib/formatMoney';
+import TakeMyMoney from './TakeMyMoney';
+
+const LOCAL_STATE_QUERY = gql`
+ query {
+ cartOpen @client
+ }
+`;
+
+const TOGGLE_CART_MUTATION = gql`
+ mutation {
+ toggleCart @client
+ }
+`;
+/* eslint-disable */
+const Composed = adopt({
+ user: ({ render }) => <User>{render}</User>,
+ toggleCart: ({ render }) => <Mutation mutation={TOGGLE_CART_MUTATION}>{render}</Mutation>,
+ localState: ({ render }) => <Query query={LOCAL_STATE_QUERY}>{render}</Query>,
+});
+/* eslint-enable */
+
+const Cart = () => (
+ <Composed>
+ {({ user, toggleCart, localState }) => {
+ const me = user.data.me;
+ if (!me) return null;
+ return (
+ <CartStyles open={localState.data.cartOpen}>
+ <header>
+ <CloseButton onClick={toggleCart} title="close">
+ &times;
+ </CloseButton>
+ <Supreme>{me.name}'s Cart</Supreme>
+ <p>
+ You Have {me.cart.length} Item{me.cart.length === 1 ? '' : 's'} in your cart.
+ </p>
+ </header>
+ <ul>{me.cart.map(cartItem => <CartItem key={cartItem.id} cartItem={cartItem} />)}</ul>
+ <footer>
+ <p>{formatMoney(calcTotalPrice(me.cart))}</p>
+ {me.cart.length && (
+ <TakeMyMoney>
+ <SickButton>Checkout</SickButton>
+ </TakeMyMoney>
+ )}
+ </footer>
+ </CartStyles>
+ );
+ }}
+ </Composed>
+);
+
+export default Cart;
+export { LOCAL_STATE_QUERY, TOGGLE_CART_MUTATION };
diff --git a/stepped-solutions/53/frontend/components/Order.js b/stepped-solutions/53/frontend/components/Order.js
new file mode 100755
index 0000000..f2a2caf
--- /dev/null
+++ b/stepped-solutions/53/frontend/components/Order.js
@@ -0,0 +1,91 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Query } from 'react-apollo';
+import { format } from 'date-fns';
+import Head from 'next/head';
+import gql from 'graphql-tag';
+import formatMoney from '../lib/formatMoney';
+import Error from './ErrorMessage';
+import OrderStyles from './styles/OrderStyles';
+
+const SINGLE_ORDER_QUERY = gql`
+ query SINGLE_ORDER_QUERY($id: ID!) {
+ order(id: $id) {
+ id
+ charge
+ total
+ createdAt
+ user {
+ id
+ }
+ items {
+ id
+ title
+ description
+ price
+ image
+ quantity
+ }
+ }
+ }
+`;
+
+class Order extends React.Component {
+ static propTypes = {
+ id: PropTypes.string.isRequired,
+ };
+ render() {
+ return (
+ <Query query={SINGLE_ORDER_QUERY} variables={{ id: this.props.id }}>
+ {({ data, error, loading }) => {
+ if (error) return <Error error={error} />;
+ if (loading) return <p>Loading...</p>;
+ const order = data.order;
+ return (
+ <OrderStyles>
+ <Head>
+ <title>Sick Fits - Order {order.id}</title>
+ </Head>
+ <p>
+ <span>Order ID:</span>
+ <span>{this.props.id}</span>
+ </p>
+ <p>
+ <span>Charge</span>
+ <span>{order.charge}</span>
+ </p>
+ <p>
+ <span>Date</span>
+ <span>{format(order.createdAt, 'MMMM d, YYYY h:mm a')}</span>
+ </p>
+ <p>
+ <span>Order Total</span>
+ <span>{formatMoney(order.total)}</span>
+ </p>
+ <p>
+ <span>Item Count</span>
+ <span>{order.items.length}</span>
+ </p>
+ <div className="items">
+ {order.items.map(item => (
+ <div className="order-item" key={item.id}>
+ <img src={item.image} alt={item.title} />
+ <div className="item-details">
+ <h2>{item.title}</h2>
+ <p>Qty: {item.quantity}</p>
+ <p>Each: {formatMoney(item.price)}</p>
+ <p>SubTotal: {formatMoney(item.price * item.quantity)}</p>
+ <p>{item.description}</p>
+ </div>
+ </div>
+ ))}
+ </div>
+ </OrderStyles>
+ );
+ }}
+ </Query>
+ );
+ }
+}
+
+export default Order;
diff --git a/stepped-solutions/53/frontend/components/Search.js b/stepped-solutions/53/frontend/components/Search.js
new file mode 100755
index 0000000..c29f93e
--- /dev/null
+++ b/stepped-solutions/53/frontend/components/Search.js
@@ -0,0 +1,94 @@
+import React from 'react';
+import Downshift, { resetIdCounter } from 'downshift';
+import Router from 'next/router';
+import { ApolloConsumer } from 'react-apollo';
+import gql from 'graphql-tag';
+import debounce from 'lodash.debounce';
+import { DropDown, DropDownItem, SearchStyles } from './styles/DropDown';
+
+const SEARCH_ITEMS_QUERY = gql`
+ query SEARCH_ITEMS_QUERY($searchTerm: String!) {
+ items(where: { OR: [{ title_contains: $searchTerm }, { description_contains: $searchTerm }] }) {
+ id
+ image
+ title
+ }
+ }
+`;
+
+function routeToItem(item) {
+ Router.push({
+ pathname: '/item',
+ query: {
+ id: item.id,
+ },
+ });
+}
+
+class AutoComplete extends React.Component {
+ state = {
+ items: [],
+ loading: false,
+ };
+ onChange = debounce(async (e, client) => {
+ console.log('Searching...');
+ // turn loading on
+ this.setState({ loading: true });
+ // Manually query apollo client
+ const res = await client.query({
+ query: SEARCH_ITEMS_QUERY,
+ variables: { searchTerm: e.target.value },
+ });
+ this.setState({
+ items: res.data.items,
+ loading: false,
+ });
+ }, 350);
+ render() {
+ resetIdCounter();
+ return (
+ <SearchStyles>
+ <Downshift onChange={routeToItem} itemToString={item => (item === null ? '' : item.title)}>
+ {({ getInputProps, getItemProps, isOpen, inputValue, highlightedIndex }) => (
+ <div>
+ <ApolloConsumer>
+ {client => (
+ <input
+ {...getInputProps({
+ type: 'search',
+ placeholder: 'Search For An Item',
+ id: 'search',
+ className: this.state.loading ? 'loading' : '',
+ onChange: e => {
+ e.persist();
+ this.onChange(e, client);
+ },
+ })}
+ />
+ )}
+ </ApolloConsumer>
+ {isOpen && (
+ <DropDown>
+ {this.state.items.map((item, index) => (
+ <DropDownItem
+ {...getItemProps({ item })}
+ key={item.id}
+ highlighted={index === highlightedIndex}
+ >
+ <img width="50" src={item.image} alt={item.title} />
+ {item.title}
+ </DropDownItem>
+ ))}
+ {!this.state.items.length &&
+ !this.state.loading && <DropDownItem> Nothing Found {inputValue}</DropDownItem>}
+ </DropDown>
+ )}
+ </div>
+ )}
+ </Downshift>
+ </SearchStyles>
+ );
+ }
+}
+
+export default AutoComplete;
diff --git a/stepped-solutions/53/frontend/components/TakeMyMoney.js b/stepped-solutions/53/frontend/components/TakeMyMoney.js
new file mode 100755
index 0000000..9d6614e
--- /dev/null
+++ b/stepped-solutions/53/frontend/components/TakeMyMoney.js
@@ -0,0 +1,77 @@
+import React from 'react';
+import StripeCheckout from 'react-stripe-checkout';
+import { Mutation } from 'react-apollo';
+import Router from 'next/router';
+import NProgress from 'nprogress';
+import PropTypes from 'prop-types';
+import gql from 'graphql-tag';
+import calcTotalPrice from '../lib/calcTotalPrice';
+import Error from './ErrorMessage';
+import User, { CURRENT_USER_QUERY } from './User';
+
+const CREATE_ORDER_MUTATION = gql`
+ mutation createOrder($token: String!) {
+ createOrder(token: $token) {
+ id
+ charge
+ total
+ items {
+ id
+ title
+ }
+ }
+ }
+`;
+
+function totalItems(cart) {
+ return cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0);
+}
+
+class TakeMyMoney extends React.Component {
+ onToken = async (res, createOrder) => {
+ NProgress.start();
+ console.log('On Token Called!');
+ console.log(res.id);
+ // manually call the mutation once we have the stripe token
+ const order = await createOrder({
+ variables: {
+ token: res.id,
+ },
+ }).catch(err => {
+ alert(err.message);
+ });
+ Router.push({
+ pathname: '/order',
+ query: { id: order.data.createOrder.id },
+ });
+ };
+ render() {
+ return (
+ <User>
+ {({ data: { me } }) => (
+ <Mutation
+ mutation={CREATE_ORDER_MUTATION}
+ refetchQueries={[{ query: CURRENT_USER_QUERY }]}
+ >
+ {createOrder => (
+ <StripeCheckout
+ amount={calcTotalPrice(me.cart)}
+ name="Sick Fits"
+ description={`Order of ${totalItems(me.cart)} items!`}
+ image={me.cart.length && me.cart[0].item && me.cart[0].item.image}
+ stripeKey="pk_test_Vtknn6vSdcZWSG2JWvEiWSqC"
+ currency="USD"
+ email={me.email}
+ token={res => this.onToken(res, createOrder)}
+ >
+ {this.props.children}
+ </StripeCheckout>
+ )}
+ </Mutation>
+ )}
+ </User>
+ );
+ }
+}
+
+export default TakeMyMoney;
diff --git a/stepped-solutions/53/frontend/components/styles/OrderStyles.js b/stepped-solutions/53/frontend/components/styles/OrderStyles.js
new file mode 100755
index 0000000..f461b70
--- /dev/null
+++ b/stepped-solutions/53/frontend/components/styles/OrderStyles.js
@@ -0,0 +1,37 @@
+import styled from 'styled-components';
+
+const OrderStyles = styled.div`
+ max-width: 1000px;
+ margin: 0 auto;
+ border: 1px solid ${props => props.theme.offWhite};
+ box-shadow: ${props => props.theme.bs};
+ padding: 2rem;
+ border-top: 10px solid red;
+ & > p {
+ display: grid;
+ grid-template-columns: 1fr 5fr;
+ margin: 0;
+ border-bottom: 1px solid ${props => props.theme.offWhite};
+ span {
+ padding: 1rem;
+ &:first-child {
+ font-weight: 900;
+ text-align: right;
+ }
+ }
+ }
+ .order-item {
+ border-bottom: 1px solid ${props => props.theme.offWhite};
+ display: grid;
+ grid-template-columns: 300px 1fr;
+ align-items: center;
+ grid-gap: 2rem;
+ margin: 2rem 0;
+ padding-bottom: 2rem;
+ img {
+ width: 100%;
+ object-fit: cover;
+ }
+ }
+`;
+export default OrderStyles;
diff --git a/stepped-solutions/53/frontend/pages/order.js b/stepped-solutions/53/frontend/pages/order.js
new file mode 100755
index 0000000..0fea0c6
--- /dev/null
+++ b/stepped-solutions/53/frontend/pages/order.js
@@ -0,0 +1,12 @@
+import PleaseSignIn from '../components/PleaseSignIn';
+import Order from '../components/Order';
+
+const OrderPage = props => (
+ <div>
+ <PleaseSignIn>
+ <Order id={props.query.id} />
+ </PleaseSignIn>
+ </div>
+);
+
+export default OrderPage;
diff --git a/stepped-solutions/54/backend/src/resolvers/Query.js b/stepped-solutions/54/backend/src/resolvers/Query.js
new file mode 100755
index 0000000..22a6414
--- /dev/null
+++ b/stepped-solutions/54/backend/src/resolvers/Query.js
@@ -0,0 +1,69 @@
+const { forwardTo } = require('prisma-binding');
+const { hasPermission } = require('../utils');
+
+const Query = {
+ items: forwardTo('db'),
+ item: forwardTo('db'),
+ itemsConnection: forwardTo('db'),
+ me(parent, args, ctx, info) {
+ // check if there is a current user ID
+ if (!ctx.request.userId) {
+ return null;
+ }
+ return ctx.db.query.user(
+ {
+ where: { id: ctx.request.userId },
+ },
+ info
+ );
+ },
+ async users(parent, args, ctx, info) {
+ // 1. Check if they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You must be logged in!');
+ }
+ console.log(ctx.request.userId);
+ // 2. Check if the user has the permissions to query all the users
+ hasPermission(ctx.request.user, ['ADMIN', 'PERMISSIONUPDATE']);
+
+ // 2. if they do, query all the users!
+ return ctx.db.query.users({}, info);
+ },
+ async order(parent, args, ctx, info) {
+ // 1. Make sure they are logged in
+ if (!ctx.request.userId) {
+ throw new Error('You arent logged in!');
+ }
+ // 2. Query the current order
+ const order = await ctx.db.query.order(
+ {
+ where: { id: args.id },
+ },
+ info
+ );
+ // 3. Check if the have the permissions to see this order
+ const ownsOrder = order.user.id === ctx.request.userId;
+ const hasPermissionToSeeOrder = ctx.request.user.permissions.includes('ADMIN');
+ if (!ownsOrder || !hasPermission) {
+ throw new Error('You cant see this buddd');
+ }
+ // 4. Return the order
+ return order;
+ },
+ async orders(parent, args, ctx, info) {
+ const { userId } = ctx.request;
+ if (!userId) {
+ throw new Error('you must be signed in!');
+ }
+ return ctx.db.query.orders(
+ {
+ where: {
+ user: { id: userId },
+ },
+ },
+ info
+ );
+ },
+};
+
+module.exports = Query;
diff --git a/stepped-solutions/54/backend/src/schema.graphql b/stepped-solutions/54/backend/src/schema.graphql
new file mode 100755
index 0000000..d9ab917
--- /dev/null
+++ b/stepped-solutions/54/backend/src/schema.graphql
@@ -0,0 +1,38 @@
+# import * from './generated/prisma.graphql'
+
+type SuccessMessage {
+ message: String
+}
+
+type Mutation {
+ createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item!
+ updateItem(id: ID!, title: String, description: String, price: Int): Item!
+ deleteItem(id: ID!): Item
+ signup(email: String!, password: String!, name: String!): User!
+ signin(email: String!, password: String!): User!
+ signout: SuccessMessage
+ requestReset(email: String!): SuccessMessage
+ resetPassword(resetToken: String!, password: String!, confirmPassword: String!): User!
+ updatePermissions(permissions: [Permission], userId: ID!): User
+ addToCart(id: ID!): CartItem
+ removeFromCart(id: ID!): CartItem
+ createOrder(token: String!): Order!
+}
+
+type Query {
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
+ item(where: ItemWhereUniqueInput!): Item
+ itemsConnection(where: ItemWhereInput): ItemConnection!
+ me: User
+ users: [User]!
+ order(id: ID!): Order
+ orders(orderBy: OrderOrderByInput): [Order]!
+}
+
+type User{
+ id: ID!
+ name: String!
+ email: String!
+ permissions: [Permission!]!
+ cart: [CartItem!]!
+}
diff --git a/stepped-solutions/54/frontend/components/OrderList.js b/stepped-solutions/54/frontend/components/OrderList.js
new file mode 100755
index 0000000..e2e22ff
--- /dev/null
+++ b/stepped-solutions/54/frontend/components/OrderList.js
@@ -0,0 +1,80 @@
+import React from 'react';
+import { Query } from 'react-apollo';
+import { formatDistance } from 'date-fns';
+import Link from 'next/link';
+import styled from 'styled-components';
+import gql from 'graphql-tag';
+import Error from './ErrorMessage';
+import formatMoney from '../lib/formatMoney';
+import OrderItemStyles from './styles/OrderItemStyles';
+
+const USER_ORDERS_QUERY = gql`
+ query USER_ORDERS_QUERY {
+ orders(orderBy: createdAt_DESC) {
+ id
+ total
+ createdAt
+ items {
+ id
+ title
+ price
+ description
+ quantity
+ image
+ }
+ }
+ }
+`;
+
+const orderUl = styled.ul`
+ display: grid;
+ grid-gap: 4rem;
+ grid-template-columns: repeat(auto-fit, minmax(40%, 1fr));
+`;
+
+class OrderList extends React.Component {
+ render() {
+ return (
+ <Query query={USER_ORDERS_QUERY}>
+ {({ data: { orders }, loading, error }) => {
+ if (loading) return <p>loading...</p>;
+ if (error) return <Error erorr={error} />;
+ console.log(orders);
+ return (
+ <div>
+ <h2>You have {orders.length} orders</h2>
+ <orderUl>
+ {orders.map(order => (
+ <OrderItemStyles key={order.id}>
+ <Link
+ href={{
+ pathname: '/order',
+ query: { id: order.id },
+ }}
+ >
+ <a>
+ <div className="order-meta">
+ <p>{order.items.reduce((a, b) => a + b.quantity, 0)} Items</p>
+ <p>{order.items.length} Products</p>
+ <p>{formatDistance(order.createdAt, new Date())}</p>
+ <p>{formatMoney(order.total)}</p>
+ </div>
+ <div className="images">
+ {order.items.map(item => (
+ <img key={item.id} src={item.image} alt={item.title} />
+ ))}
+ </div>
+ </a>
+ </Link>
+ </OrderItemStyles>
+ ))}
+ </orderUl>
+ </div>
+ );
+ }}
+ </Query>
+ );
+ }
+}
+
+export default OrderList;
diff --git a/stepped-solutions/54/frontend/pages/orders.js b/stepped-solutions/54/frontend/pages/orders.js
new file mode 100755
index 0000000..c65d80d
--- /dev/null
+++ b/stepped-solutions/54/frontend/pages/orders.js
@@ -0,0 +1,12 @@
+import PleaseSignIn from '../components/PleaseSignIn';
+import OrderList from '../components/OrderList';
+
+const OrderPage = props => (
+ <div>
+ <PleaseSignIn>
+ <OrderList />
+ </PleaseSignIn>
+ </div>
+);
+
+export default OrderPage;
diff --git a/stepped-solutions/56/frontend/__tests__/formatMoney.test.js b/stepped-solutions/56/frontend/__tests__/formatMoney.test.js
new file mode 100755
index 0000000..23d8183
--- /dev/null
+++ b/stepped-solutions/56/frontend/__tests__/formatMoney.test.js
@@ -0,0 +1,23 @@
+import formatMoney from '../lib/formatMoney';
+
+describe('formatMoney Function', () => {
+ it('works with fractional dollars', () => {
+ expect(formatMoney(1)).toEqual('$0.01');
+ expect(formatMoney(10)).toEqual('$0.10');
+ expect(formatMoney(9)).toEqual('$0.09');
+ expect(formatMoney(40)).toEqual('$0.40');
+ });
+
+ it('leaves cents off for whole dollars', () => {
+ expect(formatMoney(5000)).toEqual('$50');
+ expect(formatMoney(100)).toEqual('$1');
+ expect(formatMoney(50000000)).toEqual('$500,000');
+ });
+
+ it('works with whole and fractional dollars', () => {
+ expect(formatMoney(5012)).toEqual('$50.12');
+ expect(formatMoney(101)).toEqual('$1.01');
+ expect(formatMoney(110)).toEqual('$1.10');
+ expect(formatMoney(20893749823749823749)).toEqual('$208,937,498,237,498,240.00');
+ });
+});
diff --git a/stepped-solutions/56/frontend/__tests__/sample.test.js b/stepped-solutions/56/frontend/__tests__/sample.test.js
new file mode 100755
index 0000000..dbed94f
--- /dev/null
+++ b/stepped-solutions/56/frontend/__tests__/sample.test.js
@@ -0,0 +1,19 @@
+describe('sample test 101', () => {
+ it('works as expected', () => {
+ const age = 100;
+ expect(1).toEqual(1);
+ expect(age).toEqual(100);
+ });
+
+ it('handles ranges just fine', () => {
+ const age = 200;
+ expect(age).toBeGreaterThan(100);
+ });
+
+ it('makes a list of dog names', () => {
+ const dogs = ['snickers', 'hugo'];
+ expect(dogs).toEqual(dogs);
+ expect(dogs).toContain('snickers');
+ expect(dogs).toContain('snickers');
+ });
+});
diff --git a/stepped-solutions/57/frontend/__tests__/mocking.test.js b/stepped-solutions/57/frontend/__tests__/mocking.test.js
new file mode 100755
index 0000000..d0a05bf
--- /dev/null
+++ b/stepped-solutions/57/frontend/__tests__/mocking.test.js
@@ -0,0 +1,36 @@
+function Person(name, foods) {
+ this.name = name;
+ this.foods = foods;
+}
+
+Person.prototype.fetchFavFoods = function() {
+ return new Promise((resolve, reject) => {
+ // Simulate an API
+ setTimeout(() => resolve(this.foods), 2000);
+ });
+};
+
+describe('mocking learning', () => {
+ it('mocks a reg function', () => {
+ const fetchDogs = jest.fn();
+ fetchDogs('snickers');
+ expect(fetchDogs).toHaveBeenCalled();
+ expect(fetchDogs).toHaveBeenCalledWith('snickers');
+ fetchDogs('hugo');
+ expect(fetchDogs).toHaveBeenCalledTimes(2);
+ });
+
+ it('can create a person', () => {
+ const me = new Person('Wes', ['pizza', 'burgs']);
+ expect(me.name).toBe('Wes');
+ });
+
+ it('can fetch foods', async () => {
+ const me = new Person('Wes', ['pizza', 'burgs']);
+ // mock the favFoods function
+ me.fetchFavFoods = jest.fn().mockResolvedValue(['sushi', 'ramen']);
+ const favFoods = await me.fetchFavFoods();
+ console.log(favFoods);
+ expect(favFoods).toContain('sushi');
+ });
+});
diff --git a/stepped-solutions/59/frontend/__tests__/CartCount.test.js b/stepped-solutions/59/frontend/__tests__/CartCount.test.js
new file mode 100755
index 0000000..8ace3da
--- /dev/null
+++ b/stepped-solutions/59/frontend/__tests__/CartCount.test.js
@@ -0,0 +1,21 @@
+import { shallow, mount } from 'enzyme';
+import toJSON from 'enzyme-to-json';
+import CartCount from '../components/CartCount';
+
+describe('<CartCount/>', () => {
+ it('renders', () => {
+ shallow(<CartCount count={10} />);
+ });
+
+ it('matches the snapshot', () => {
+ const wrapper = shallow(<CartCount count={11} />);
+ expect(toJSON(wrapper)).toMatchSnapshot();
+ });
+
+ it('updates via props', () => {
+ const wrapper = shallow(<CartCount count={50} />);
+ expect(toJSON(wrapper)).toMatchSnapshot();
+ wrapper.setProps({ count: 10 });
+ expect(toJSON(wrapper)).toMatchSnapshot();
+ });
+});
diff --git a/stepped-solutions/59/frontend/__tests__/Item.test.js b/stepped-solutions/59/frontend/__tests__/Item.test.js
new file mode 100755
index 0000000..692b913
--- /dev/null
+++ b/stepped-solutions/59/frontend/__tests__/Item.test.js
@@ -0,0 +1,39 @@
+import ItemComponent from '../components/Item';
+import { shallow, mount } from 'enzyme';
+import toJSON from 'enzyme-to-json';
+
+const fakeItem = {
+ id: 'ABC123',
+ title: 'A Cool Item',
+ price: 4000,
+ description: 'This item is really cool!',
+ image: 'dog.jpg',
+ largeImage: 'largedog.jpg',
+};
+
+describe('<Item/>', () => {
+ it('renders and matches the snapshot', () => {
+ const wrapper = shallow(<ItemComponent item={fakeItem} />);
+ expect(toJSON(wrapper)).toMatchSnapshot();
+ });
+ // it('renders the image properly', () => {
+ // const wrapper = shallow(<ItemComponent item={fakeItem} />);
+ // const img = wrapper.find('img');
+ // expect(img.props().src).toBe(fakeItem.image);
+ // expect(img.props().alt).toBe(fakeItem.title);
+ // });
+ // it('renders the pricetag and title', () => {
+ // const wrapper = shallow(<ItemComponent item={fakeItem} />);
+ // const PriceTag = wrapper.find('PriceTag');
+ // expect(PriceTag.children().text()).toBe('$50');
+ // expect(wrapper.find('Title a').text()).toBe(fakeItem.title);
+ // });
+ // it('renders out the buttons properly', () => {
+ // const wrapper = shallow(<ItemComponent item={fakeItem} />);
+ // const buttonList = wrapper.find('.buttonList');
+ // expect(buttonList.children()).toHaveLength(3);
+ // expect(buttonList.find('Link')).toHaveLength(1);
+ // expect(buttonList.find('AddToCart').exists()).toBe(true);
+ // expect(buttonList.find('DeleteItem').exists()).toBe(true);
+ // });
+});
diff --git a/stepped-solutions/59/frontend/__tests__/__snapshots__/CartCount.test.js.snap b/stepped-solutions/59/frontend/__tests__/__snapshots__/CartCount.test.js.snap
new file mode 100755
index 0000000..92ee89a
--- /dev/null
+++ b/stepped-solutions/59/frontend/__tests__/__snapshots__/CartCount.test.js.snap
@@ -0,0 +1,79 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`<CartCount/> matches the snapshot 1`] = `
+<CartCount__AnimationStyles>
+ <TransitionGroup
+ childFactory={[Function]}
+ component="div"
+ >
+ <CSSTransition
+ className="count"
+ classNames="count"
+ key="11"
+ timeout={
+ Object {
+ "enter": 400,
+ "exit": 400,
+ }
+ }
+ unmountOnExit={true}
+ >
+ <CartCount__Dot>
+ 11
+ </CartCount__Dot>
+ </CSSTransition>
+ </TransitionGroup>
+</CartCount__AnimationStyles>
+`;
+
+exports[`<CartCount/> updates via props 1`] = `
+<CartCount__AnimationStyles>
+ <TransitionGroup
+ childFactory={[Function]}
+ component="div"
+ >
+ <CSSTransition
+ className="count"
+ classNames="count"
+ key="50"
+ timeout={
+ Object {
+ "enter": 400,
+ "exit": 400,
+ }
+ }
+ unmountOnExit={true}
+ >
+ <CartCount__Dot>
+ 50
+ </CartCount__Dot>
+ </CSSTransition>
+ </TransitionGroup>
+</CartCount__AnimationStyles>
+`;
+
+exports[`<CartCount/> updates via props 2`] = `
+<CartCount__AnimationStyles>
+ <TransitionGroup
+ childFactory={[Function]}
+ component="div"
+ >
+ <CSSTransition
+ className="count"
+ classNames="count"
+ key="10"
+ timeout={
+ Object {
+ "enter": 400,
+ "exit": 400,
+ }
+ }
+ unmountOnExit={true}
+ >
+ <CartCount__Dot>
+ 10
+ </CartCount__Dot>
+ </CSSTransition>
+ </TransitionGroup>
+</CartCount__AnimationStyles>
+`;
diff --git a/stepped-solutions/59/frontend/__tests__/__snapshots__/Item.test.js.snap b/stepped-solutions/59/frontend/__tests__/__snapshots__/Item.test.js.snap
new file mode 100755
index 0000000..70e4aa8
--- /dev/null
+++ b/stepped-solutions/59/frontend/__tests__/__snapshots__/Item.test.js.snap
@@ -0,0 +1,58 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`<Item/> renders and matches the snapshot 1`] = `
+<ItemStyles__Item>
+ <img
+ alt="A Cool Item"
+ src="dog.jpg"
+ />
+ <Title>
+ <Link
+ href={
+ Object {
+ "pathname": "/item",
+ "query": Object {
+ "id": "ABC123",
+ },
+ }
+ }
+ >
+ <a>
+ A Cool Item
+ </a>
+ </Link>
+ </Title>
+ <PriceTag>
+ $40
+ </PriceTag>
+ <p>
+ This item is really cool!
+ </p>
+ <div
+ className="buttonList"
+ >
+ <Link
+ href={
+ Object {
+ "pathname": "update",
+ "query": Object {
+ "id": "ABC123",
+ },
+ }
+ }
+ >
+ <a>
+ Edit ✏️
+ </a>
+ </Link>
+ <AddToCart
+ id="ABC123"
+ />
+ <DeleteItem
+ id="ABC123"
+ >
+ Delete This Item
+ </DeleteItem>
+ </div>
+</ItemStyles__Item>
+`;
diff --git a/stepped-solutions/60/frontend/__tests__/SingleItem.test.js b/stepped-solutions/60/frontend/__tests__/SingleItem.test.js
new file mode 100755
index 0000000..2963bde
--- /dev/null
+++ b/stepped-solutions/60/frontend/__tests__/SingleItem.test.js
@@ -0,0 +1,57 @@
+import { mount } from 'enzyme';
+import toJSON from 'enzyme-to-json';
+import wait from 'waait';
+import SingleItem, { SINGLE_ITEM_QUERY } from '../components/SingleItem';
+import { MockedProvider } from 'react-apollo/test-utils';
+import { fakeItem } from '../lib/testUtils';
+
+describe('<SingleItem/>', () => {
+ it('renders with proper data', async () => {
+ const mocks = [
+ {
+ // when someone makes a request with this query and variable combo
+ request: { query: SINGLE_ITEM_QUERY, variables: { id: '123' } },
+ // return this fake data (mocked data)
+ result: {
+ data: {
+ item: fakeItem(),
+ },
+ },
+ },
+ ];
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <SingleItem id="123" />
+ </MockedProvider>
+ );
+ expect(wrapper.text()).toContain('Loading...');
+ await wait();
+ wrapper.update();
+ // console.log(wrapper.debug());
+ expect(toJSON(wrapper.find('h2'))).toMatchSnapshot();
+ expect(toJSON(wrapper.find('img'))).toMatchSnapshot();
+ expect(toJSON(wrapper.find('p'))).toMatchSnapshot();
+ });
+
+ it('Errors with a not found item', async () => {
+ const mocks = [
+ {
+ request: { query: SINGLE_ITEM_QUERY, variables: { id: '123' } },
+ result: {
+ errors: [{ message: 'Items Not Found!' }],
+ },
+ },
+ ];
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <SingleItem id="123" />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ console.log(wrapper.debug());
+ const item = wrapper.find('[data-test="graphql-error"]');
+ expect(item.text()).toContain('Items Not Found!');
+ expect(toJSON(item)).toMatchSnapshot();
+ });
+});
diff --git a/stepped-solutions/60/frontend/__tests__/__snapshots__/SingleItem.test.js.snap b/stepped-solutions/60/frontend/__tests__/__snapshots__/SingleItem.test.js.snap
new file mode 100755
index 0000000..2f41d4c
--- /dev/null
+++ b/stepped-solutions/60/frontend/__tests__/__snapshots__/SingleItem.test.js.snap
@@ -0,0 +1,32 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`<SingleItem/> Errors with a not found item 1`] = `
+<p
+ data-test="graphql-error"
+>
+ <strong>
+ Shoot!
+ </strong>
+ Items Not Found!
+</p>
+`;
+
+exports[`<SingleItem/> renders with proper data 1`] = `
+<h2>
+ Viewing
+ dogs are best
+</h2>
+`;
+
+exports[`<SingleItem/> renders with proper data 2`] = `
+<img
+ alt="dogs are best"
+ src="dog.jpg"
+/>
+`;
+
+exports[`<SingleItem/> renders with proper data 3`] = `
+<p>
+ dogs
+</p>
+`;
diff --git a/stepped-solutions/60/frontend/components/SingleItem.js b/stepped-solutions/60/frontend/components/SingleItem.js
new file mode 100755
index 0000000..145b5ae
--- /dev/null
+++ b/stepped-solutions/60/frontend/components/SingleItem.js
@@ -0,0 +1,70 @@
+import React, { Component } from 'react';
+import gql from 'graphql-tag';
+import { Query } from 'react-apollo';
+import Error from './ErrorMessage';
+import styled from 'styled-components';
+import Head from 'next/head';
+
+const SingleItemStyles = styled.div`
+ max-width: 1200px;
+ margin: 2rem auto;
+ box-shadow: ${props => props.theme.bs};
+ display: grid;
+ grid-auto-columns: 1fr;
+ grid-auto-flow: column;
+ min-height: 800px;
+ img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+ }
+ .details {
+ margin: 3rem;
+ font-size: 2rem;
+ }
+`;
+
+const SINGLE_ITEM_QUERY = gql`
+ query SINGLE_ITEM_QUERY($id: ID!) {
+ item(where: { id: $id }) {
+ id
+ title
+ description
+ largeImage
+ }
+ }
+`;
+class SingleItem extends Component {
+ render() {
+ return (
+ <Query
+ query={SINGLE_ITEM_QUERY}
+ variables={{
+ id: this.props.id,
+ }}
+ >
+ {({ error, loading, data }) => {
+ if (error) return <Error error={error} />;
+ if (loading) return <p>Loading...</p>;
+ if (!data.item) return <p>No Item Found for {this.props.id}</p>;
+ const item = data.item;
+ return (
+ <SingleItemStyles>
+ <Head>
+ <title>Sick Fits | {item.title}</title>
+ </Head>
+ <img src={item.largeImage} alt={item.title} />
+ <div className="details">
+ <h2>Viewing {item.title}</h2>
+ <p>{item.description}</p>
+ </div>
+ </SingleItemStyles>
+ );
+ }}
+ </Query>
+ );
+ }
+}
+
+export default SingleItem;
+export { SINGLE_ITEM_QUERY };
diff --git a/stepped-solutions/62/frontend/__tests__/Nav.test.js b/stepped-solutions/62/frontend/__tests__/Nav.test.js
new file mode 100755
index 0000000..d30cb39
--- /dev/null
+++ b/stepped-solutions/62/frontend/__tests__/Nav.test.js
@@ -0,0 +1,76 @@
+import { mount } from 'enzyme';
+import wait from 'waait';
+import toJSON from 'enzyme-to-json';
+import Nav from '../components/Nav';
+import { CURRENT_USER_QUERY } from '../components/User';
+import { MockedProvider } from 'react-apollo/test-utils';
+import { fakeUser, fakeCartItem } from '../lib/testUtils';
+
+const notSignedInMocks = [
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: { data: { me: null } },
+ },
+];
+
+const signedInMocks = [
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: { data: { me: fakeUser() } },
+ },
+];
+
+const signedInMocksWithCartItems = [
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: {
+ data: {
+ me: {
+ ...fakeUser(),
+ cart: [fakeCartItem(), fakeCartItem(), fakeCartItem()],
+ },
+ },
+ },
+ },
+];
+
+describe('<Nav/>', () => {
+ it('renders a minimal nav when signed out', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={notSignedInMocks}>
+ <Nav />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ // console.log(wrapper.debug());
+ const nav = wrapper.find('ul[data-test="nav"]');
+ expect(toJSON(nav)).toMatchSnapshot();
+ });
+
+ it('renders full nav when signed in', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={signedInMocks}>
+ <Nav />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ const nav = wrapper.find('ul[data-test="nav"]');
+ expect(nav.children().length).toBe(6);
+ expect(nav.text()).toContain('Sign Out');
+ });
+
+ it('renders the amount of items in the cart', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={signedInMocksWithCartItems}>
+ <Nav />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ const nav = wrapper.find('[data-test="nav"]');
+ const count = nav.find('div.count');
+ expect(toJSON(count)).toMatchSnapshot();
+ });
+});
diff --git a/stepped-solutions/62/frontend/__tests__/Pagination.test.js b/stepped-solutions/62/frontend/__tests__/Pagination.test.js
new file mode 100755
index 0000000..7117db8
--- /dev/null
+++ b/stepped-solutions/62/frontend/__tests__/Pagination.test.js
@@ -0,0 +1,89 @@
+import { mount } from 'enzyme';
+import wait from 'waait';
+import toJSON from 'enzyme-to-json';
+import Router from 'next/router';
+import Pagination, { PAGINATION_QUERY } from '../components/Pagination';
+import { MockedProvider } from 'react-apollo/test-utils';
+
+Router.router = {
+ push() {},
+ prefetch() {},
+};
+
+function makeMocksFor(length) {
+ return [
+ {
+ request: { query: PAGINATION_QUERY },
+ result: {
+ data: {
+ itemsConnection: {
+ __typename: 'aggregate',
+ aggregate: {
+ count: length,
+ __typename: 'count',
+ },
+ },
+ },
+ },
+ },
+ ];
+}
+
+describe('<Pagination/>', () => {
+ it('displays a loading message', () => {
+ const wrapper = mount(
+ <MockedProvider mocks={makeMocksFor(1)}>
+ <Pagination page={1} />
+ </MockedProvider>
+ );
+ const pagination = wrapper.find('[data-test="pagination"]');
+ expect(wrapper.text()).toContain('Loading...');
+ });
+
+ it('renders pagination for 18 items', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={makeMocksFor(18)}>
+ <Pagination page={1} />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ expect(wrapper.find('.totalPages').text()).toEqual('5');
+ const pagination = wrapper.find('div[data-test="pagination"]');
+ expect(toJSON(pagination)).toMatchSnapshot();
+ });
+
+ it('disables prev button on first page', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={makeMocksFor(18)}>
+ <Pagination page={1} />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ expect(wrapper.find('a.prev').prop('aria-disabled')).toEqual(true);
+ expect(wrapper.find('a.next').prop('aria-disabled')).toEqual(false);
+ });
+ it('disables next button on last page', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={makeMocksFor(18)}>
+ <Pagination page={5} />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ expect(wrapper.find('a.prev').prop('aria-disabled')).toEqual(false);
+ expect(wrapper.find('a.next').prop('aria-disabled')).toEqual(true);
+ });
+ it('enables all buttons on a middle page', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={makeMocksFor(18)}>
+ <Pagination page={3} />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ expect(wrapper.find('a.prev').prop('aria-disabled')).toEqual(false);
+ expect(wrapper.find('a.next').prop('aria-disabled')).toEqual(false);
+ });
+});
diff --git a/stepped-solutions/62/frontend/__tests__/PleaseSignIn.test.js b/stepped-solutions/62/frontend/__tests__/PleaseSignIn.test.js
new file mode 100755
index 0000000..7d476b4
--- /dev/null
+++ b/stepped-solutions/62/frontend/__tests__/PleaseSignIn.test.js
@@ -0,0 +1,51 @@
+import { mount } from 'enzyme';
+import wait from 'waait';
+import PleaseSignIn from '../components/PleaseSignIn';
+import { CURRENT_USER_QUERY } from '../components/User';
+import { MockedProvider } from 'react-apollo/test-utils';
+import { fakeUser } from '../lib/testUtils';
+
+const notSignedInMocks = [
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: { data: { me: null } },
+ },
+];
+
+const signedInMocks = [
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: { data: { me: fakeUser() } },
+ },
+];
+
+describe('<PleaseSignIn/>', () => {
+ it('renders the sign in dialog to logged out users', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={notSignedInMocks}>
+ <PleaseSignIn />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ expect(wrapper.text()).toContain('Please Sign In before Continuing');
+ const SignIn = wrapper.find('Signin');
+ expect(SignIn.exists()).toBe(true);
+ });
+
+ it('renders the child component when the user is signed in', async () => {
+ const Hey = () => <p>Hey!</p>;
+ const wrapper = mount(
+ <MockedProvider mocks={signedInMocks}>
+ <PleaseSignIn>
+ <Hey />
+ </PleaseSignIn>
+ </MockedProvider>
+ );
+
+ await wait();
+ wrapper.update();
+ // expect(wrapper.find('Hey').exists()).toBe(true);
+ expect(wrapper.contains(<Hey />)).toBe(true);
+ });
+});
diff --git a/stepped-solutions/62/frontend/__tests__/__snapshots__/Nav.test.js.snap b/stepped-solutions/62/frontend/__tests__/__snapshots__/Nav.test.js.snap
new file mode 100755
index 0000000..9a5a14c
--- /dev/null
+++ b/stepped-solutions/62/frontend/__tests__/__snapshots__/Nav.test.js.snap
@@ -0,0 +1,37 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`<Nav/> renders a minimal nav when signed out 1`] = `
+<ul
+ className="NavStyles-s11c0d2g-0 ddqXnG"
+ data-test="nav"
+>
+ <Link
+ href="/items"
+ >
+ <a
+ href="/items"
+ onClick={[Function]}
+ >
+ Shop
+ </a>
+ </Link>
+ <Link
+ href="/signup"
+ >
+ <a
+ href="/signup"
+ onClick={[Function]}
+ >
+ Sign In
+ </a>
+ </Link>
+</ul>
+`;
+
+exports[`<Nav/> renders the amount of items in the cart 1`] = `
+<div
+ className="count CartCount__Dot-xxvp4g-1 fJsVOg"
+>
+ 9
+</div>
+`;
diff --git a/stepped-solutions/62/frontend/__tests__/__snapshots__/Pagination.test.js.snap b/stepped-solutions/62/frontend/__tests__/__snapshots__/Pagination.test.js.snap
new file mode 100755
index 0000000..110f59d
--- /dev/null
+++ b/stepped-solutions/62/frontend/__tests__/__snapshots__/Pagination.test.js.snap
@@ -0,0 +1,67 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`<Pagination/> renders pagination for 18 items 1`] = `
+<div
+ className="PaginationStyles-aduuar-0 ewJsCc"
+ data-test="pagination"
+>
+ <SideEffect(Head)>
+ <Head />
+ </SideEffect(Head)>
+ <Link
+ href={
+ Object {
+ "pathname": "items",
+ "query": Object {
+ "page": 0,
+ },
+ }
+ }
+ prefetch={true}
+ >
+ <a
+ aria-disabled={true}
+ className="prev"
+ href="items?page=0"
+ onClick={[Function]}
+ >
+ ← Prev
+ </a>
+ </Link>
+ <p>
+ Page
+ 1
+ of
+ <span
+ className="totalPages"
+ >
+ 5
+ </span>
+ !
+ </p>
+ <p>
+ 18
+ Items Total
+ </p>
+ <Link
+ href={
+ Object {
+ "pathname": "items",
+ "query": Object {
+ "page": 2,
+ },
+ }
+ }
+ prefetch={true}
+ >
+ <a
+ aria-disabled={false}
+ className="next"
+ href="items?page=2"
+ onClick={[Function]}
+ >
+ Next →
+ </a>
+ </Link>
+</div>
+`;
diff --git a/stepped-solutions/62/frontend/components/Nav.js b/stepped-solutions/62/frontend/components/Nav.js
new file mode 100755
index 0000000..118db5a
--- /dev/null
+++ b/stepped-solutions/62/frontend/components/Nav.js
@@ -0,0 +1,49 @@
+import Link from 'next/link';
+import { Mutation } from 'react-apollo';
+import { TOGGLE_CART_MUTATION } from './Cart';
+import NavStyles from './styles/NavStyles';
+import User from './User';
+import CartCount from './CartCount';
+import Signout from './Signout';
+
+const Nav = () => (
+ <User>
+ {({ data: { me } }) => (
+ <NavStyles data-test="nav">
+ <Link href="/items">
+ <a>Shop</a>
+ </Link>
+ {me && (
+ <>
+ <Link href="/sell">
+ <a>Sell</a>
+ </Link>
+ <Link href="/orders">
+ <a>Orders</a>
+ </Link>
+ <Link href="/me">
+ <a>Account</a>
+ </Link>
+ <Signout />
+ <Mutation mutation={TOGGLE_CART_MUTATION}>
+ {(toggleCart) => (
+ <button onClick={toggleCart}>
+ My Cart
+ <CartCount count={me.cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0)}></CartCount>
+ </button>
+ )}
+ </Mutation>
+ </>
+ )}
+ {!me && (
+ <Link href="/signup">
+ <a>Sign In</a>
+ </Link>
+
+ )}
+ </NavStyles>
+ )}
+ </User>
+);
+
+export default Nav;
diff --git a/stepped-solutions/62/frontend/components/Pagination.js b/stepped-solutions/62/frontend/components/Pagination.js
new file mode 100755
index 0000000..b84af76
--- /dev/null
+++ b/stepped-solutions/62/frontend/components/Pagination.js
@@ -0,0 +1,67 @@
+import React from 'react';
+import gql from 'graphql-tag';
+import { Query } from 'react-apollo';
+import Head from 'next/head';
+import Link from 'next/link';
+import PaginationStyles from './styles/PaginationStyles';
+import { perPage } from '../config';
+
+const PAGINATION_QUERY = gql`
+ query PAGINATION_QUERY {
+ itemsConnection {
+ aggregate {
+ count
+ }
+ }
+ }
+`;
+
+const Pagination = props => (
+ <Query query={PAGINATION_QUERY}>
+ {({ data, loading, error }) => {
+ if (loading) return <p>Loading...</p>;
+ const count = data.itemsConnection.aggregate.count;
+ const pages = Math.ceil(count / perPage);
+ const page = props.page;
+ return (
+ <PaginationStyles data-test="pagination">
+ <Head>
+ <title>
+ Sick Fits! — Page {page} of {pages}
+ </title>
+ </Head>
+ <Link
+ prefetch
+ href={{
+ pathname: 'items',
+ query: { page: page - 1 },
+ }}
+ >
+ <a className="prev" aria-disabled={page <= 1}>
+ ← Prev
+ </a>
+ </Link>
+ <p>
+ Page {props.page} of
+ <span className="totalPages">{pages}</span>!
+ </p>
+ <p>{count} Items Total</p>
+ <Link
+ prefetch
+ href={{
+ pathname: 'items',
+ query: { page: page + 1 },
+ }}
+ >
+ <a className="next" aria-disabled={page >= pages}>
+ Next →
+ </a>
+ </Link>
+ </PaginationStyles>
+ );
+ }}
+ </Query>
+);
+
+export default Pagination;
+export { PAGINATION_QUERY };
diff --git a/stepped-solutions/63/update.zip b/stepped-solutions/63/update.zip
new file mode 100644
index 0000000..a07440c
--- /dev/null
+++ b/stepped-solutions/63/update.zip
Binary files differ
diff --git a/stepped-solutions/64/frontend/__tests__/Signup.test.js b/stepped-solutions/64/frontend/__tests__/Signup.test.js
new file mode 100755
index 0000000..e18bdee
--- /dev/null
+++ b/stepped-solutions/64/frontend/__tests__/Signup.test.js
@@ -0,0 +1,80 @@
+import { mount } from 'enzyme';
+import wait from 'waait';
+import toJSON from 'enzyme-to-json';
+import { MockedProvider } from 'react-apollo/test-utils';
+import { ApolloConsumer } from 'react-apollo';
+import Signup, { SIGNUP_MUTATION } from '../components/Signup';
+import { CURRENT_USER_QUERY } from '../components/User';
+import { fakeUser } from '../lib/testUtils';
+
+function type(wrapper, name, value) {
+ wrapper.find(`input[name="${name}"]`).simulate('change', {
+ target: { name, value },
+ });
+}
+
+const me = fakeUser();
+const mocks = [
+ // signup mock mutation
+ {
+ request: {
+ query: SIGNUP_MUTATION,
+ variables: {
+ name: me.name,
+ email: me.email,
+ password: 'wes',
+ },
+ },
+ result: {
+ data: {
+ signup: {
+ __typename: 'User',
+ id: 'abc123',
+ email: me.email,
+ name: me.name,
+ },
+ },
+ },
+ },
+ // current user query mock
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: { data: { me } },
+ },
+];
+
+describe('<Signup/>', () => {
+ it('renders and matches snapshot', async () => {
+ const wrapper = mount(
+ <MockedProvider>
+ <Signup />
+ </MockedProvider>
+ );
+ expect(toJSON(wrapper.find('form'))).toMatchSnapshot();
+ });
+
+ it('calls the mutation properly', async () => {
+ let apolloClient;
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <ApolloConsumer>
+ {client => {
+ apolloClient = client;
+ return <Signup />;
+ }}
+ </ApolloConsumer>
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ type(wrapper, 'name', me.name);
+ type(wrapper, 'email', me.email);
+ type(wrapper, 'password', 'wes');
+ wrapper.update();
+ wrapper.find('form').simulate('submit');
+ await wait();
+ // query the user out of the apollo client
+ const user = await apolloClient.query({ query: CURRENT_USER_QUERY });
+ expect(user.data.me).toMatchObject(me);
+ });
+});
diff --git a/stepped-solutions/64/frontend/__tests__/__snapshots__/Signup.test.js.snap b/stepped-solutions/64/frontend/__tests__/__snapshots__/Signup.test.js.snap
new file mode 100755
index 0000000..14c5912
--- /dev/null
+++ b/stepped-solutions/64/frontend/__tests__/__snapshots__/Signup.test.js.snap
@@ -0,0 +1,62 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`<Signup/> renders and matches snapshot 1`] = `
+<form
+ className="Form-s1xszr8q-0 dIYPmt"
+ method="post"
+ onSubmit={[Function]}
+>
+ <fieldset
+ aria-busy={false}
+ disabled={false}
+ >
+ <h2>
+ Sign Up for An Account
+ </h2>
+ <DisplayError
+ error={Object {}}
+ />
+ <label
+ htmlFor="email"
+ >
+ Email
+ <input
+ name="email"
+ onChange={[Function]}
+ placeholder="email"
+ type="email"
+ value=""
+ />
+ </label>
+ <label
+ htmlFor="name"
+ >
+ Name
+ <input
+ name="name"
+ onChange={[Function]}
+ placeholder="name"
+ type="text"
+ value=""
+ />
+ </label>
+ <label
+ htmlFor="password"
+ >
+ Password
+ <input
+ name="password"
+ onChange={[Function]}
+ placeholder="password"
+ type="password"
+ value=""
+ />
+ </label>
+ <button
+ type="submit"
+ >
+ Sign Up!
+ </button>
+ </fieldset>
+</form>
+`;
diff --git a/stepped-solutions/64/frontend/components/Signup.js b/stepped-solutions/64/frontend/components/Signup.js
new file mode 100755
index 0000000..e2f1a3f
--- /dev/null
+++ b/stepped-solutions/64/frontend/components/Signup.js
@@ -0,0 +1,87 @@
+import React, { Component } from 'react';
+import { Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import Form from './styles/Form';
+import Error from './ErrorMessage';
+import { CURRENT_USER_QUERY } from './User';
+
+const SIGNUP_MUTATION = gql`
+ mutation SIGNUP_MUTATION($email: String!, $name: String!, $password: String!) {
+ signup(email: $email, name: $name, password: $password) {
+ id
+ email
+ name
+ }
+ }
+`;
+
+class Signup extends Component {
+ state = {
+ name: '',
+ email: '',
+ password: '',
+ };
+ saveToState = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+ render() {
+ return (
+ <Mutation
+ mutation={SIGNUP_MUTATION}
+ variables={this.state}
+ refetchQueries={[{ query: CURRENT_USER_QUERY }]}
+ >
+ {(signup, { error, loading }) => (
+ <Form
+ method="post"
+ onSubmit={async e => {
+ e.preventDefault();
+ await signup();
+ this.setState({ name: '', email: '', password: '' });
+ }}
+ >
+ <fieldset disabled={loading} aria-busy={loading}>
+ <h2>Sign Up for An Account</h2>
+ <Error error={error} />
+ <label htmlFor="email">
+ Email
+ <input
+ type="email"
+ name="email"
+ placeholder="email"
+ value={this.state.email}
+ onChange={this.saveToState}
+ />
+ </label>
+ <label htmlFor="name">
+ Name
+ <input
+ type="text"
+ name="name"
+ placeholder="name"
+ value={this.state.name}
+ onChange={this.saveToState}
+ />
+ </label>
+ <label htmlFor="password">
+ Password
+ <input
+ type="password"
+ name="password"
+ placeholder="password"
+ value={this.state.password}
+ onChange={this.saveToState}
+ />
+ </label>
+
+ <button type="submit">Sign Up!</button>
+ </fieldset>
+ </Form>
+ )}
+ </Mutation>
+ );
+ }
+}
+
+export default Signup;
+export { SIGNUP_MUTATION };
diff --git a/stepped-solutions/64/frontend/components/User.js b/stepped-solutions/64/frontend/components/User.js
new file mode 100755
index 0000000..6f8a4fb
--- /dev/null
+++ b/stepped-solutions/64/frontend/components/User.js
@@ -0,0 +1,41 @@
+import { Query } from 'react-apollo';
+import gql from 'graphql-tag';
+import PropTypes from 'prop-types';
+
+const CURRENT_USER_QUERY = gql`
+ query {
+ me {
+ id
+ email
+ name
+ permissions
+ orders {
+ id
+ }
+ cart {
+ id
+ quantity
+ item {
+ id
+ price
+ image
+ title
+ description
+ }
+ }
+ }
+ }
+`;
+
+const User = props => (
+ <Query {...props} query={CURRENT_USER_QUERY}>
+ {payload => props.children(payload)}
+ </Query>
+);
+
+User.propTypes = {
+ children: PropTypes.func.isRequired,
+};
+
+export default User;
+export { CURRENT_USER_QUERY };
diff --git a/stepped-solutions/65/frontend/__tests__/AddToCart.test.js b/stepped-solutions/65/frontend/__tests__/AddToCart.test.js
new file mode 100755
index 0000000..cfc2e3e
--- /dev/null
+++ b/stepped-solutions/65/frontend/__tests__/AddToCart.test.js
@@ -0,0 +1,97 @@
+import { mount } from 'enzyme';
+import wait from 'waait';
+import toJSON from 'enzyme-to-json';
+import { MockedProvider } from 'react-apollo/test-utils';
+import { ApolloConsumer } from 'react-apollo';
+import AddToCart, { ADD_TO_CART_MUTATION } from '../components/AddToCart';
+import { CURRENT_USER_QUERY } from '../components/User';
+import { fakeUser, fakeCartItem } from '../lib/testUtils';
+
+const mocks = [
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: {
+ data: {
+ me: {
+ ...fakeUser(),
+ cart: [],
+ },
+ },
+ },
+ },
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: {
+ data: {
+ me: {
+ ...fakeUser(),
+ cart: [fakeCartItem()],
+ },
+ },
+ },
+ },
+ {
+ request: { query: ADD_TO_CART_MUTATION, variables: { id: 'abc123' } },
+ result: {
+ data: {
+ addToCart: {
+ ...fakeCartItem(),
+ quantity: 1,
+ },
+ },
+ },
+ },
+];
+
+describe('<AddToCart/>', () => {
+ it('renders and matches the snap shot', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <AddToCart id="abc123" />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ expect(toJSON(wrapper.find('button'))).toMatchSnapshot();
+ });
+
+ it('adds an item to cart when clicked', async () => {
+ let apolloClient;
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <ApolloConsumer>
+ {client => {
+ apolloClient = client;
+ return <AddToCart id="abc123" />;
+ }}
+ </ApolloConsumer>
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ const { data: { me } } = await apolloClient.query({ query: CURRENT_USER_QUERY });
+ // console.log(me);
+ expect(me.cart).toHaveLength(0);
+ // add an item to the cart
+ wrapper.find('button').simulate('click');
+ await wait();
+ // check if the item is in the cart
+ const { data: { me: me2 } } = await apolloClient.query({ query: CURRENT_USER_QUERY });
+ expect(me2.cart).toHaveLength(1);
+ expect(me2.cart[0].id).toBe('omg123');
+ expect(me2.cart[0].quantity).toBe(3);
+ });
+
+ it('changes from add to adding when clicked', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <AddToCart id="abc123" />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ expect(wrapper.text()).toContain('Add To Cart');
+ wrapper.find('button').simulate('click');
+ expect(wrapper.text()).toContain('Adding To Cart');
+ });
+});
diff --git a/stepped-solutions/65/frontend/__tests__/Cart.test.js b/stepped-solutions/65/frontend/__tests__/Cart.test.js
new file mode 100755
index 0000000..b8afc88
--- /dev/null
+++ b/stepped-solutions/65/frontend/__tests__/Cart.test.js
@@ -0,0 +1,39 @@
+import { mount } from 'enzyme';
+import wait from 'waait';
+import toJSON from 'enzyme-to-json';
+import { MockedProvider } from 'react-apollo/test-utils';
+import Cart, { LOCAL_STATE_QUERY } from '../components/Cart';
+import { CURRENT_USER_QUERY } from '../components/User';
+import { fakeUser, fakeCartItem } from '../lib/testUtils';
+
+const mocks = [
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: {
+ data: {
+ me: {
+ ...fakeUser(),
+ cart: [fakeCartItem()],
+ },
+ },
+ },
+ },
+ {
+ request: { query: LOCAL_STATE_QUERY },
+ result: { data: { cartOpen: true } },
+ },
+];
+
+describe('<Cart/>', () => {
+ it('renders and matches snappy', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <Cart />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ expect(toJSON(wrapper.find('header'))).toMatchSnapshot();
+ expect(wrapper.find('CartItem')).toHaveLength(1);
+ });
+});
diff --git a/stepped-solutions/65/frontend/__tests__/RemoveFromCart.test.js b/stepped-solutions/65/frontend/__tests__/RemoveFromCart.test.js
new file mode 100755
index 0000000..faacc91
--- /dev/null
+++ b/stepped-solutions/65/frontend/__tests__/RemoveFromCart.test.js
@@ -0,0 +1,67 @@
+import { mount } from 'enzyme';
+import wait from 'waait';
+import toJSON from 'enzyme-to-json';
+import { MockedProvider } from 'react-apollo/test-utils';
+import { ApolloConsumer } from 'react-apollo';
+import RemoveFromCart, { REMOVE_FROM_CART_MUTATION } from '../components/RemoveFromCart';
+import { CURRENT_USER_QUERY } from '../components/User';
+import { fakeUser, fakeCartItem } from '../lib/testUtils';
+
+global.alert = console.log;
+
+const mocks = [
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: {
+ data: {
+ me: {
+ ...fakeUser(),
+ cart: [fakeCartItem({ id: 'abc123' })],
+ },
+ },
+ },
+ },
+ {
+ request: { query: REMOVE_FROM_CART_MUTATION, variables: { id: 'abc123' } },
+ result: {
+ data: {
+ removeFromCart: {
+ __typename: 'CartItem',
+ id: 'abc123',
+ },
+ },
+ },
+ },
+];
+
+describe('<RemoveFromCart/>', () => {
+ it('renders and matches snapshot', async () => {
+ const wrapper = mount(
+ <MockedProvider>
+ <RemoveFromCart id="abc123" />
+ </MockedProvider>
+ );
+ expect(toJSON(wrapper.find('button'))).toMatchSnapshot();
+ });
+
+ it('removes the item from cart', async () => {
+ let apolloClient;
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <ApolloConsumer>
+ {client => {
+ apolloClient = client;
+ return <RemoveFromCart id="abc123" />;
+ }}
+ </ApolloConsumer>
+ </MockedProvider>
+ );
+ const res = await apolloClient.query({ query: CURRENT_USER_QUERY });
+ expect(res.data.me.cart).toHaveLength(1);
+ expect(res.data.me.cart[0].item.price).toBe(5000);
+ wrapper.find('button').simulate('click');
+ await wait();
+ const res2 = await apolloClient.query({ query: CURRENT_USER_QUERY });
+ expect(res2.data.me.cart).toHaveLength(0);
+ });
+});
diff --git a/stepped-solutions/65/frontend/components/AddToCart.js b/stepped-solutions/65/frontend/components/AddToCart.js
new file mode 100755
index 0000000..8a71cc3
--- /dev/null
+++ b/stepped-solutions/65/frontend/components/AddToCart.js
@@ -0,0 +1,36 @@
+import React from 'react';
+import { Mutation } from 'react-apollo';
+import gql from 'graphql-tag';
+import { CURRENT_USER_QUERY } from './User';
+
+const ADD_TO_CART_MUTATION = gql`
+ mutation addToCart($id: ID!) {
+ addToCart(id: $id) {
+ id
+ quantity
+ }
+ }
+`;
+
+class AddToCart extends React.Component {
+ render() {
+ const { id } = this.props;
+ return (
+ <Mutation
+ mutation={ADD_TO_CART_MUTATION}
+ variables={{
+ id,
+ }}
+ refetchQueries={[{ query: CURRENT_USER_QUERY }]}
+ >
+ {(addToCart, { loading }) => (
+ <button disabled={loading} onClick={addToCart}>
+ Add{loading && 'ing'} To Cart 🛒
+ </button>
+ )}
+ </Mutation>
+ );
+ }
+}
+export default AddToCart;
+export { ADD_TO_CART_MUTATION };
diff --git a/stepped-solutions/65/frontend/components/RemoveFromCart.js b/stepped-solutions/65/frontend/components/RemoveFromCart.js
new file mode 100755
index 0000000..025dae5
--- /dev/null
+++ b/stepped-solutions/65/frontend/components/RemoveFromCart.js
@@ -0,0 +1,71 @@
+import React from 'react';
+import { Mutation } from 'react-apollo';
+import styled from 'styled-components';
+import PropTypes from 'prop-types';
+import gql from 'graphql-tag';
+import { CURRENT_USER_QUERY } from './User';
+
+const REMOVE_FROM_CART_MUTATION = gql`
+ mutation removeFromCart($id: ID!) {
+ removeFromCart(id: $id) {
+ id
+ }
+ }
+`;
+
+const BigButton = styled.button`
+ font-size: 3rem;
+ background: none;
+ border: 0;
+ &:hover {
+ color: ${props => props.theme.red};
+ cursor: pointer;
+ }
+`;
+
+class RemoveFromCart extends React.Component {
+ static propTypes = {
+ id: PropTypes.string.isRequired,
+ };
+ // This gets called as soon as we get a response back from the server after a mutation has been performed
+ update = (cache, payload) => {
+ // 1. first read the cache
+ const data = cache.readQuery({ query: CURRENT_USER_QUERY });
+ // 2. remove that item from the cart
+ const cartItemId = payload.data.removeFromCart.id;
+ data.me.cart = data.me.cart.filter(cartItem => cartItem.id !== cartItemId);
+ // 3. write it back to the cache
+ cache.writeQuery({ query: CURRENT_USER_QUERY, data });
+ };
+ render() {
+ return (
+ <Mutation
+ mutation={REMOVE_FROM_CART_MUTATION}
+ variables={{ id: this.props.id }}
+ update={this.update}
+ optimisticResponse={{
+ __typename: 'Mutation',
+ removeFromCart: {
+ __typename: 'CartItem',
+ id: this.props.id,
+ },
+ }}
+ >
+ {(removeFromCart, { loading, error }) => (
+ <BigButton
+ disabled={loading}
+ onClick={() => {
+ removeFromCart().catch(err => alert(err.message));
+ }}
+ title="Delete Item"
+ >
+ &times;
+ </BigButton>
+ )}
+ </Mutation>
+ );
+ }
+}
+
+export default RemoveFromCart;
+export { REMOVE_FROM_CART_MUTATION };
diff --git a/stepped-solutions/66/backend/prisma.yml b/stepped-solutions/66/backend/prisma.yml
new file mode 100755
index 0000000..58b7a3b
--- /dev/null
+++ b/stepped-solutions/66/backend/prisma.yml
@@ -0,0 +1,7 @@
+#endpoint: ${env:PRISMA_ENDPOINT}
+endpoint: https://sick-fits-production.herokuapp.com/sick-fits-prod/prod
+datamodel: datamodel.graphql
+secret: ${env:PRISMA_SECRET}
+hooks:
+ post-deploy:
+ - graphql get-schema -p prisma
diff --git a/stepped-solutions/66/backend/src/generated/prisma.graphql b/stepped-solutions/66/backend/src/generated/prisma.graphql
new file mode 100755
index 0000000..cc13ecf
--- /dev/null
+++ b/stepped-solutions/66/backend/src/generated/prisma.graphql
@@ -0,0 +1,1862 @@
+# source: https://us1.prisma.sh/wesbos/siccccccccck-fits/dev
+# timestamp: Tue Sep 11 2018 16:26:22 GMT-0400 (EDT)
+
+type AggregateCartItem {
+ count: Int!
+}
+
+type AggregateItem {
+ count: Int!
+}
+
+type AggregateOrder {
+ count: Int!
+}
+
+type AggregateOrderItem {
+ count: Int!
+}
+
+type AggregateUser {
+ count: Int!
+}
+
+type BatchPayload {
+ """The number of nodes that have been affected by the Batch operation."""
+ count: Long!
+}
+
+type CartItem implements Node {
+ id: ID!
+ quantity: Int!
+ item(where: ItemWhereInput): Item
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type CartItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [CartItemEdge]!
+ aggregate: AggregateCartItem!
+}
+
+input CartItemCreateInput {
+ quantity: Int
+ item: ItemCreateOneInput
+ user: UserCreateOneWithoutCartInput!
+}
+
+input CartItemCreateManyWithoutUserInput {
+ create: [CartItemCreateWithoutUserInput!]
+ connect: [CartItemWhereUniqueInput!]
+}
+
+input CartItemCreateWithoutUserInput {
+ quantity: Int
+ item: ItemCreateOneInput
+}
+
+"""An edge in a connection."""
+type CartItemEdge {
+ """The item at the end of the edge."""
+ node: CartItem!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum CartItemOrderByInput {
+ id_ASC
+ id_DESC
+ quantity_ASC
+ quantity_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type CartItemPreviousValues {
+ id: ID!
+ quantity: Int!
+}
+
+type CartItemSubscriptionPayload {
+ mutation: MutationType!
+ node: CartItem
+ updatedFields: [String!]
+ previousValues: CartItemPreviousValues
+}
+
+input CartItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [CartItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [CartItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [CartItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: CartItemWhereInput
+}
+
+input CartItemUpdateInput {
+ quantity: Int
+ item: ItemUpdateOneInput
+ user: UserUpdateOneRequiredWithoutCartInput
+}
+
+input CartItemUpdateManyWithoutUserInput {
+ create: [CartItemCreateWithoutUserInput!]
+ connect: [CartItemWhereUniqueInput!]
+ disconnect: [CartItemWhereUniqueInput!]
+ delete: [CartItemWhereUniqueInput!]
+ update: [CartItemUpdateWithWhereUniqueWithoutUserInput!]
+ upsert: [CartItemUpsertWithWhereUniqueWithoutUserInput!]
+}
+
+input CartItemUpdateWithoutUserDataInput {
+ quantity: Int
+ item: ItemUpdateOneInput
+}
+
+input CartItemUpdateWithWhereUniqueWithoutUserInput {
+ where: CartItemWhereUniqueInput!
+ data: CartItemUpdateWithoutUserDataInput!
+}
+
+input CartItemUpsertWithWhereUniqueWithoutUserInput {
+ where: CartItemWhereUniqueInput!
+ update: CartItemUpdateWithoutUserDataInput!
+ create: CartItemCreateWithoutUserInput!
+}
+
+input CartItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [CartItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [CartItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [CartItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ quantity: Int
+
+ """All values that are not equal to given value."""
+ quantity_not: Int
+
+ """All values that are contained in given list."""
+ quantity_in: [Int!]
+
+ """All values that are not contained in given list."""
+ quantity_not_in: [Int!]
+
+ """All values less than the given value."""
+ quantity_lt: Int
+
+ """All values less than or equal the given value."""
+ quantity_lte: Int
+
+ """All values greater than the given value."""
+ quantity_gt: Int
+
+ """All values greater than or equal the given value."""
+ quantity_gte: Int
+ item: ItemWhereInput
+ user: UserWhereInput
+}
+
+input CartItemWhereUniqueInput {
+ id: ID
+}
+
+scalar DateTime
+
+type Item implements Node {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user(where: UserWhereInput): User!
+}
+
+"""A connection to a list of items."""
+type ItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [ItemEdge]!
+ aggregate: AggregateItem!
+}
+
+input ItemCreateInput {
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+ user: UserCreateOneInput!
+}
+
+input ItemCreateOneInput {
+ create: ItemCreateInput
+ connect: ItemWhereUniqueInput
+}
+
+"""An edge in a connection."""
+type ItemEdge {
+ """The item at the end of the edge."""
+ node: Item!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum ItemOrderByInput {
+ id_ASC
+ id_DESC
+ title_ASC
+ title_DESC
+ description_ASC
+ description_DESC
+ image_ASC
+ image_DESC
+ largeImage_ASC
+ largeImage_DESC
+ price_ASC
+ price_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type ItemPreviousValues {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ largeImage: String
+ price: Int!
+}
+
+type ItemSubscriptionPayload {
+ mutation: MutationType!
+ node: Item
+ updatedFields: [String!]
+ previousValues: ItemPreviousValues
+}
+
+input ItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: ItemWhereInput
+}
+
+input ItemUpdateDataInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneRequiredInput
+}
+
+input ItemUpdateInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ user: UserUpdateOneRequiredInput
+}
+
+input ItemUpdateOneInput {
+ create: ItemCreateInput
+ connect: ItemWhereUniqueInput
+ disconnect: Boolean
+ delete: Boolean
+ update: ItemUpdateDataInput
+ upsert: ItemUpsertNestedInput
+}
+
+input ItemUpsertNestedInput {
+ update: ItemUpdateDataInput!
+ create: ItemCreateInput!
+}
+
+input ItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [ItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [ItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [ItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ title: String
+
+ """All values that are not equal to given value."""
+ title_not: String
+
+ """All values that are contained in given list."""
+ title_in: [String!]
+
+ """All values that are not contained in given list."""
+ title_not_in: [String!]
+
+ """All values less than the given value."""
+ title_lt: String
+
+ """All values less than or equal the given value."""
+ title_lte: String
+
+ """All values greater than the given value."""
+ title_gt: String
+
+ """All values greater than or equal the given value."""
+ title_gte: String
+
+ """All values containing the given string."""
+ title_contains: String
+
+ """All values not containing the given string."""
+ title_not_contains: String
+
+ """All values starting with the given string."""
+ title_starts_with: String
+
+ """All values not starting with the given string."""
+ title_not_starts_with: String
+
+ """All values ending with the given string."""
+ title_ends_with: String
+
+ """All values not ending with the given string."""
+ title_not_ends_with: String
+ description: String
+
+ """All values that are not equal to given value."""
+ description_not: String
+
+ """All values that are contained in given list."""
+ description_in: [String!]
+
+ """All values that are not contained in given list."""
+ description_not_in: [String!]
+
+ """All values less than the given value."""
+ description_lt: String
+
+ """All values less than or equal the given value."""
+ description_lte: String
+
+ """All values greater than the given value."""
+ description_gt: String
+
+ """All values greater than or equal the given value."""
+ description_gte: String
+
+ """All values containing the given string."""
+ description_contains: String
+
+ """All values not containing the given string."""
+ description_not_contains: String
+
+ """All values starting with the given string."""
+ description_starts_with: String
+
+ """All values not starting with the given string."""
+ description_not_starts_with: String
+
+ """All values ending with the given string."""
+ description_ends_with: String
+
+ """All values not ending with the given string."""
+ description_not_ends_with: String
+ image: String
+
+ """All values that are not equal to given value."""
+ image_not: String
+
+ """All values that are contained in given list."""
+ image_in: [String!]
+
+ """All values that are not contained in given list."""
+ image_not_in: [String!]
+
+ """All values less than the given value."""
+ image_lt: String
+
+ """All values less than or equal the given value."""
+ image_lte: String
+
+ """All values greater than the given value."""
+ image_gt: String
+
+ """All values greater than or equal the given value."""
+ image_gte: String
+
+ """All values containing the given string."""
+ image_contains: String
+
+ """All values not containing the given string."""
+ image_not_contains: String
+
+ """All values starting with the given string."""
+ image_starts_with: String
+
+ """All values not starting with the given string."""
+ image_not_starts_with: String
+
+ """All values ending with the given string."""
+ image_ends_with: String
+
+ """All values not ending with the given string."""
+ image_not_ends_with: String
+ largeImage: String
+
+ """All values that are not equal to given value."""
+ largeImage_not: String
+
+ """All values that are contained in given list."""
+ largeImage_in: [String!]
+
+ """All values that are not contained in given list."""
+ largeImage_not_in: [String!]
+
+ """All values less than the given value."""
+ largeImage_lt: String
+
+ """All values less than or equal the given value."""
+ largeImage_lte: String
+
+ """All values greater than the given value."""
+ largeImage_gt: String
+
+ """All values greater than or equal the given value."""
+ largeImage_gte: String
+
+ """All values containing the given string."""
+ largeImage_contains: String
+
+ """All values not containing the given string."""
+ largeImage_not_contains: String
+
+ """All values starting with the given string."""
+ largeImage_starts_with: String
+
+ """All values not starting with the given string."""
+ largeImage_not_starts_with: String
+
+ """All values ending with the given string."""
+ largeImage_ends_with: String
+
+ """All values not ending with the given string."""
+ largeImage_not_ends_with: String
+ price: Int
+
+ """All values that are not equal to given value."""
+ price_not: Int
+
+ """All values that are contained in given list."""
+ price_in: [Int!]
+
+ """All values that are not contained in given list."""
+ price_not_in: [Int!]
+
+ """All values less than the given value."""
+ price_lt: Int
+
+ """All values less than or equal the given value."""
+ price_lte: Int
+
+ """All values greater than the given value."""
+ price_gt: Int
+
+ """All values greater than or equal the given value."""
+ price_gte: Int
+ user: UserWhereInput
+}
+
+input ItemWhereUniqueInput {
+ id: ID
+}
+
+"""
+The `Long` scalar type represents non-fractional signed whole numeric values.
+Long can represent values between -(2^63) and 2^63 - 1.
+"""
+scalar Long
+
+type Mutation {
+ createCartItem(data: CartItemCreateInput!): CartItem!
+ createOrder(data: OrderCreateInput!): Order!
+ createItem(data: ItemCreateInput!): Item!
+ createOrderItem(data: OrderItemCreateInput!): OrderItem!
+ createUser(data: UserCreateInput!): User!
+ updateCartItem(data: CartItemUpdateInput!, where: CartItemWhereUniqueInput!): CartItem
+ updateOrder(data: OrderUpdateInput!, where: OrderWhereUniqueInput!): Order
+ updateItem(data: ItemUpdateInput!, where: ItemWhereUniqueInput!): Item
+ updateOrderItem(data: OrderItemUpdateInput!, where: OrderItemWhereUniqueInput!): OrderItem
+ updateUser(data: UserUpdateInput!, where: UserWhereUniqueInput!): User
+ deleteCartItem(where: CartItemWhereUniqueInput!): CartItem
+ deleteOrder(where: OrderWhereUniqueInput!): Order
+ deleteItem(where: ItemWhereUniqueInput!): Item
+ deleteOrderItem(where: OrderItemWhereUniqueInput!): OrderItem
+ deleteUser(where: UserWhereUniqueInput!): User
+ upsertCartItem(where: CartItemWhereUniqueInput!, create: CartItemCreateInput!, update: CartItemUpdateInput!): CartItem!
+ upsertOrder(where: OrderWhereUniqueInput!, create: OrderCreateInput!, update: OrderUpdateInput!): Order!
+ upsertItem(where: ItemWhereUniqueInput!, create: ItemCreateInput!, update: ItemUpdateInput!): Item!
+ upsertOrderItem(where: OrderItemWhereUniqueInput!, create: OrderItemCreateInput!, update: OrderItemUpdateInput!): OrderItem!
+ upsertUser(where: UserWhereUniqueInput!, create: UserCreateInput!, update: UserUpdateInput!): User!
+ updateManyCartItems(data: CartItemUpdateInput!, where: CartItemWhereInput): BatchPayload!
+ updateManyOrders(data: OrderUpdateInput!, where: OrderWhereInput): BatchPayload!
+ updateManyItems(data: ItemUpdateInput!, where: ItemWhereInput): BatchPayload!
+ updateManyOrderItems(data: OrderItemUpdateInput!, where: OrderItemWhereInput): BatchPayload!
+ updateManyUsers(data: UserUpdateInput!, where: UserWhereInput): BatchPayload!
+ deleteManyCartItems(where: CartItemWhereInput): BatchPayload!
+ deleteManyOrders(where: OrderWhereInput): BatchPayload!
+ deleteManyItems(where: ItemWhereInput): BatchPayload!
+ deleteManyOrderItems(where: OrderItemWhereInput): BatchPayload!
+ deleteManyUsers(where: UserWhereInput): BatchPayload!
+}
+
+enum MutationType {
+ CREATED
+ UPDATED
+ DELETED
+}
+
+"""An object with an ID"""
+interface Node {
+ """The id of the object."""
+ id: ID!
+}
+
+type Order implements Node {
+ id: ID!
+ items(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [OrderItem!]
+ total: Int!
+ user(where: UserWhereInput): User!
+ charge: String!
+ createdAt: DateTime!
+ updatedAt: DateTime!
+}
+
+"""A connection to a list of items."""
+type OrderConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [OrderEdge]!
+ aggregate: AggregateOrder!
+}
+
+input OrderCreateInput {
+ total: Int!
+ charge: String!
+ items: OrderItemCreateManyInput
+ user: UserCreateOneInput!
+}
+
+"""An edge in a connection."""
+type OrderEdge {
+ """The item at the end of the edge."""
+ node: Order!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+type OrderItem implements Node {
+ id: ID!
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int!
+ user(where: UserWhereInput): User
+}
+
+"""A connection to a list of items."""
+type OrderItemConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [OrderItemEdge]!
+ aggregate: AggregateOrderItem!
+}
+
+input OrderItemCreateInput {
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int
+ user: UserCreateOneInput
+}
+
+input OrderItemCreateManyInput {
+ create: [OrderItemCreateInput!]
+ connect: [OrderItemWhereUniqueInput!]
+}
+
+"""An edge in a connection."""
+type OrderItemEdge {
+ """The item at the end of the edge."""
+ node: OrderItem!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum OrderItemOrderByInput {
+ id_ASC
+ id_DESC
+ title_ASC
+ title_DESC
+ description_ASC
+ description_DESC
+ image_ASC
+ image_DESC
+ largeImage_ASC
+ largeImage_DESC
+ price_ASC
+ price_DESC
+ quantity_ASC
+ quantity_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type OrderItemPreviousValues {
+ id: ID!
+ title: String!
+ description: String!
+ image: String!
+ largeImage: String!
+ price: Int!
+ quantity: Int!
+}
+
+type OrderItemSubscriptionPayload {
+ mutation: MutationType!
+ node: OrderItem
+ updatedFields: [String!]
+ previousValues: OrderItemPreviousValues
+}
+
+input OrderItemSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderItemSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderItemSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderItemSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: OrderItemWhereInput
+}
+
+input OrderItemUpdateDataInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ quantity: Int
+ user: UserUpdateOneInput
+}
+
+input OrderItemUpdateInput {
+ title: String
+ description: String
+ image: String
+ largeImage: String
+ price: Int
+ quantity: Int
+ user: UserUpdateOneInput
+}
+
+input OrderItemUpdateManyInput {
+ create: [OrderItemCreateInput!]
+ connect: [OrderItemWhereUniqueInput!]
+ disconnect: [OrderItemWhereUniqueInput!]
+ delete: [OrderItemWhereUniqueInput!]
+ update: [OrderItemUpdateWithWhereUniqueNestedInput!]
+ upsert: [OrderItemUpsertWithWhereUniqueNestedInput!]
+}
+
+input OrderItemUpdateWithWhereUniqueNestedInput {
+ where: OrderItemWhereUniqueInput!
+ data: OrderItemUpdateDataInput!
+}
+
+input OrderItemUpsertWithWhereUniqueNestedInput {
+ where: OrderItemWhereUniqueInput!
+ update: OrderItemUpdateDataInput!
+ create: OrderItemCreateInput!
+}
+
+input OrderItemWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderItemWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderItemWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderItemWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ title: String
+
+ """All values that are not equal to given value."""
+ title_not: String
+
+ """All values that are contained in given list."""
+ title_in: [String!]
+
+ """All values that are not contained in given list."""
+ title_not_in: [String!]
+
+ """All values less than the given value."""
+ title_lt: String
+
+ """All values less than or equal the given value."""
+ title_lte: String
+
+ """All values greater than the given value."""
+ title_gt: String
+
+ """All values greater than or equal the given value."""
+ title_gte: String
+
+ """All values containing the given string."""
+ title_contains: String
+
+ """All values not containing the given string."""
+ title_not_contains: String
+
+ """All values starting with the given string."""
+ title_starts_with: String
+
+ """All values not starting with the given string."""
+ title_not_starts_with: String
+
+ """All values ending with the given string."""
+ title_ends_with: String
+
+ """All values not ending with the given string."""
+ title_not_ends_with: String
+ description: String
+
+ """All values that are not equal to given value."""
+ description_not: String
+
+ """All values that are contained in given list."""
+ description_in: [String!]
+
+ """All values that are not contained in given list."""
+ description_not_in: [String!]
+
+ """All values less than the given value."""
+ description_lt: String
+
+ """All values less than or equal the given value."""
+ description_lte: String
+
+ """All values greater than the given value."""
+ description_gt: String
+
+ """All values greater than or equal the given value."""
+ description_gte: String
+
+ """All values containing the given string."""
+ description_contains: String
+
+ """All values not containing the given string."""
+ description_not_contains: String
+
+ """All values starting with the given string."""
+ description_starts_with: String
+
+ """All values not starting with the given string."""
+ description_not_starts_with: String
+
+ """All values ending with the given string."""
+ description_ends_with: String
+
+ """All values not ending with the given string."""
+ description_not_ends_with: String
+ image: String
+
+ """All values that are not equal to given value."""
+ image_not: String
+
+ """All values that are contained in given list."""
+ image_in: [String!]
+
+ """All values that are not contained in given list."""
+ image_not_in: [String!]
+
+ """All values less than the given value."""
+ image_lt: String
+
+ """All values less than or equal the given value."""
+ image_lte: String
+
+ """All values greater than the given value."""
+ image_gt: String
+
+ """All values greater than or equal the given value."""
+ image_gte: String
+
+ """All values containing the given string."""
+ image_contains: String
+
+ """All values not containing the given string."""
+ image_not_contains: String
+
+ """All values starting with the given string."""
+ image_starts_with: String
+
+ """All values not starting with the given string."""
+ image_not_starts_with: String
+
+ """All values ending with the given string."""
+ image_ends_with: String
+
+ """All values not ending with the given string."""
+ image_not_ends_with: String
+ largeImage: String
+
+ """All values that are not equal to given value."""
+ largeImage_not: String
+
+ """All values that are contained in given list."""
+ largeImage_in: [String!]
+
+ """All values that are not contained in given list."""
+ largeImage_not_in: [String!]
+
+ """All values less than the given value."""
+ largeImage_lt: String
+
+ """All values less than or equal the given value."""
+ largeImage_lte: String
+
+ """All values greater than the given value."""
+ largeImage_gt: String
+
+ """All values greater than or equal the given value."""
+ largeImage_gte: String
+
+ """All values containing the given string."""
+ largeImage_contains: String
+
+ """All values not containing the given string."""
+ largeImage_not_contains: String
+
+ """All values starting with the given string."""
+ largeImage_starts_with: String
+
+ """All values not starting with the given string."""
+ largeImage_not_starts_with: String
+
+ """All values ending with the given string."""
+ largeImage_ends_with: String
+
+ """All values not ending with the given string."""
+ largeImage_not_ends_with: String
+ price: Int
+
+ """All values that are not equal to given value."""
+ price_not: Int
+
+ """All values that are contained in given list."""
+ price_in: [Int!]
+
+ """All values that are not contained in given list."""
+ price_not_in: [Int!]
+
+ """All values less than the given value."""
+ price_lt: Int
+
+ """All values less than or equal the given value."""
+ price_lte: Int
+
+ """All values greater than the given value."""
+ price_gt: Int
+
+ """All values greater than or equal the given value."""
+ price_gte: Int
+ quantity: Int
+
+ """All values that are not equal to given value."""
+ quantity_not: Int
+
+ """All values that are contained in given list."""
+ quantity_in: [Int!]
+
+ """All values that are not contained in given list."""
+ quantity_not_in: [Int!]
+
+ """All values less than the given value."""
+ quantity_lt: Int
+
+ """All values less than or equal the given value."""
+ quantity_lte: Int
+
+ """All values greater than the given value."""
+ quantity_gt: Int
+
+ """All values greater than or equal the given value."""
+ quantity_gte: Int
+ user: UserWhereInput
+}
+
+input OrderItemWhereUniqueInput {
+ id: ID
+}
+
+enum OrderOrderByInput {
+ id_ASC
+ id_DESC
+ total_ASC
+ total_DESC
+ charge_ASC
+ charge_DESC
+ createdAt_ASC
+ createdAt_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+}
+
+type OrderPreviousValues {
+ id: ID!
+ total: Int!
+ charge: String!
+ createdAt: DateTime!
+ updatedAt: DateTime!
+}
+
+type OrderSubscriptionPayload {
+ mutation: MutationType!
+ node: Order
+ updatedFields: [String!]
+ previousValues: OrderPreviousValues
+}
+
+input OrderSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: OrderWhereInput
+}
+
+input OrderUpdateInput {
+ total: Int
+ charge: String
+ items: OrderItemUpdateManyInput
+ user: UserUpdateOneRequiredInput
+}
+
+input OrderWhereInput {
+ """Logical AND on all given filters."""
+ AND: [OrderWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [OrderWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [OrderWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ total: Int
+
+ """All values that are not equal to given value."""
+ total_not: Int
+
+ """All values that are contained in given list."""
+ total_in: [Int!]
+
+ """All values that are not contained in given list."""
+ total_not_in: [Int!]
+
+ """All values less than the given value."""
+ total_lt: Int
+
+ """All values less than or equal the given value."""
+ total_lte: Int
+
+ """All values greater than the given value."""
+ total_gt: Int
+
+ """All values greater than or equal the given value."""
+ total_gte: Int
+ charge: String
+
+ """All values that are not equal to given value."""
+ charge_not: String
+
+ """All values that are contained in given list."""
+ charge_in: [String!]
+
+ """All values that are not contained in given list."""
+ charge_not_in: [String!]
+
+ """All values less than the given value."""
+ charge_lt: String
+
+ """All values less than or equal the given value."""
+ charge_lte: String
+
+ """All values greater than the given value."""
+ charge_gt: String
+
+ """All values greater than or equal the given value."""
+ charge_gte: String
+
+ """All values containing the given string."""
+ charge_contains: String
+
+ """All values not containing the given string."""
+ charge_not_contains: String
+
+ """All values starting with the given string."""
+ charge_starts_with: String
+
+ """All values not starting with the given string."""
+ charge_not_starts_with: String
+
+ """All values ending with the given string."""
+ charge_ends_with: String
+
+ """All values not ending with the given string."""
+ charge_not_ends_with: String
+ createdAt: DateTime
+
+ """All values that are not equal to given value."""
+ createdAt_not: DateTime
+
+ """All values that are contained in given list."""
+ createdAt_in: [DateTime!]
+
+ """All values that are not contained in given list."""
+ createdAt_not_in: [DateTime!]
+
+ """All values less than the given value."""
+ createdAt_lt: DateTime
+
+ """All values less than or equal the given value."""
+ createdAt_lte: DateTime
+
+ """All values greater than the given value."""
+ createdAt_gt: DateTime
+
+ """All values greater than or equal the given value."""
+ createdAt_gte: DateTime
+ updatedAt: DateTime
+
+ """All values that are not equal to given value."""
+ updatedAt_not: DateTime
+
+ """All values that are contained in given list."""
+ updatedAt_in: [DateTime!]
+
+ """All values that are not contained in given list."""
+ updatedAt_not_in: [DateTime!]
+
+ """All values less than the given value."""
+ updatedAt_lt: DateTime
+
+ """All values less than or equal the given value."""
+ updatedAt_lte: DateTime
+
+ """All values greater than the given value."""
+ updatedAt_gt: DateTime
+
+ """All values greater than or equal the given value."""
+ updatedAt_gte: DateTime
+ items_every: OrderItemWhereInput
+ items_some: OrderItemWhereInput
+ items_none: OrderItemWhereInput
+ user: UserWhereInput
+}
+
+input OrderWhereUniqueInput {
+ id: ID
+}
+
+"""Information about pagination in a connection."""
+type PageInfo {
+ """When paginating forwards, are there more items?"""
+ hasNextPage: Boolean!
+
+ """When paginating backwards, are there more items?"""
+ hasPreviousPage: Boolean!
+
+ """When paginating backwards, the cursor to continue."""
+ startCursor: String
+
+ """When paginating forwards, the cursor to continue."""
+ endCursor: String
+}
+
+enum Permission {
+ ADMIN
+ USER
+ ITEMCREATE
+ ITEMUPDATE
+ ITEMDELETE
+ PERMISSIONUPDATE
+}
+
+type Query {
+ cartItems(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [CartItem]!
+ orders(where: OrderWhereInput, orderBy: OrderOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Order]!
+ items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Item]!
+ orderItems(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [OrderItem]!
+ users(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [User]!
+ cartItem(where: CartItemWhereUniqueInput!): CartItem
+ order(where: OrderWhereUniqueInput!): Order
+ item(where: ItemWhereUniqueInput!): Item
+ orderItem(where: OrderItemWhereUniqueInput!): OrderItem
+ user(where: UserWhereUniqueInput!): User
+ cartItemsConnection(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): CartItemConnection!
+ ordersConnection(where: OrderWhereInput, orderBy: OrderOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): OrderConnection!
+ itemsConnection(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): ItemConnection!
+ orderItemsConnection(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): OrderItemConnection!
+ usersConnection(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): UserConnection!
+
+ """Fetches an object given its ID"""
+ node(
+ """The ID of an object"""
+ id: ID!
+ ): Node
+}
+
+type Subscription {
+ cartItem(where: CartItemSubscriptionWhereInput): CartItemSubscriptionPayload
+ order(where: OrderSubscriptionWhereInput): OrderSubscriptionPayload
+ item(where: ItemSubscriptionWhereInput): ItemSubscriptionPayload
+ orderItem(where: OrderItemSubscriptionWhereInput): OrderItemSubscriptionPayload
+ user(where: UserSubscriptionWhereInput): UserSubscriptionPayload
+}
+
+type User implements Node {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+ cart(where: CartItemWhereInput, orderBy: CartItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [CartItem!]
+}
+
+"""A connection to a list of items."""
+type UserConnection {
+ """Information to aid in pagination."""
+ pageInfo: PageInfo!
+
+ """A list of edges."""
+ edges: [UserEdge]!
+ aggregate: AggregateUser!
+}
+
+input UserCreateInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+ cart: CartItemCreateManyWithoutUserInput
+}
+
+input UserCreateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreateOneWithoutCartInput {
+ create: UserCreateWithoutCartInput
+ connect: UserWhereUniqueInput
+}
+
+input UserCreatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserCreateWithoutCartInput {
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserCreatepermissionsInput
+}
+
+"""An edge in a connection."""
+type UserEdge {
+ """The item at the end of the edge."""
+ node: User!
+
+ """A cursor for use in pagination."""
+ cursor: String!
+}
+
+enum UserOrderByInput {
+ id_ASC
+ id_DESC
+ name_ASC
+ name_DESC
+ email_ASC
+ email_DESC
+ password_ASC
+ password_DESC
+ resetToken_ASC
+ resetToken_DESC
+ resetTokenExpiry_ASC
+ resetTokenExpiry_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ createdAt_ASC
+ createdAt_DESC
+}
+
+type UserPreviousValues {
+ id: ID!
+ name: String!
+ email: String!
+ password: String!
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: [Permission!]!
+}
+
+type UserSubscriptionPayload {
+ mutation: MutationType!
+ node: User
+ updatedFields: [String!]
+ previousValues: UserPreviousValues
+}
+
+input UserSubscriptionWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserSubscriptionWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserSubscriptionWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserSubscriptionWhereInput!]
+
+ """
+ The subscription event gets dispatched when it's listed in mutation_in
+ """
+ mutation_in: [MutationType!]
+
+ """
+ The subscription event gets only dispatched when one of the updated fields names is included in this list
+ """
+ updatedFields_contains: String
+
+ """
+ The subscription event gets only dispatched when all of the field names included in this list have been updated
+ """
+ updatedFields_contains_every: [String!]
+
+ """
+ The subscription event gets only dispatched when some of the field names included in this list have been updated
+ """
+ updatedFields_contains_some: [String!]
+ node: UserWhereInput
+}
+
+input UserUpdateDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+ cart: CartItemUpdateManyWithoutUserInput
+}
+
+input UserUpdateInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+ cart: CartItemUpdateManyWithoutUserInput
+}
+
+input UserUpdateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+ disconnect: Boolean
+ delete: Boolean
+ update: UserUpdateDataInput
+ upsert: UserUpsertNestedInput
+}
+
+input UserUpdateOneRequiredInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+ update: UserUpdateDataInput
+ upsert: UserUpsertNestedInput
+}
+
+input UserUpdateOneRequiredWithoutCartInput {
+ create: UserCreateWithoutCartInput
+ connect: UserWhereUniqueInput
+ update: UserUpdateWithoutCartDataInput
+ upsert: UserUpsertWithoutCartInput
+}
+
+input UserUpdatepermissionsInput {
+ set: [Permission!]
+}
+
+input UserUpdateWithoutCartDataInput {
+ name: String
+ email: String
+ password: String
+ resetToken: String
+ resetTokenExpiry: String
+ permissions: UserUpdatepermissionsInput
+}
+
+input UserUpsertNestedInput {
+ update: UserUpdateDataInput!
+ create: UserCreateInput!
+}
+
+input UserUpsertWithoutCartInput {
+ update: UserUpdateWithoutCartDataInput!
+ create: UserCreateWithoutCartInput!
+}
+
+input UserWhereInput {
+ """Logical AND on all given filters."""
+ AND: [UserWhereInput!]
+
+ """Logical OR on all given filters."""
+ OR: [UserWhereInput!]
+
+ """Logical NOT on all given filters combined by AND."""
+ NOT: [UserWhereInput!]
+ id: ID
+
+ """All values that are not equal to given value."""
+ id_not: ID
+
+ """All values that are contained in given list."""
+ id_in: [ID!]
+
+ """All values that are not contained in given list."""
+ id_not_in: [ID!]
+
+ """All values less than the given value."""
+ id_lt: ID
+
+ """All values less than or equal the given value."""
+ id_lte: ID
+
+ """All values greater than the given value."""
+ id_gt: ID
+
+ """All values greater than or equal the given value."""
+ id_gte: ID
+
+ """All values containing the given string."""
+ id_contains: ID
+
+ """All values not containing the given string."""
+ id_not_contains: ID
+
+ """All values starting with the given string."""
+ id_starts_with: ID
+
+ """All values not starting with the given string."""
+ id_not_starts_with: ID
+
+ """All values ending with the given string."""
+ id_ends_with: ID
+
+ """All values not ending with the given string."""
+ id_not_ends_with: ID
+ name: String
+
+ """All values that are not equal to given value."""
+ name_not: String
+
+ """All values that are contained in given list."""
+ name_in: [String!]
+
+ """All values that are not contained in given list."""
+ name_not_in: [String!]
+
+ """All values less than the given value."""
+ name_lt: String
+
+ """All values less than or equal the given value."""
+ name_lte: String
+
+ """All values greater than the given value."""
+ name_gt: String
+
+ """All values greater than or equal the given value."""
+ name_gte: String
+
+ """All values containing the given string."""
+ name_contains: String
+
+ """All values not containing the given string."""
+ name_not_contains: String
+
+ """All values starting with the given string."""
+ name_starts_with: String
+
+ """All values not starting with the given string."""
+ name_not_starts_with: String
+
+ """All values ending with the given string."""
+ name_ends_with: String
+
+ """All values not ending with the given string."""
+ name_not_ends_with: String
+ email: String
+
+ """All values that are not equal to given value."""
+ email_not: String
+
+ """All values that are contained in given list."""
+ email_in: [String!]
+
+ """All values that are not contained in given list."""
+ email_not_in: [String!]
+
+ """All values less than the given value."""
+ email_lt: String
+
+ """All values less than or equal the given value."""
+ email_lte: String
+
+ """All values greater than the given value."""
+ email_gt: String
+
+ """All values greater than or equal the given value."""
+ email_gte: String
+
+ """All values containing the given string."""
+ email_contains: String
+
+ """All values not containing the given string."""
+ email_not_contains: String
+
+ """All values starting with the given string."""
+ email_starts_with: String
+
+ """All values not starting with the given string."""
+ email_not_starts_with: String
+
+ """All values ending with the given string."""
+ email_ends_with: String
+
+ """All values not ending with the given string."""
+ email_not_ends_with: String
+ password: String
+
+ """All values that are not equal to given value."""
+ password_not: String
+
+ """All values that are contained in given list."""
+ password_in: [String!]
+
+ """All values that are not contained in given list."""
+ password_not_in: [String!]
+
+ """All values less than the given value."""
+ password_lt: String
+
+ """All values less than or equal the given value."""
+ password_lte: String
+
+ """All values greater than the given value."""
+ password_gt: String
+
+ """All values greater than or equal the given value."""
+ password_gte: String
+
+ """All values containing the given string."""
+ password_contains: String
+
+ """All values not containing the given string."""
+ password_not_contains: String
+
+ """All values starting with the given string."""
+ password_starts_with: String
+
+ """All values not starting with the given string."""
+ password_not_starts_with: String
+
+ """All values ending with the given string."""
+ password_ends_with: String
+
+ """All values not ending with the given string."""
+ password_not_ends_with: String
+ resetToken: String
+
+ """All values that are not equal to given value."""
+ resetToken_not: String
+
+ """All values that are contained in given list."""
+ resetToken_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetToken_not_in: [String!]
+
+ """All values less than the given value."""
+ resetToken_lt: String
+
+ """All values less than or equal the given value."""
+ resetToken_lte: String
+
+ """All values greater than the given value."""
+ resetToken_gt: String
+
+ """All values greater than or equal the given value."""
+ resetToken_gte: String
+
+ """All values containing the given string."""
+ resetToken_contains: String
+
+ """All values not containing the given string."""
+ resetToken_not_contains: String
+
+ """All values starting with the given string."""
+ resetToken_starts_with: String
+
+ """All values not starting with the given string."""
+ resetToken_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetToken_ends_with: String
+
+ """All values not ending with the given string."""
+ resetToken_not_ends_with: String
+ resetTokenExpiry: String
+
+ """All values that are not equal to given value."""
+ resetTokenExpiry_not: String
+
+ """All values that are contained in given list."""
+ resetTokenExpiry_in: [String!]
+
+ """All values that are not contained in given list."""
+ resetTokenExpiry_not_in: [String!]
+
+ """All values less than the given value."""
+ resetTokenExpiry_lt: String
+
+ """All values less than or equal the given value."""
+ resetTokenExpiry_lte: String
+
+ """All values greater than the given value."""
+ resetTokenExpiry_gt: String
+
+ """All values greater than or equal the given value."""
+ resetTokenExpiry_gte: String
+
+ """All values containing the given string."""
+ resetTokenExpiry_contains: String
+
+ """All values not containing the given string."""
+ resetTokenExpiry_not_contains: String
+
+ """All values starting with the given string."""
+ resetTokenExpiry_starts_with: String
+
+ """All values not starting with the given string."""
+ resetTokenExpiry_not_starts_with: String
+
+ """All values ending with the given string."""
+ resetTokenExpiry_ends_with: String
+
+ """All values not ending with the given string."""
+ resetTokenExpiry_not_ends_with: String
+ cart_every: CartItemWhereInput
+ cart_some: CartItemWhereInput
+ cart_none: CartItemWhereInput
+}
+
+input UserWhereUniqueInput {
+ id: ID
+ email: String
+}
diff --git a/stepped-solutions/66/frontend/__tests__/Order.test.js b/stepped-solutions/66/frontend/__tests__/Order.test.js
new file mode 100755
index 0000000..71accfa
--- /dev/null
+++ b/stepped-solutions/66/frontend/__tests__/Order.test.js
@@ -0,0 +1,27 @@
+import { mount } from 'enzyme';
+import toJSON from 'enzyme-to-json';
+import wait from 'waait';
+import { MockedProvider } from 'react-apollo/test-utils';
+import Order, { SINGLE_ORDER_QUERY } from '../components/Order';
+import { fakeOrder } from '../lib/testUtils';
+
+const mocks = [
+ {
+ request: { query: SINGLE_ORDER_QUERY, variables: { id: 'ord123' } },
+ result: { data: { order: fakeOrder() } },
+ },
+];
+
+describe('<Order/>', () => {
+ it('renders the order', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <Order id="ord123" />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ const order = wrapper.find('div[data-test="order"]');
+ expect(toJSON(order)).toMatchSnapshot();
+ });
+});
diff --git a/stepped-solutions/66/frontend/__tests__/TakeMyMoney.test.js b/stepped-solutions/66/frontend/__tests__/TakeMyMoney.test.js
new file mode 100755
index 0000000..3d68502
--- /dev/null
+++ b/stepped-solutions/66/frontend/__tests__/TakeMyMoney.test.js
@@ -0,0 +1,98 @@
+import { mount } from 'enzyme';
+import wait from 'waait';
+import toJSON from 'enzyme-to-json';
+import NProgress from 'nprogress';
+import Router from 'next/router';
+import { MockedProvider } from 'react-apollo/test-utils';
+import { ApolloConsumer } from 'react-apollo';
+import TakeMyMoney, { CREATE_ORDER_MUTATION } from '../components/TakeMyMoney';
+import { CURRENT_USER_QUERY } from '../components/User';
+import { fakeUser, fakeCartItem } from '../lib/testUtils';
+
+Router.router = { push() {} };
+
+const mocks = [
+ {
+ request: { query: CURRENT_USER_QUERY },
+ result: {
+ data: {
+ me: {
+ ...fakeUser(),
+ cart: [fakeCartItem()],
+ },
+ },
+ },
+ },
+];
+
+describe('<TakeMyMoney/>', () => {
+ it('renders and matches snapshot', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <TakeMyMoney />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ const checkoutButton = wrapper.find('ReactStripeCheckout');
+ expect(toJSON(checkoutButton)).toMatchSnapshot();
+ });
+ it('creates an order ontoken', async () => {
+ const createOrderMock = jest.fn().mockResolvedValue({
+ data: { createOrder: { id: 'xyz789' } },
+ });
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <TakeMyMoney />
+ </MockedProvider>
+ );
+ const component = wrapper.find('TakeMyMoney').instance();
+ // manully call that onToken method
+ component.onToken({ id: 'abc123' }, createOrderMock);
+ expect(createOrderMock).toHaveBeenCalled();
+ expect(createOrderMock).toHaveBeenCalledWith({ variables: { token: 'abc123' } });
+ });
+
+ it('turns the progress bar on', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <TakeMyMoney />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ NProgress.start = jest.fn();
+ const createOrderMock = jest.fn().mockResolvedValue({
+ data: { createOrder: { id: 'xyz789' } },
+ });
+ const component = wrapper.find('TakeMyMoney').instance();
+ // manully call that onToken method
+ component.onToken({ id: 'abc123' }, createOrderMock);
+ expect(NProgress.start).toHaveBeenCalled();
+ });
+
+ it('routes to the order page when completed', async () => {
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <TakeMyMoney />
+ </MockedProvider>
+ );
+ await wait();
+ wrapper.update();
+ const createOrderMock = jest.fn().mockResolvedValue({
+ data: { createOrder: { id: 'xyz789' } },
+ });
+ const component = wrapper.find('TakeMyMoney').instance();
+ Router.router.push = jest.fn();
+ // manully call that onToken method
+ component.onToken({ id: 'abc123' }, createOrderMock);
+ await wait();
+ expect(Router.router.push).toHaveBeenCalled();
+ expect(Router.router.push).toHaveBeenCalledWith({
+ pathname: '/order',
+ query: {
+ id: 'xyz789',
+ },
+ });
+ });
+});
diff --git a/stepped-solutions/66/frontend/__tests__/__snapshots__/Order.test.js.snap b/stepped-solutions/66/frontend/__tests__/__snapshots__/Order.test.js.snap
new file mode 100755
index 0000000..9dce80b
--- /dev/null
+++ b/stepped-solutions/66/frontend/__tests__/__snapshots__/Order.test.js.snap
@@ -0,0 +1,118 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`<Order/> renders the order 1`] = `
+<div
+ className="OrderStyles-sc-4oqalm-0 eDzsVm"
+ data-test="order"
+>
+ <SideEffect(Head)>
+ <Head />
+ </SideEffect(Head)>
+ <p>
+ <span>
+ Order ID:
+ </span>
+ <span>
+ ord123
+ </span>
+ </p>
+ <p>
+ <span>
+ Charge
+ </span>
+ <span>
+ ch_123
+ </span>
+ </p>
+ <p>
+ <span>
+ Date
+ </span>
+ <span>
+ March 31, 2018 8:00 PM
+ </span>
+ </p>
+ <p>
+ <span>
+ Order Total
+ </span>
+ <span>
+ $400
+ </span>
+ </p>
+ <p>
+ <span>
+ Item Count
+ </span>
+ <span>
+ 2
+ </span>
+ </p>
+ <div
+ className="items"
+ >
+ <div
+ className="order-item"
+ key="3a430a73-c9e9-4bcc-b46a-41618965ffea"
+ >
+ <img
+ alt="soluta non omnis consequatur enim quia autem"
+ src="reprehenderit.jpg"
+ />
+ <div
+ className="item-details"
+ >
+ <h2>
+ soluta non omnis consequatur enim quia autem
+ </h2>
+ <p>
+ Qty:
+ 1
+ </p>
+ <p>
+ Each:
+ $42.34
+ </p>
+ <p>
+ SubTotal:
+ $42.34
+ </p>
+ <p>
+ et modi tenetur amet modi reprehenderit omnis
+ </p>
+ </div>
+ </div>
+ <div
+ className="order-item"
+ key="2393e090-592f-4d03-b808-c9d81098deec"
+ >
+ <img
+ alt="quia sed exercitationem omnis laborum exercitationem est"
+ src="sint.jpg"
+ />
+ <div
+ className="item-details"
+ >
+ <h2>
+ quia sed exercitationem omnis laborum exercitationem est
+ </h2>
+ <p>
+ Qty:
+ 1
+ </p>
+ <p>
+ Each:
+ $42.34
+ </p>
+ <p>
+ SubTotal:
+ $42.34
+ </p>
+ <p>
+ sapiente laudantium molestias assumenda quasi adipisci mollitia
+ </p>
+ </div>
+ </div>
+ </div>
+</div>
+`;
diff --git a/stepped-solutions/66/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap b/stepped-solutions/66/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap
new file mode 100755
index 0000000..02a112e
--- /dev/null
+++ b/stepped-solutions/66/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap
@@ -0,0 +1,67 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`<TakeMyMoney/> renders and matches snapshot 1`] = `
+<ReactStripeCheckout
+ ComponentClass="span"
+ amount={15000}
+ className="StripeCheckout"
+ currency="USD"
+ description="Order of 3 items!"
+ email="Delmer.Smith@yahoo.com"
+ image="dog-small.jpg"
+ label="Pay With Card"
+ locale="auto"
+ name="Sick Fits"
+ reconfigureOnUpdate={false}
+ stripeKey="pk_test_Vtknn6vSdcZWSG2JWvEiWSqC"
+ token={[Function]}
+ triggerEvent="onClick"
+>
+ <button
+ className="StripeCheckout"
+ onBlur={[Function]}
+ onClick={[Function]}
+ onFocus={[Function]}
+ onMouseDown={[Function]}
+ onMouseOut={[Function]}
+ onMouseUp={[Function]}
+ style={
+ Object {
+ "background": "linear-gradient(#28a0e5,#015e94)",
+ "border": 0,
+ "borderRadius": 5,
+ "boxShadow": "0 1px 0 rgba(0,0,0,0.2)",
+ "cursor": "pointer",
+ "display": "inline-block",
+ "overflow": "hidden",
+ "padding": 1,
+ "textDecoration": "none",
+ "userSelect": "none",
+ "visibility": "visible",
+ }
+ }
+ >
+ <span
+ style={
+ Object {
+ "backgroundImage": "linear-gradient(#7dc5ee,#008cdd 85%,#30a2e4)",
+ "borderRadius": 4,
+ "boxShadow": "inset 0 1px 0 rgba(255,255,255,0.25)",
+ "color": "#fff",
+ "display": "block",
+ "fontFamily": "\\"Helvetica Neue\\",Helvetica,Arial,sans-serif",
+ "fontSize": 14,
+ "fontWeight": "bold",
+ "height": 30,
+ "lineHeight": "30px",
+ "padding": "0 12px",
+ "position": "relative",
+ "textShadow": "0 -1px 0 rgba(0,0,0,0.25)",
+ }
+ }
+ >
+ Pay With Card
+ </span>
+ </button>
+</ReactStripeCheckout>
+`;
diff --git a/stepped-solutions/66/frontend/components/Order.js b/stepped-solutions/66/frontend/components/Order.js
new file mode 100755
index 0000000..5177c0a
--- /dev/null
+++ b/stepped-solutions/66/frontend/components/Order.js
@@ -0,0 +1,92 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Query } from 'react-apollo';
+import { format } from 'date-fns';
+import Head from 'next/head';
+import gql from 'graphql-tag';
+import formatMoney from '../lib/formatMoney';
+import Error from './ErrorMessage';
+import OrderStyles from './styles/OrderStyles';
+
+const SINGLE_ORDER_QUERY = gql`
+ query SINGLE_ORDER_QUERY($id: ID!) {
+ order(id: $id) {
+ id
+ charge
+ total
+ createdAt
+ user {
+ id
+ }
+ items {
+ id
+ title
+ description
+ price
+ image
+ quantity
+ }
+ }
+ }
+`;
+
+class Order extends React.Component {
+ static propTypes = {
+ id: PropTypes.string.isRequired,
+ };
+ render() {
+ return (
+ <Query query={SINGLE_ORDER_QUERY} variables={{ id: this.props.id }}>
+ {({ data, error, loading }) => {
+ if (error) return <Error error={error} />;
+ if (loading) return <p>Loading...</p>;
+ const order = data.order;
+ return (
+ <OrderStyles data-test="order">
+ <Head>
+ <title>Sick Fits - Order {order.id}</title>
+ </Head>
+ <p>
+ <span>Order ID:</span>
+ <span>{this.props.id}</span>
+ </p>
+ <p>
+ <span>Charge</span>
+ <span>{order.charge}</span>
+ </p>
+ <p>
+ <span>Date</span>
+ <span>{format(order.createdAt, 'MMMM d, YYYY h:mm a')}</span>
+ </p>
+ <p>
+ <span>Order Total</span>
+ <span>{formatMoney(order.total)}</span>
+ </p>
+ <p>
+ <span>Item Count</span>
+ <span>{order.items.length}</span>
+ </p>
+ <div className="items">
+ {order.items.map(item => (
+ <div className="order-item" key={item.id}>
+ <img src={item.image} alt={item.title} />
+ <div className="item-details">
+ <h2>{item.title}</h2>
+ <p>Qty: {item.quantity}</p>
+ <p>Each: {formatMoney(item.price)}</p>
+ <p>SubTotal: {formatMoney(item.price * item.quantity)}</p>
+ <p>{item.description}</p>
+ </div>
+ </div>
+ ))}
+ </div>
+ </OrderStyles>
+ );
+ }}
+ </Query>
+ );
+ }
+}
+
+export default Order;
+export { SINGLE_ORDER_QUERY };
diff --git a/stepped-solutions/66/frontend/components/TakeMyMoney.js b/stepped-solutions/66/frontend/components/TakeMyMoney.js
new file mode 100755
index 0000000..ca87832
--- /dev/null
+++ b/stepped-solutions/66/frontend/components/TakeMyMoney.js
@@ -0,0 +1,79 @@
+import React from 'react';
+import StripeCheckout from 'react-stripe-checkout';
+import { Mutation } from 'react-apollo';
+import Router from 'next/router';
+import NProgress from 'nprogress';
+import PropTypes from 'prop-types';
+import gql from 'graphql-tag';
+import calcTotalPrice from '../lib/calcTotalPrice';
+import Error from './ErrorMessage';
+import User, { CURRENT_USER_QUERY } from './User';
+
+const CREATE_ORDER_MUTATION = gql`
+ mutation createOrder($token: String!) {
+ createOrder(token: $token) {
+ id
+ charge
+ total
+ items {
+ id
+ title
+ }
+ }
+ }
+`;
+
+function totalItems(cart) {
+ return cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0);
+}
+
+class TakeMyMoney extends React.Component {
+ onToken = async (res, createOrder) => {
+ NProgress.start();
+ // manually call the mutation once we have the stripe token
+ const order = await createOrder({
+ variables: {
+ token: res.id,
+ },
+ }).catch(err => {
+ alert(err.message);
+ });
+ Router.push({
+ pathname: '/order',
+ query: { id: order.data.createOrder.id },
+ });
+ };
+ render() {
+ return (
+ <User>
+ {({ data: { me }, loading }) => {
+ if (loading) return null;
+ return (
+ <Mutation
+ mutation={CREATE_ORDER_MUTATION}
+ refetchQueries={[{ query: CURRENT_USER_QUERY }]}
+ >
+ {createOrder => (
+ <StripeCheckout
+ amount={calcTotalPrice(me.cart)}
+ name="Sick Fits"
+ description={`Order of ${totalItems(me.cart)} items!`}
+ image={me.cart.length && me.cart[0].item && me.cart[0].item.image}
+ stripeKey="pk_test_Vtknn6vSdcZWSG2JWvEiWSqC"
+ currency="USD"
+ email={me.email}
+ token={res => this.onToken(res, createOrder)}
+ >
+ {this.props.children}
+ </StripeCheckout>
+ )}
+ </Mutation>
+ );
+ }}
+ </User>
+ );
+ }
+}
+
+export default TakeMyMoney;
+export { CREATE_ORDER_MUTATION };