From 4823f13c8f6b279c51fe6137ec9cf2574efa521d Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 10 May 2018 10:13:07 -0400 Subject: fix remove from cart mutation --- backend/src/resolvers/Mutation.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'backend/src/resolvers/Mutation.js') diff --git a/backend/src/resolvers/Mutation.js b/backend/src/resolvers/Mutation.js index 2909ade..cde9513 100644 --- a/backend/src/resolvers/Mutation.js +++ b/backend/src/resolvers/Mutation.js @@ -221,13 +221,23 @@ const mutations = { // delete that cart item async removeFromCart(parent, args, ctx, info) { - return ctx.db.mutation.deleteManyCartItems( + console.log(args.id); + // 1. Find the CartItem + const cartItem = await ctx.db.query.cartItem( + { + where: { id: args.id }, + }, + `{ id, user { id, permissions }}` + ); + // 2. Check they own it + if (cartItem.user.id !== ctx.request.userId) { + throw new Error("Cheatin' huh"); + } + // 3. Delete it + return ctx.db.mutation.deleteCartItem( { where: { id: args.id, - user: { - id: ctx.request.userId, - }, }, }, info -- cgit v1.3