Skip to content

Commit a60de15

Browse files
committed
product hide endpoint changed to delete
1 parent db379e6 commit a60de15

File tree

4 files changed

+58
-58
lines changed

4 files changed

+58
-58
lines changed

README.md

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,72 +44,72 @@ STRIPE_TOKEN=sk_text_z&&2DbCJa9d3gZkxFwJdE$&hHbRe47KHxAF%&N#qRVx*zVFG$W
4444

4545
### User
4646

47-
| User Actions | Routes | Required | Http Verb |
48-
| --------------- | ------------------------- | -------------------------- | --------- |
49-
| Sign In | `/api/users/signIn` | email , password | Post |
50-
| Sign Up | `/api/users/signUp` | email, password , password | Post |
51-
| User Stats | `/api/users/stats` | must by Admin | Get |
52-
| Find user by Id | `/api/users/find/:userId` | userId | Get |
47+
| User Actions | Routes | Http Verb |
48+
| --------------- | ------------------------- | --------- |
49+
| Sign In | `/api/users/signIn` | Post |
50+
| Sign Up | `/api/users/signUp` | Post |
51+
| User Stats | `/api/users/stats` | Get |
52+
| Find user by Id | `/api/users/find/:userId` | Get |
5353

5454
[Postman Documentation]()
5555

5656
### Products
5757

58-
| Products Actions | Routes | Required | Http Verb |
59-
| -------------------- | --------------------------------- | -------- | --------- |
60-
| Create Product | `/api/products/create` | | Post |
61-
| Get All Product | `/api/products` | | Get |
62-
| Get Product by Tag | `/api/products/tag` | | Get |
63-
| Get Product By Query | `/api/products/search` | | Get |
64-
| Get Product By Id | `/api/products/:productId` | | Get |
65-
| Edit Product Info | `/api/products/update/:productId` | | Put |
66-
| Hide Product | `/api/products/hide/:productId` | | Put |
58+
| Products Actions | Routes | Http Verb |
59+
| -------------------- | --------------------------------- | --------- |
60+
| Create Product | `/api/products/create` | Post |
61+
| Get All Product | `/api/products` | Get |
62+
| Get Product by Tag | `/api/products/tag` | Get |
63+
| Get Product By Query | `/api/products/search` | Get |
64+
| Get Product By Id | `/api/products/:productId` | Get |
65+
| Edit Product Info | `/api/products/update/:productId` | Put |
66+
| Hide Product | `/api/products/hide/:productId` | Put |
6767

6868
[Postman Documentation]()
6969

7070
### Cart
7171

72-
| Cart Actions | Routes | Required | Http Verb |
73-
| ------------- | -------------------- | -------- | --------- |
74-
| Create Cart | `/api/carts/create` | | Post |
75-
| Get All Carts | `/api/carts/getAll` | | Get |
76-
| Get user Cart | `/api/carts/:userId` | | Get |
77-
| Edit Cart | `/api/carts/:cartId` | | Put |
78-
| Delete Cart | `/api/carts/:cartId` | | Delete |
72+
| Cart Actions | Routes | Http Verb |
73+
| ------------- | -------------------- | --------- |
74+
| Create Cart | `/api/carts/create` | Post |
75+
| Get All Carts | `/api/carts/getAll` | Get |
76+
| Get user Cart | `/api/carts/:userId` | Get |
77+
| Edit Cart | `/api/carts/:cartId` | Put |
78+
| Delete Cart | `/api/carts/:cartId` | Delete |
7979

8080
[Postman Documentation]()
8181

8282
### Purchases
8383

84-
| Purchases Actions | Routes | Required | Http Verb |
85-
| --------------------- | ---------------------------- | -------- | --------- |
86-
| Create Purchase | `/api/purchases/create` | | Post |
87-
| Payment | `/api/purchases/payment` | | Post |
88-
| Get Monthly Purchases | `/api/purchases/monthly` | | Get |
89-
| Get All Purchase | `/api/purchases/getAll` | | Get |
90-
| Get user Purchase | `/api/purchases/:userId` | | Get |
91-
| Delete Purchase | `/api/purchases/:purchaseId` | | Delete |
92-
| Edit Purchase | `/api/purchases/create` | | Put |
84+
| Purchases Actions | Routes | Http Verb |
85+
| --------------------- | ---------------------------- | --------- |
86+
| Create Purchase | `/api/purchases/create` | Post |
87+
| Payment | `/api/purchases/payment` | Post |
88+
| Get Monthly Purchases | `/api/purchases/monthly` | Get |
89+
| Get All Purchase | `/api/purchases/getAll` | Get |
90+
| Get user Purchase | `/api/purchases/:userId` | Get |
91+
| Delete Purchase | `/api/purchases/:purchaseId` | Delete |
92+
| Edit Purchase | `/api/purchases/create` | Put |
9393

