Skip to content

Commit 94ee051

Browse files
committed
remove unused syntax and update readme
1 parent e8f0faf commit 94ee051

File tree

2 files changed

+65
-19
lines changed

2 files changed

+65
-19
lines changed

README.md

+65-13
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ To start local environment run `yarn dev`
7474
}
7575
```
7676

77-
#### Get All Books
77+
#### Get Book by ID
7878

79-
> https://halobuku.ericprd.site/api/v1/books
79+
> https://halobuku.ericprd.site/api/v1/books/:id
8080
8181
- method: `GET`
8282
- body:
@@ -108,17 +108,69 @@ To start local environment run `yarn dev`
108108

109109
```js
110110
{
111-
book: {
112-
_id: Number,
113-
title: String,
114-
author: String,
115-
publishedYear: Number,
116-
description: String,
117-
image: String,
118-
price: Number,
119-
quantity: Number,
120-
isAvailable: Boolean
121-
}
111+
books: [
112+
{
113+
_id: Number,
114+
title: String,
115+
author: String,
116+
publishedYear: Number,
117+
description: String,
118+
image: String,
119+
price: Number,
120+
quantity: Number,
121+
isAvailable: Boolean,
122+
},
123+
];
122124
}
125+
```
126+
127+
#### Delete Book by ID (Auth)
128+
129+
> https://halobuku.ericprd.site/api/v1/books/:id
130+
131+
- method: `DELETE`
132+
- parameter is book's ID
133+
134+
### Cart
135+
136+
#### Get Cart
137+
138+
> https://halobuku.ericprd.site/api/v1/cart
139+
140+
- method: `GET`
141+
- cart:
123142

143+
```js
144+
{
145+
_id: String;
146+
cart: [
147+
{
148+
_id: Number,
149+
title: String,
150+
author: String,
151+
publishedYear: Number,
152+
description: String,
153+
image: String,
154+
price: Number,
155+
quantity: Number,
156+
isAvailable: Boolean,
157+
},
158+
];
159+
}
124160
```
161+
162+
#### Add to Cart
163+
164+
> https://halobuku.ericprd.site/api/v1/cart/:id
165+
166+
- method: `POST`
167+
- parameter is book's ID
168+
169+
#### Remove from Cart
170+
171+
> https://halobuku.ericprd.site/api/v1/cart/:id
172+
173+
- method: `DELETE`
174+
- parameter is book's ID
175+
176+
`note: cart only can be accessed by auth user`

src/controllers/cart-controllers.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Request, Response } from "express";
22
import Book from "../models/book-schema";
33
import Cart from "../models/cart-schema";
4-
import User from "../models/user-schema";
54

65
const getCart = async (req: Request, res: Response) => {
76
const { _id } = req.app.locals.user;
@@ -34,18 +33,13 @@ const removeFromCart = async (req: Request, res: Response) => {
3433
const bookId: number = parseInt(req.params.id);
3534
const { _id } = req.app.locals.user;
3635

37-
console.log(bookId);
38-
3936
try {
4037
await Cart.updateOne(
4138
{ _id: _id },
4239
{ $pull: { books: { _id: bookId } } },
4340
{ safe: true }
4441
).exec();
4542

46-
// const res = await Cart.findOne({ _id });
47-
// await res?.books.({ _id: bookId });
48-
4943
res.status(200).json({ message: "Delete Success" });
5044
} catch (error) {
5145
res.status(400);

0 commit comments

Comments
 (0)