Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions apps/e-commerce/src/backend/controllers/CouponController.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import { Response } from "miragejs";
* send GET Request at /api/coupon
* */

export const getAllCouponsHandler = function () {
return new Response(200, {}, { coupons: this.db.coupons });
export const getAllCouponsHandler = function () {
try {
return new Response(200, {}, { coupons: this.db.coupons });
} catch (error) {
return new Response(
500,
{},
{
error,
}
);
}
};
2 changes: 2 additions & 0 deletions apps/e-commerce/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { categories } from "./backend/db/categories";
import { products } from "./backend/db/products";
import { users } from "./backend/db/users";
import { coupons } from "./backend/db/coupons";

export function makeServer({ environment = "development" } = {}) {
return new Server({
Expand Down Expand Up @@ -60,6 +61,7 @@ export function makeServer({ environment = "development" } = {}) {
);

categories.forEach((item) => server.create("category", { ...item }));
coupons.forEach((item) => server.create("coupon", { ...item }));
},

routes() {
Expand Down
22 changes: 22 additions & 0 deletions website/docs/api/apps/e-commerce.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,25 @@ The following Routes are relating to User's Wishlist. These are private routes.
```

- **Functionality**: This API call removes a product from the wishlist of the user in the db.

---

## Coupons Routes

The following Routes are relating to Coupons. These are Publicly accessible routes.

### 1. GET `/api/coupon`

- **Request URL**: `/api/coupon`
- **HTTP Method**: GET
- **Response Body**:

```js
{
data: {
coupons: Array;
}
}
```

- **Functionality**: This API call gets all coupons from the db.