summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2018-02-28 15:28:15 -0500
committerWes Bos <wesbos@gmail.com>2018-02-28 15:28:15 -0500
commitf7bea2d1b7be2b70dceb25c9837f608b538e9cec (patch)
tree3bac7ad6d76fe9eca1d97f92109d709a141bfc00
parent8f2c595eca30e2d7138c8e8d6685774a8f44e55d (diff)
what
-rw-r--r--backend/database/datamodel.graphql15
-rw-r--r--backend/src/generated/prisma.graphql256
-rw-r--r--backend/src/resolvers/Mutation.js155
-rw-r--r--backend/src/resolvers/Query.js33
-rw-r--r--backend/src/schema.graphql12
-rw-r--r--frontend/components/Order.js60
-rw-r--r--frontend/components/OrderList.js12
-rw-r--r--frontend/components/Page.js2
-rw-r--r--frontend/components/TakeMyMoney.js11
-rw-r--r--frontend/pages/_document.js5
-rw-r--r--frontend/pages/order.js13
-rw-r--r--frontend/queries/index.js19
-rw-r--r--frontend/routes.js3
13 files changed, 464 insertions, 132 deletions
diff --git a/backend/database/datamodel.graphql b/backend/database/datamodel.graphql
index 940fb6f..c4ac4f6 100644
--- a/backend/database/datamodel.graphql
+++ b/backend/database/datamodel.graphql
@@ -43,9 +43,22 @@ type Item {
updatedAt: DateTime!
}
+type OrderItem {
+ id: ID! @unique
+ title: String!
+ description: String!
+ image: String
+ price: Int!
+ createdAt: DateTime!
+ updatedAt: DateTime!
+ quantity: Int! @default(value: 1)
+ item: Item! # Relationship to an Item
+ user: User! # Relationship to a user
+}
+
type Order {
id: ID! @unique
- items: [Item!]!
+ items: [OrderItem!]!
total: Int!
user: User!
createdAt: DateTime!
diff --git a/backend/src/generated/prisma.graphql b/backend/src/generated/prisma.graphql
index a0c3a3f..f65ba96 100644
--- a/backend/src/generated/prisma.graphql
+++ b/backend/src/generated/prisma.graphql
@@ -26,7 +26,7 @@ type Item implements Node {
type Order implements Node {
id: ID!
- items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Item!]
+ items(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [OrderItem!]
total: Int!
user(where: UserWhereInput): User!
createdAt: DateTime!
@@ -34,6 +34,19 @@ type Order implements Node {
charge: String!
}
+type OrderItem implements Node {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ price: Int!
+ createdAt: DateTime!
+ updatedAt: DateTime!
+ quantity: Int!
+ item(where: ItemWhereInput): Item!
+ user(where: UserWhereInput): User!
+}
+
type Post implements Node {
id: ID!
createdAt: DateTime!
@@ -77,6 +90,10 @@ type AggregateOrder {
count: Int!
}
+type AggregateOrderItem {
+ count: Int!
+}
+
type AggregatePost {
count: Int!
}
@@ -246,11 +263,6 @@ input ItemCreateInput {
price: Int!
}
-input ItemCreateManyInput {
- create: [ItemCreateInput!]
- connect: [ItemWhereUniqueInput!]
-}
-
input ItemCreateOneInput {
create: ItemCreateInput
connect: ItemWhereUniqueInput
@@ -312,13 +324,6 @@ input ItemUpdateInput {
price: Int
}
-input ItemUpdateManyInput {
- create: [ItemCreateInput!]
- connect: [ItemWhereUniqueInput!]
- disconnect: [ItemWhereUniqueInput!]
- delete: [ItemWhereUniqueInput!]
-}
-
input ItemUpdateOneInput {
create: ItemCreateInput
connect: ItemWhereUniqueInput
@@ -422,31 +427,37 @@ type Mutation {
createUser(data: UserCreateInput!): User!
createCartItem(data: CartItemCreateInput!): CartItem!
createItem(data: ItemCreateInput!): Item!
+ createOrderItem(data: OrderItemCreateInput!): OrderItem!
createOrder(data: OrderCreateInput!): Order!
updatePost(data: PostUpdateInput!, where: PostWhereUniqueInput!): Post
updateUser(data: UserUpdateInput!, where: UserWhereUniqueInput!): User
updateCartItem(data: CartItemUpdateInput!, where: CartItemWhereUniqueInput!): CartItem
updateItem(data: ItemUpdateInput!, where: ItemWhereUniqueInput!): Item
+ updateOrderItem(data: OrderItemUpdateInput!, where: OrderItemWhereUniqueInput!): OrderItem
updateOrder(data: OrderUpdateInput!, where: OrderWhereUniqueInput!): Order
deletePost(where: PostWhereUniqueInput!): Post
deleteUser(where: UserWhereUniqueInput!): User
deleteCartItem(where: CartItemWhereUniqueInput!): CartItem
deleteItem(where: ItemWhereUniqueInput!): Item
+ deleteOrderItem(where: OrderItemWhereUniqueInput!): OrderItem
deleteOrder(where: OrderWhereUniqueInput!): Order
upsertPost(where: PostWhereUniqueInput!, create: PostCreateInput!, update: PostUpdateInput!): Post!
upsertUser(where: UserWhereUniqueInput!, create: UserCreateInput!, update: UserUpdateInput!): User!
upsertCartItem(where: CartItemWhereUniqueInput!, create: CartItemCreateInput!, update: CartItemUpdateInput!): CartItem!
upsertItem(where: ItemWhereUniqueInput!, create: ItemCreateInput!, update: ItemUpdateInput!): Item!
+ upsertOrderItem(where: OrderItemWhereUniqueInput!, create: OrderItemCreateInput!, update: OrderItemUpdateInput!): OrderItem!
upsertOrder(where: OrderWhereUniqueInput!, create: OrderCreateInput!, update: OrderUpdateInput!): Order!
updateManyPosts(data: PostUpdateInput!, where: PostWhereInput!): BatchPayload!
updateManyUsers(data: UserUpdateInput!, where: UserWhereInput!): BatchPayload!
updateManyCartItems(data: CartItemUpdateInput!, where: CartItemWhereInput!): BatchPayload!
updateManyItems(data: ItemUpdateInput!, where: ItemWhereInput!): BatchPayload!
+ updateManyOrderItems(data: OrderItemUpdateInput!, where: OrderItemWhereInput!): BatchPayload!
updateManyOrders(data: OrderUpdateInput!, where: OrderWhereInput!): BatchPayload!
deleteManyPosts(where: PostWhereInput!): BatchPayload!
deleteManyUsers(where: UserWhereInput!): BatchPayload!
deleteManyCartItems(where: CartItemWhereInput!): BatchPayload!
deleteManyItems(where: ItemWhereInput!): BatchPayload!
+ deleteManyOrderItems(where: OrderItemWhereInput!): BatchPayload!
deleteManyOrders(where: OrderWhereInput!): BatchPayload!
}
@@ -469,7 +480,7 @@ type OrderConnection {
input OrderCreateInput {
total: Int!
charge: String!
- items: ItemCreateManyInput
+ items: OrderItemCreateManyInput
user: UserCreateOneWithoutOrdersInput!
}
@@ -481,7 +492,7 @@ input OrderCreateManyWithoutUserInput {
input OrderCreateWithoutUserInput {
total: Int!
charge: String!
- items: ItemCreateManyInput
+ items: OrderItemCreateManyInput
}
type OrderEdge {
@@ -489,6 +500,195 @@ type OrderEdge {
cursor: String!
}
+type OrderItemConnection {
+ pageInfo: PageInfo!
+ edges: [OrderItemEdge]!
+ aggregate: AggregateOrderItem!
+}
+
+input OrderItemCreateInput {
+ title: String!
+ description: String!
+ image: String
+ price: Int!
+ quantity: Int
+ item: ItemCreateOneInput!
+ user: UserCreateOneInput!
+}
+
+input OrderItemCreateManyInput {
+ create: [OrderItemCreateInput!]
+ connect: [OrderItemWhereUniqueInput!]
+}
+
+type OrderItemEdge {
+ node: OrderItem!
+ cursor: String!
+}
+
+enum OrderItemOrderByInput {
+ id_ASC
+ id_DESC
+ title_ASC
+ title_DESC
+ description_ASC
+ description_DESC
+ image_ASC
+ image_DESC
+ price_ASC
+ price_DESC
+ createdAt_ASC
+ createdAt_DESC
+ updatedAt_ASC
+ updatedAt_DESC
+ quantity_ASC
+ quantity_DESC
+}
+
+type OrderItemPreviousValues {
+ id: ID!
+ title: String!
+ description: String!
+ image: String
+ price: Int!
+ createdAt: DateTime!
+ updatedAt: DateTime!
+ quantity: Int!
+}
+
+type OrderItemSubscriptionPayload {
+ mutation: MutationType!
+ node: OrderItem
+ updatedFields: [String!]
+ previousValues: OrderItemPreviousValues
+}
+
+input OrderItemSubscriptionWhereInput {
+ AND: [OrderItemSubscriptionWhereInput!]
+ OR: [OrderItemSubscriptionWhereInput!]
+ mutation_in: [MutationType!]
+ updatedFields_contains: String
+ updatedFields_contains_every: [String!]
+ updatedFields_contains_some: [String!]
+ node: OrderItemWhereInput
+}
+
+input OrderItemUpdateInput {
+ title: String
+ description: String
+ image: String
+ price: Int
+ quantity: Int
+ item: ItemUpdateOneInput
+ user: UserUpdateOneInput
+}
+
+input OrderItemUpdateManyInput {
+ create: [OrderItemCreateInput!]
+ connect: [OrderItemWhereUniqueInput!]
+ disconnect: [OrderItemWhereUniqueInput!]
+ delete: [OrderItemWhereUniqueInput!]
+}
+
+input OrderItemWhereInput {
+ AND: [OrderItemWhereInput!]
+ OR: [OrderItemWhereInput!]
+ id: ID
+ id_not: ID
+ id_in: [ID!]
+ id_not_in: [ID!]
+ id_lt: ID
+ id_lte: ID
+ id_gt: ID
+ id_gte: ID
+ id_contains: ID
+ id_not_contains: ID
+ id_starts_with: ID
+ id_not_starts_with: ID
+ id_ends_with: ID
+ id_not_ends_with: ID
+ title: String
+ title_not: String
+ title_in: [String!]
+ title_not_in: [String!]
+ title_lt: String
+ title_lte: String
+ title_gt: String
+ title_gte: String
+ title_contains: String
+ title_not_contains: String
+ title_starts_with: String
+ title_not_starts_with: String
+ title_ends_with: String
+ title_not_ends_with: String
+ description: String
+ description_not: String
+ description_in: [String!]
+ description_not_in: [String!]
+ description_lt: String
+ description_lte: String
+ description_gt: String
+ description_gte: String
+ description_contains: String
+ description_not_contains: String
+ description_starts_with: String
+ description_not_starts_with: String
+ description_ends_with: String
+ description_not_ends_with: String
+ image: String
+ image_not: String
+ image_in: [String!]
+ image_not_in: [String!]
+ image_lt: String
+ image_lte: String
+ image_gt: String
+ image_gte: String
+ image_contains: String
+ image_not_contains: String
+ image_starts_with: String
+ image_not_starts_with: String
+ image_ends_with: String
+ image_not_ends_with: String
+ price: Int
+ price_not: Int
+ price_in: [Int!]
+ price_not_in: [Int!]
+ price_lt: Int
+ price_lte: Int
+ price_gt: Int
+ price_gte: Int
+ createdAt: DateTime
+ createdAt_not: DateTime
+ createdAt_in: [DateTime!]
+ createdAt_not_in: [DateTime!]
+ createdAt_lt: DateTime
+ createdAt_lte: DateTime
+ createdAt_gt: DateTime
+ createdAt_gte: DateTime
+ updatedAt: DateTime
+ updatedAt_not: DateTime
+ updatedAt_in: [DateTime!]
+ updatedAt_not_in: [DateTime!]
+ updatedAt_lt: DateTime
+ updatedAt_lte: DateTime
+ updatedAt_gt: DateTime
+ updatedAt_gte: DateTime
+ quantity: Int
+ quantity_not: Int
+ quantity_in: [Int!]
+ quantity_not_in: [Int!]
+ quantity_lt: Int
+ quantity_lte: Int
+ quantity_gt: Int
+ quantity_gte: Int
+ item: ItemWhereInput
+ user: UserWhereInput
+}
+
+input OrderItemWhereUniqueInput {
+ id: ID
+}
+
enum OrderOrderByInput {
id_ASC
id_DESC
@@ -530,7 +730,7 @@ input OrderSubscriptionWhereInput {
input OrderUpdateInput {
total: Int
charge: String
- items: ItemUpdateManyInput
+ items: OrderItemUpdateManyInput
user: UserUpdateOneWithoutOrdersInput
}
@@ -546,7 +746,7 @@ input OrderUpdateManyWithoutUserInput {
input OrderUpdateWithoutUserDataInput {
total: Int
charge: String
- items: ItemUpdateManyInput
+ items: OrderItemUpdateManyInput
}
input OrderUpdateWithoutUserInput {
@@ -615,9 +815,9 @@ input OrderWhereInput {
charge_not_starts_with: String
charge_ends_with: String
charge_not_ends_with: String
- items_every: ItemWhereInput
- items_some: ItemWhereInput
- items_none: ItemWhereInput
+ items_every: OrderItemWhereInput
+ items_some: OrderItemWhereInput
+ items_none: OrderItemWhereInput
user: UserWhereInput
}
@@ -810,16 +1010,19 @@ type Query {
users(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [User]!
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]!
+ orderItems(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [OrderItem]!
orders(where: OrderWhereInput, orderBy: OrderOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Order]!
post(where: PostWhereUniqueInput!): Post
user(where: UserWhereUniqueInput!): User
cartItem(where: CartItemWhereUniqueInput!): CartItem
item(where: ItemWhereUniqueInput!): Item
+ orderItem(where: OrderItemWhereUniqueInput!): OrderItem
order(where: OrderWhereUniqueInput!): Order
postsConnection(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): PostConnection!
usersConnection(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): UserConnection!
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!
+ orderItemsConnection(where: OrderItemWhereInput, orderBy: OrderItemOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): OrderItemConnection!
ordersConnection(where: OrderWhereInput, orderBy: OrderOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): OrderConnection!
node(id: ID!): Node
}
@@ -829,6 +1032,7 @@ type Subscription {
user(where: UserSubscriptionWhereInput): UserSubscriptionPayload
cartItem(where: CartItemSubscriptionWhereInput): CartItemSubscriptionPayload
item(where: ItemSubscriptionWhereInput): ItemSubscriptionPayload
+ orderItem(where: OrderItemSubscriptionWhereInput): OrderItemSubscriptionPayload
order(where: OrderSubscriptionWhereInput): OrderSubscriptionPayload
}
@@ -851,6 +1055,11 @@ input UserCreateInput {
cart: CartItemCreateManyWithoutUserInput
}
+input UserCreateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+}
+
input UserCreateOneWithoutCartInput {
create: UserCreateWithoutCartInput
connect: UserWhereUniqueInput
@@ -973,6 +1182,13 @@ input UserUpdateInput {
cart: CartItemUpdateManyWithoutUserInput
}
+input UserUpdateOneInput {
+ create: UserCreateInput
+ connect: UserWhereUniqueInput
+ disconnect: UserWhereUniqueInput
+ delete: UserWhereUniqueInput
+}
+
input UserUpdateOneWithoutCartInput {
create: UserCreateWithoutCartInput
connect: UserWhereUniqueInput
diff --git a/backend/src/resolvers/Mutation.js b/backend/src/resolvers/Mutation.js
index 6349109..b0afc6d 100644
--- a/backend/src/resolvers/Mutation.js
+++ b/backend/src/resolvers/Mutation.js
@@ -68,67 +68,67 @@ const mutations = {
});
},
- async createDraft(parent, { title, text }, ctx, info) {
- // const userId = getUserId(ctx);
- const userId = getUserId(ctx);
- return ctx.db.mutation.createPost(
- {
- data: {
- title,
- text,
- isPublished: false,
- author: {
- connect: { id: userId },
- },
- },
- },
- info
- );
- },
+ // async createDraft(parent, { title, text }, ctx, info) {
+ // // const userId = getUserId(ctx);
+ // const userId = getUserId(ctx);
+ // return ctx.db.mutation.createPost(
+ // {
+ // data: {
+ // title,
+ // text,
+ // isPublished: false,
+ // author: {
+ // connect: { id: userId },
+ // },
+ // },
+ // },
+ // info
+ // );
+ // },
- async publish(parent, { id }, ctx, info) {
- const userId = getUserId(ctx);
- const postExists = await ctx.db.exists.Post({
- id,
- author: { id: userId },
- });
- if (!postExists) {
- throw new Error(`Post not found or you're not the author`);
- }
+ // async publish(parent, { id }, ctx, info) {
+ // const userId = getUserId(ctx);
+ // const postExists = await ctx.db.exists.Post({
+ // id,
+ // author: { id: userId },
+ // });
+ // if (!postExists) {
+ // throw new Error(`Post not found or you're not the author`);
+ // }
- return ctx.db.mutation.updatePost(
- {
- where: { id },
- data: { isPublished: true },
- },
- info
- );
- },
+ // return ctx.db.mutation.updatePost(
+ // {
+ // where: { id },
+ // data: { isPublished: true },
+ // },
+ // info
+ // );
+ // },
- async deletePost(parent, { id }, ctx, info) {
- const userId = getUserId(ctx);
- const postExists = await ctx.db.exists.Post({
- id,
- author: { id: userId },
- });
- if (!postExists) {
- throw new Error(`Post not found or you're not the author`);
- }
+ // async deletePost(parent, { id }, ctx, info) {
+ // const userId = getUserId(ctx);
+ // const postExists = await ctx.db.exists.Post({
+ // id,
+ // author: { id: userId },
+ // });
+ // if (!postExists) {
+ // throw new Error(`Post not found or you're not the author`);
+ // }
- return ctx.db.mutation.deletePost({ where: { id } });
- },
+ // return ctx.db.mutation.deletePost({ where: { id } });
+ // },
- // Wes Added this brand new one!
- async updatePost(parent, args, ctx, info) {
- const updatedPost = await ctx.db.mutation.updatePost({
- where: { id: args.id },
- data: {
- title: args.title,
- text: args.text,
- },
- });
- return updatedPost;
- },
+ // // Wes Added this brand new one!
+ // async updatePost(parent, args, ctx, info) {
+ // const updatedPost = await ctx.db.mutation.updatePost({
+ // where: { id: args.id },
+ // data: {
+ // title: args.title,
+ // text: args.text,
+ // },
+ // });
+ // return updatedPost;
+ // },
// Send password request
async requestReset(parent, args, ctx, info) {
@@ -256,11 +256,9 @@ const mutations = {
const userId = getUserId(ctx);
const user = await ctx.db.query.user(
{ where: { id: userId } },
- '{ id, name, email, cart { id, quantity, item { price, id } }}'
+ // TODO - can we just pass info here?
+ '{ id, name, email, cart { id, quantity, item { title, price, id, description, image } }}'
);
- console.log('-------USER-----');
- console.log(user);
- console.log('-------USER-----');
// 1. Recalculate the total for the price
const amount = user.cart.reduce((tally, cartItem) => tally + cartItem.item.price * cartItem.quantity, 0);
// TODO Error Handling
@@ -268,7 +266,6 @@ const mutations = {
const customer = await stripe.customers.create({
email: user.email,
});
- console.log(customer);
// 2.3 Charge the stripe token
const charge = await stripe.charges.create({
amount,
@@ -276,17 +273,30 @@ const mutations = {
source: args.token,
});
- // Save this order to the database
- const items = user.cart.map(cartItem => ({ id: cartItem.item.id }));
- console.l('---Gonna connect these items: ----');
- console.log(items);
- console.l('---Gonna connect these items: ----');
+ const orderItems = user.cart.map(cartItem => {
+ const orderItem = {
+ quantity: cartItem.quantity,
+ // copy all the item details so it's there forever
+ ...cartItem.item,
+ item: {
+ // realtionship to the Item incase we need it
+ connect: { id: cartItem.item.id },
+ },
+ user: { connect: { id: user.id } },
+ };
+ // scrub the ID from it because the orderItem will have it's own ID
+ delete orderItem.id;
+ return orderItem;
+ });
+
+ // Create the Order
const order = await ctx.db.mutation.createOrder({
data: {
total: charge.amount,
charge: charge.id,
items: {
- connect: items,
+ // TODO this is going to be create instead
+ create: orderItems,
},
user: {
connect: {
@@ -295,13 +305,22 @@ const mutations = {
},
},
});
+ console.log('Gonna delete some items');
+ // 6. Clean up, clear the users cart adn send back { user, order }
+ // Delete the users current cart items
+ const cartItemIds = user.cart.map(cartItem => cartItem.id);
+ const deletedCartItems = await ctx.db.mutation.deleteManyCartItems({
+ where: {
+ id_in: cartItemIds,
+ },
+ });
+
console.l('--------ORDER-------------');
console.log(order);
console.l('--------ORDER-------------');
return order;
// 4. Send an email with their order
// 5. Send the order back
- // 6. Clean up, clear the users cart adn send back { user, order }
},
};
diff --git a/backend/src/resolvers/Query.js b/backend/src/resolvers/Query.js
index 2aabdb7..262517a 100644
--- a/backend/src/resolvers/Query.js
+++ b/backend/src/resolvers/Query.js
@@ -8,27 +8,28 @@ const Query = {
},
itemsConnection: forwardTo('db'),
+ order: forwardTo('db'),
- feed(parent, args, ctx, info) {
- return ctx.db.query.posts({}, info);
- },
+ // feed(parent, args, ctx, info) {
+ // return ctx.db.query.posts({}, info);
+ // },
- drafts(parent, args, ctx, info) {
- // const id = getUserId(ctx);
+ // drafts(parent, args, ctx, info) {
+ // // const id = getUserId(ctx);
- const where = {
- isPublished: false,
- // author: {
- // id,
- // },
- };
+ // const where = {
+ // isPublished: false,
+ // // author: {
+ // // id,
+ // // },
+ // };
- return ctx.db.query.posts({ where }, info);
- },
+ // return ctx.db.query.posts({ where }, info);
+ // },
- post(parent, { id }, ctx, info) {
- return ctx.db.query.post({ where: { id } }, info);
- },
+ // post(parent, { id }, ctx, info) {
+ // return ctx.db.query.post({ where: { id } }, info);
+ // },
me(parent, args, ctx, info) {
console.l('me!');
diff --git a/backend/src/schema.graphql b/backend/src/schema.graphql
index 84844c6..8d8218a 100644
--- a/backend/src/schema.graphql
+++ b/backend/src/schema.graphql
@@ -1,9 +1,6 @@
-# import Order, CartItem, ItemWhereInput, ItemOrderByInput, allItems, Post, Item, ItemCreateInput, ItemOrderByInput, ItemWhereInput, Query.order, Query.orders from './generated/prisma.graphql'
+# import Order, OrderItem, CartItem, ItemWhereInput, ItemOrderByInput, allItems, Item, ItemCreateInput, ItemOrderByInput, ItemWhereInput, Query.order, Query.orders from './generated/prisma.graphql'
type Query {
- feed: [Post!]!
- drafts: [Post!]!
- post(id: ID!): Post!
me: User
itemsConnection(
where: ItemWhereInput
@@ -29,10 +26,6 @@ type Mutation {
signin(email: String!, password: String!): AuthPayload!
requestReset(email: String!): User
resetPassword(resetToken: String!, password: String!, confirmPassword: String!): AuthPayload!
- createDraft(title: String!, text: String!): Post!
- publish(id: ID!): Post!
- deletePost(id: ID!): Post!
- updatePost(id: ID!, title: String, text: String): Post!
createItem(title: String, description: String, price: Int, image: String): Item!
deleteItem(id: ID!): Item!
updateItem(id: ID!, title: String, description: String, price: Int): Item!
@@ -49,10 +42,7 @@ type AuthPayload {
type User {
id: ID!
email: String!
- website: String
name: String!
- posts: [Post!]!
- age: Int
orders: [Order!]!
cart: [CartItem!]!
}
diff --git a/frontend/components/Order.js b/frontend/components/Order.js
new file mode 100644
index 0000000..409db66
--- /dev/null
+++ b/frontend/components/Order.js
@@ -0,0 +1,60 @@
+import { Component } from 'react';
+import { SINGLE_ORDER_QUERY } from '../queries';
+import { graphql, compose } from 'react-apollo';
+import { format, formatDistance } from 'date-fns';
+import formatMoney from '../lib/formatMoney';
+import Item from './Item';
+import Head from 'next/head';
+
+class Order extends Component {
+ componentDidMount() {
+ // this.props.orderQuery.refetch();
+ }
+ render() {
+ const { order } = this.props.orderQuery;
+ if (!order) {
+ return <p>No order Found!</p>;
+ }
+ return (
+ <div>
+ <Head>
+ <title>Sick Fits - Order {order.id}</title>
+ </Head>
+ <p>
+ <span>Order Id:</span>
+ <span>{order.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>You Bought {order.items.length} items in this order</p>
+ <div className="items">
+ {order.items.map(item => (
+ <div className="order-item" key={item.id}>
+ <h2>
+ {item.quantity} OF {item.title}
+ </h2>
+ </div>
+ ))}
+ </div>
+ </div>
+ );
+ }
+}
+
+const orderEnhancer = graphql(SINGLE_ORDER_QUERY, {
+ name: 'orderQuery',
+ options: ({ id }) => ({
+ variables: { id },
+ }),
+});
+export default compose(orderEnhancer)(Order);
diff --git a/frontend/components/OrderList.js b/frontend/components/OrderList.js
index 5e32ba2..cf12dc8 100644
--- a/frontend/components/OrderList.js
+++ b/frontend/components/OrderList.js
@@ -3,6 +3,7 @@ import { USER_ORDERS_QUERY } from '../queries';
import { graphql, compose } from 'react-apollo';
import { format, formatDistance } from 'date-fns';
import formatMoney from '../lib/formatMoney';
+import Link from 'next/link';
class OrderList extends Component {
componentDidMount() {
@@ -30,18 +31,13 @@ class OrderList extends Component {
<ul className="order-items">
<hr />
<h2>
- {order.id}
+ <Link href={`/order/${order.id}`} prefetch>
+ <a>{order.id}</a>
+ </Link>
<time dateTime={order.createdAt} title={format(order.createdAt, 'MMMM D, YYYY h:mm A')}>
{formatDistance(order.createdAt, new Date())}
</time>
</h2>
-
- {order.items.map(item => (
- <li>
- <img src={item.image} alt={item.title} />
- <p>{item.title}</p>
- </li>
- ))}
</ul>
</li>
))}
diff --git a/frontend/components/Page.js b/frontend/components/Page.js
index 66c65e6..6256c3d 100644
--- a/frontend/components/Page.js
+++ b/frontend/components/Page.js
@@ -25,9 +25,9 @@ const globals = injectGlobal`
font-family: 'radnika next', sans-serif;
padding: 0;
background-color: #ffffff;
- background: blue;
margin: 0;
font-size: 1.5rem;
+ background: red;
}
*, *:before, *:after {
box-sizing: inherit;
diff --git a/frontend/components/TakeMyMoney.js b/frontend/components/TakeMyMoney.js
index 5bdc409..5ebfb95 100644
--- a/frontend/components/TakeMyMoney.js
+++ b/frontend/components/TakeMyMoney.js
@@ -3,16 +3,23 @@ import StripeCheckout from 'react-stripe-checkout';
import { graphql, compose } from 'react-apollo';
import { CREATE_ORDER_MUTATION, CURRENT_USER_QUERY } from '../queries';
import formatMoney from '../lib/formatMoney';
+import Router from 'next/router';
+import NProgress from 'nprogress';
class TakeMyMoney extends Component {
onToken = async res => {
- console.log('We got a toooken!');
+ NProgress.start();
const order = await this.props.createOrder({
variables: {
token: res.id,
},
});
- console.log(order);
+ // Route them to that order page
+ const { id } = order.data.createOrder;
+ Router.push({
+ pathname: `/order/${id}`,
+ query: { id },
+ });
};
render() {
diff --git a/frontend/pages/_document.js b/frontend/pages/_document.js
index e9a6570..0ac8935 100644
--- a/frontend/pages/_document.js
+++ b/frontend/pages/_document.js
@@ -12,10 +12,7 @@ export default class MyDocument extends Document {
render() {
return (
<html>
- <Head>
- <title>My page</title>
- {this.props.styleTags}
- </Head>
+ <Head>{this.props.styleTags}</Head>
<body>
<Main />
<NextScript />
diff --git a/frontend/pages/order.js b/frontend/pages/order.js
new file mode 100644
index 0000000..d8fa17e
--- /dev/null
+++ b/frontend/pages/order.js
@@ -0,0 +1,13 @@
+import { Component } from 'react';
+import withData from '../lib/withData';
+import Page from '../components/Page';
+import Order from '../components/Order';
+
+const OrderPage = props => (
+ <Page>
+ <h2>Single Order:</h2>
+ <Order id={props.url.query.orderId} />
+ </Page>
+);
+
+export default withData(OrderPage);
diff --git a/frontend/queries/index.js b/frontend/queries/index.js
index beaec05..87f66b9 100644
--- a/frontend/queries/index.js
+++ b/frontend/queries/index.js
@@ -99,6 +99,25 @@ export const SINGLE_ITEM_QUERY = gql`
}
`;
+export const SINGLE_ORDER_QUERY = gql`
+ query order($id: ID!) {
+ order(where: { id: $id }) {
+ id
+ charge
+ total
+ createdAt
+ items {
+ id
+ title
+ price
+ description
+ image
+ quantity
+ }
+ }
+ }
+`;
+
export const SEARCH_ITEMS_QUERY = gql`
${itemDetails}
query SearchItems($searchTerm: String!) {
diff --git a/frontend/routes.js b/frontend/routes.js
index 62f91a9..b873186 100644
--- a/frontend/routes.js
+++ b/frontend/routes.js
@@ -3,4 +3,5 @@ const routes = (module.exports = require('next-routes')());
routes
.add('about')
.add('item', '/item/:itemId/:slug')
- .add('items', '/items/:page');
+ .add('items', '/items/:page')
+ .add('order', '/order/:orderId');