Skip to content

Commit

Permalink
Extract an API call into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
bespoyasov committed Jan 21, 2022
1 parent 80ebc00 commit 7475ae2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Pretend like this is an API call =)

export function callApi(order) {
return new Promise((resolve) => {
setTimeout(() => {
console.log(order);
resolve("some-order-id");
}, 500);
});
}
10 changes: 3 additions & 7 deletions src/order.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { callApi } from "./api";

export async function makePurchase({ user, cart, coupon }) {
if (!cart.products.length) throw new Error("The cart is empty.");
if (
Expand Down Expand Up @@ -33,11 +35,5 @@ export async function makePurchase({ user, cart, coupon }) {
discount,
};

// Pretend like this is an API call =)
return await new Promise((resolve) => {
setTimeout(() => {
console.log(order);
resolve("some-order-id");
}, 500);
});
return await callApi(order);
}

0 comments on commit 7475ae2

Please sign in to comment.