diff options
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 |
