diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-05-10 10:13:07 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-05-10 10:13:07 -0400 |
| commit | 4823f13c8f6b279c51fe6137ec9cf2574efa521d (patch) | |
| tree | acbe71c69840b7ef1e96e72da69a1d78623c3f9d /backend/src/resolvers/Mutation.js | |
| parent | 8ed7d5b734ba588fe0570e0e22f21a0fcda13422 (diff) | |
fix remove from cart mutation
Diffstat (limited to 'backend/src/resolvers/Mutation.js')
| -rw-r--r-- | backend/src/resolvers/Mutation.js | 18 |
1 files changed, 14 insertions, 4 deletions
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 |
