@@ -23,7 +23,7 @@ function isValidObjectId(id) {
2323 return false ;
2424 }
2525}
26-
26+ // get product by id
2727async function getProductById ( productId ) {
2828 if ( productId && isValidObjectId ( productId ) ) {
2929 const product = await Product . findById ( productId ) ;
@@ -32,6 +32,7 @@ async function getProductById(productId) {
3232 throw new NotFoundError ( `Product with id ${ productId } Not found` ) ;
3333 }
3434}
35+ // pagination products
3536
3637async function getProduct ( page , size ) {
3738 // Pagination for products
@@ -51,6 +52,7 @@ async function getProduct(page, size) {
5152 return { products, totalPages } ;
5253}
5354
55+ // recomendations && categories
5456async function getProductByTag ( category , page , size ) {
5557 const actualPage = parseInt ( page ) || 1 ;
5658 const pageSize = parseInt ( size ) || 8 ;
@@ -67,6 +69,7 @@ async function getProductByTag(category, page, size) {
6769 return { products, totalPages } ;
6870}
6971
72+ // create products
7073async function createProduct (
7174 name ,
7275 img ,
@@ -89,13 +92,14 @@ async function createProduct(
8992 } ) ;
9093 return await newProduct . save ( ) ;
9194}
92-
95+ // products by query
9396async function searchProduct ( query ) {
9497 const product = await Product . find ( {
9598 name : { $regex : query , $options : 'i' } ,
9699 } ) . limit ( 40 ) ;
97100 return product ;
98101}
102+ // change products properties
99103
100104async function updateProduct ( productId , newPrice , hot , newDescription ) {
101105 const updatedProperties = { } ;
@@ -117,9 +121,8 @@ async function updateProduct(productId, newPrice, hot, newDescription) {
117121 ) ;
118122 return result ;
119123}
120-
124+ // delete products
121125async function deleteProduct ( productId ) {
122- await getProductById ( productId ) ;
123126 return await Product . findOneAndDelete ( productId ) ;
124127}
125128
0 commit comments