File tree 2 files changed +65
-19
lines changed
2 files changed +65
-19
lines changed Original file line number Diff line number Diff line change @@ -74,9 +74,9 @@ To start local environment run `yarn dev`
74
74
}
75
75
```
76
76
77
- #### Get All Books
77
+ #### Get Book by ID
78
78
79
- > https://halobuku.ericprd.site/api/v1/books
79
+ > https://halobuku.ericprd.site/api/v1/books/:id
80
80
81
81
- method: ` GET `
82
82
- body:
@@ -108,17 +108,69 @@ To start local environment run `yarn dev`
108
108
109
109
``` js
110
110
{
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
+ ];
122
124
}
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:
123
142
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
+ }
124
160
```
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 `
Original file line number Diff line number Diff line change 1
1
import { Request , Response } from "express" ;
2
2
import Book from "../models/book-schema" ;
3
3
import Cart from "../models/cart-schema" ;
4
- import User from "../models/user-schema" ;
5
4
6
5
const getCart = async ( req : Request , res : Response ) => {
7
6
const { _id } = req . app . locals . user ;
@@ -34,18 +33,13 @@ const removeFromCart = async (req: Request, res: Response) => {
34
33
const bookId : number = parseInt ( req . params . id ) ;
35
34
const { _id } = req . app . locals . user ;
36
35
37
- console . log ( bookId ) ;
38
-
39
36
try {
40
37
await Cart . updateOne (
41
38
{ _id : _id } ,
42
39
{ $pull : { books : { _id : bookId } } } ,
43
40
{ safe : true }
44
41
) . exec ( ) ;
45
42
46
- // const res = await Cart.findOne({ _id });
47
- // await res?.books.({ _id: bookId });
48
-
49
43
res . status ( 200 ) . json ( { message : "Delete Success" } ) ;
50
44
} catch ( error ) {
51
45
res . status ( 400 ) ;
You can’t perform that action at this time.
0 commit comments