Skip to content

Commit

Permalink
Fix cancel order API
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeNg93 committed Feb 24, 2019
1 parent cc37ab1 commit 9210517
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions back-end/src/resolvers/Mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,25 +483,26 @@ const Mutations = {
}

// 2. Check if the selected subscription is available
const oldOrder = await prisma
const orders = await prisma
.user({ id: userId })
.orders({ id: args.orderId });
if (!oldOrder) {
.orders({ where: { id: args.orderId } });
const order = orders.length > 0 ? orders[0] : null;
if (!order) {
throw new Error('Could not find this order.');
}

// 3. Set the cancel date to today.
const order = await prisma.updateOrder({
const updatedOrder = await prisma.updateOrder({
data: {
cancelDate: new Date().toISOString(),
},
where: {
id: oldOrder.id,
id: order.id,
},
});

// 4. Return the order
return order;
return updatedOrder;
},
};

Expand Down

0 comments on commit 9210517

Please sign in to comment.