From 22635ea05dab85a71fa93dbb98f93da7670ef899 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Fri, 25 May 2018 14:06:53 -0400 Subject: Delete and Add refetch refinements --- backend/prisma/datamodel.graphql | 4 +-- backend/src/generated/prisma.graphql | 15 ++------ backend/src/resolvers/Mutation.js | 11 ++++-- frontend/README.md | 42 +++++++++++++--------- frontend/__tests__/__snapshots__/Nav.test.js.snap | 2 +- .../__snapshots__/Pagination.test.js.snap | 3 ++ frontend/components/CreateItem.js | 10 +++++- frontend/components/DeleteItem.js | 21 +++++++++-- frontend/components/Items.js | 2 +- frontend/components/Order.js | 3 ++ frontend/components/Pagination.js | 6 ++++ frontend/components/RemoveFromCart.js | 2 +- frontend/components/SingleItem.js | 6 +++- frontend/components/styles/ItemStyles.js | 12 +++---- frontend/package.json | 6 ++-- 15 files changed, 94 insertions(+), 51 deletions(-) diff --git a/backend/prisma/datamodel.graphql b/backend/prisma/datamodel.graphql index 9465524..cb8afcb 100644 --- a/backend/prisma/datamodel.graphql +++ b/backend/prisma/datamodel.graphql @@ -52,8 +52,6 @@ type OrderItem { createdAt: DateTime! updatedAt: DateTime! quantity: Int! @default(value: 1) - item: Item! # Relationship to an Item - user: User! # Relationship to a user } type Order { @@ -64,4 +62,4 @@ type Order { createdAt: DateTime! updatedAt: DateTime! charge: String! -} \ No newline at end of file +} diff --git a/backend/src/generated/prisma.graphql b/backend/src/generated/prisma.graphql index aeacf68..953ddc2 100644 --- a/backend/src/generated/prisma.graphql +++ b/backend/src/generated/prisma.graphql @@ -1,5 +1,5 @@ -# source: https://us1.prisma.sh/johannes-schickling/wesbos/dev -# timestamp: Mon May 21 2018 18:02:25 GMT-0700 (PDT) +# source: https://us1.prisma.sh/wesbos/sick-fits/dev +# timestamp: Fri May 25 2018 10:46:45 GMT-0400 (EDT) type AggregateCartItem { count: Int! @@ -418,6 +418,7 @@ input ItemUpdateInput { input ItemUpdateOneInput { create: ItemCreateInput connect: ItemWhereUniqueInput + disconnect: Boolean delete: Boolean update: ItemUpdateDataInput upsert: ItemUpsertNestedInput @@ -818,8 +819,6 @@ type OrderItem implements Node { createdAt: DateTime! updatedAt: DateTime! quantity: Int! - item(where: ItemWhereInput): Item! - user(where: UserWhereInput): User! } """A connection to a list of items.""" @@ -839,8 +838,6 @@ input OrderItemCreateInput { largeImage: String price: Int! quantity: Int - item: ItemCreateOneInput! - user: UserCreateOneInput! } input OrderItemCreateManyInput { @@ -936,8 +933,6 @@ input OrderItemUpdateDataInput { largeImage: String price: Int quantity: Int - item: ItemUpdateOneInput - user: UserUpdateOneInput } input OrderItemUpdateInput { @@ -947,8 +942,6 @@ input OrderItemUpdateInput { largeImage: String price: Int quantity: Int - item: ItemUpdateOneInput - user: UserUpdateOneInput } input OrderItemUpdateManyInput { @@ -1268,8 +1261,6 @@ input OrderItemWhereInput { """All values greater than or equal the given value.""" quantity_gte: Int - item: ItemWhereInput - user: UserWhereInput } input OrderItemWhereUniqueInput { diff --git a/backend/src/resolvers/Mutation.js b/backend/src/resolvers/Mutation.js index 9510cd6..2a67da5 100644 --- a/backend/src/resolvers/Mutation.js +++ b/backend/src/resolvers/Mutation.js @@ -81,12 +81,17 @@ const mutations = { }; // 1. find the item const item = await ctx.db.query.item({ where }, `{ user {id}, title, id, description }`); - // 2. Make sure they own it, or are an admin - if (item.user.id !== ctx.request.user.id || !ctx.request.user.permissions.includes('ADMIN')) { + console.log(item.user); + console.log('-----------------'); + console.log(ctx.request.user); + // 2. if they 1. Don't own it AND 2. aren't an admin + if (item.user.id !== ctx.request.user.id && !ctx.request.user.permissions.includes('ADMIN')) { throw new Error("You aren't allowed to delete that item!"); } - // You Should Either Own this item, or have ITEMDELETE in roles + // 3. remove any orderItems this item is in + + return ctx.db.mutation.deleteItem({ where }, info); }, diff --git a/frontend/README.md b/frontend/README.md index 9d20e7c..9914799 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -14,36 +14,46 @@ Nudie Belt Our accessories are all about genuine leather and denim. Belts, leather wallets cases, denim bags, Knitted hats and scarves in wool or organic cotton. For our leather accessories, we only use vegetable tanned leather. Leather accessories will acquire a patina and become more beautiful the longer you use them. -Ultra Boost +Triple Black Ultra Boost Ultraboost is the ultimate running shoe that delivers constant energy returns. The more you run the more energy you bring to your life. +Patagonia Black Hole +The Black Hole Duffle is highly weather-resistant, and protects your gear from rough handling. The U-shaped lid allows quick access to the main compartment, while 2 zippered internal mesh pockets keep small items organized. A padded bottom panel adds structure and helps cushion the load when it gets tossed out of the vehicle or dropped from the pack mule. -Black Hole +Yeti cooler -The Black Hole Duffle is highly weather-resistant, and protects your gear from rough handling. The U-shaped lid allows quick access to the main compartment, while 2 zippered internal mesh pockets keep small items organized. A padded bottom panel adds structure and helps cushion the load when it gets tossed out of the vehicle or dropped from the pack mule. +Keep your brie and bevies chilly. Heavy-duty insulation ensures cold temperatures persist. A self-stopping hinge and Yeti-tough details are durable. Non-slip rubber feet keep your drinks and snacks orderly through whitewater or rough approaches to the picnic site. +Black Vapor Max -Yeti +With the radically reinvented VaporMax Air cushioning unit, the Nike Air VaporMax not only defies convention, it delivers a sensation that seems to defy gravity. -Keep your brie and bevies chilly. Heavy-duty insulation ensures cold temperatures persist. A self-stopping hinge and Yeti-tough details are durable. Non-slip rubber feet keep your drinks and snacks orderly through whitewater or rough approaches to the picnic site. +Naked and Famous Jeans + +Naked & Famous Denim uses only the most unique and rare selvedge denim fabrics from Japan, with the best style and fits around. Made in Canada. + + +Rimowa Suitcase + +RIMOWA is one of Europe's leading manufacturers of premium travel and carry-on luggage made of aluminum and polycarbonate. + + +Canada goose Macmillian + +The MacMillan Parka offers active urban style with a quilt-through design and curved hem cut. Canada Goose. + +## The North Face Fanorak +This versatile pullover offers wind and rain resistance, and packs into its own stylish fanny-pack-style kangaroo pocket. -Test Order: -FormatMoney -Cart Count -CartItem +Kith Hoodie -Things to Ask James: +Hat -* Testing Mutations - overwrite instance Mutation.client.mutate? -* Client via - best way? -* Update on Items Pagination -* Testing with context. Is this context okay? Deprecation -* Testing Error States -* wait and loading - normal? +270s --> diff --git a/frontend/__tests__/__snapshots__/Nav.test.js.snap b/frontend/__tests__/__snapshots__/Nav.test.js.snap index 8ac3ae4..354fbc1 100644 --- a/frontend/__tests__/__snapshots__/Nav.test.js.snap +++ b/frontend/__tests__/__snapshots__/Nav.test.js.snap @@ -2,7 +2,7 @@ exports[` Renders minimal nav when logged out 1`] = `