9494
[Postman Documentation]()
9595

9696
### Comments
9797

98-
| Comments Actions | Routes | Required | Http Verb |
99-
| ---------------- | ---------------------- | -------- | --------- |
100-
| Create Comment | `/api/comments/create` | | Post |
101-
| Delete Comment | `/api/comments/delete` | | Delete |
102-
| Create Comment | `/api/comments/getAll` | | Get |
98+
| Comments Actions | Routes | Http Verb |
99+
| ---------------- | ---------------------- | --------- |
100+
| Create Comment | `/api/comments/create` | Post |
101+
| Delete Comment | `/api/comments/delete` | Delete |
102+
| Create Comment | `/api/comments/getAll` | Get |
103103

104104
[Postman Documentation]()
105105

106106
### Responses
107107

108-
| Responses Actions | Routes | Required | Http Verb |
109-
| ----------------- | ------------------------------------ | -------- | --------- |
110-
| Create Response | `/api/responses/create` | | Post |
111-
| Delete Response | `/api/responses/delete/:responsesId` | | Delete |
112-
| Get All Response | `/api/responses/getAll` | | Get |
108+
| Responses Actions | Routes | Http Verb |
109+
| ----------------- | ------------------------------------ | --------- |
110+
| Create Response | `/api/responses/create` | Post |
111+
| Delete Response | `/api/responses/delete/:responsesId` | Delete |
112+
| Get All Response | `/api/responses/getAll` | Get |
113113

114114
[Postman Documentation]()
115115

server/Controllers/productController.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const productController = {
77
createProduct,
88
searchProduct,
99
updateProduct,
10-
hideProduct,
10+
deleteProduct,
1111
};
1212

1313
function getProductById(req, res, next) {
@@ -68,9 +68,9 @@ function updateProduct(req, res, next) {
6868
.catch((error) => next(error));
6969
}
7070

71-
function hideProduct(req, res, next) {
71+
function deleteProduct(req, res, next) {
7272
productService
73-
.updateProduct(req.params.id)
73+
.deleteProduct(req.params.id)
7474
.then((product) => res.json(product))
7575
.catch((error) => next(error));
7676
}

server/Routes/productRoutes.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { caching } from '../helpers/cache.js';
66
import { cleanBody, validateQuery } from '../helpers/sanitizer.js';
77
const router = Router();
88

9-
router.get('/product', caching('10 minutes'), productController.getProduct);
9+
router.get('/products', caching('10 minutes'), productController.getProduct);
1010

1111
router.get(
1212
'/products/tag',
@@ -25,7 +25,7 @@ router.get(
2525
);
2626

2727
router.get(
28-
'/products/:productId',
28+
'/products/:id',
2929
caching('10 minutes'),
3030
productController.getProductById,
3131
);
@@ -39,19 +39,19 @@ router.post(
3939
);
4040

4141
router.put(
42-
'/products/update/:productId',
42+
'/products/update/:id',
4343
authMiddleware,
4444
cleanBody,
4545
adminCheck,
4646
productController.updateProduct,
4747
);
4848

49-
router.put(
50-
'/products/hide/:productId',
49+
router.delete(
50+
'/products/delete/:id',
5151
authMiddleware,
5252
adminCheck,
5353
cleanBody,
54-
productController.hideProduct,
54+
productController.deleteProduct,
5555
);
5656

5757
export default router;

server/View/productView.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@ const productService = {
99
createProduct,
1010
searchProduct,
1111
updateProduct,
12-
hideProduct,
12+
deleteProduct,
1313
};
1414

1515
function isValidObjectId(id) {
1616
// check if the id is in a valid format
1717
if (mongoose.Types.ObjectId.isValid(id)) {
1818
if (String(new mongoose.Types.ObjectId(id)) === id) return true;
19+
else {
20+
return false;
21+
}
22+
} else {
1923
return false;
2024
}
21-
return false;
2225
}
2326

2427
async function getProductById(productId) {
28+
console.log(productId);
2529
if (productId && isValidObjectId(productId)) {
2630
const product = await Product.findById(productId);
2731
return product;
@@ -115,13 +119,9 @@ async function updateProduct(productId, newPrice, hot, newDescription) {
115119
return result;
116120
}
117121

118-
async function hideProduct(productId) {
122+
async function deleteProduct(productId) {
119123
await getProductById(productId);
120-
return await Product.findOneAndUpdate(
121-
{ _id: productId },
122-
{ $set: { hide: true } },
123-
{ new: true },
124-
);
124+
return await Product.findOneAndDelete(productId);
125125
}
126126

127127
export default productService;

0 commit comments

Comments
 (0)