|
|
|
@ -26,6 +26,9 @@ export class ProductsService { |
|
|
|
|
const newProduct = await this.productModel.create(createProductDto); |
|
|
|
|
return newProduct; |
|
|
|
|
} catch (error) { |
|
|
|
|
if(error instanceof HttpException){ |
|
|
|
|
throw error |
|
|
|
|
} |
|
|
|
|
throw new HttpException("An error occurred while creating or updating the product.", HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -80,6 +83,7 @@ export class ProductsService { |
|
|
|
|
where, |
|
|
|
|
limit, |
|
|
|
|
offset, |
|
|
|
|
attributes: { exclude: ["description", "quantity", "createdAt", "updatedAt", "tags"] }, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const totalPages = Math.ceil(total / limit); |
|
|
|
@ -111,7 +115,7 @@ export class ProductsService { |
|
|
|
|
try { |
|
|
|
|
const { name, description, price, imageUrl, tags, quantity, brand, color, category } = updateProductDto; |
|
|
|
|
|
|
|
|
|
let updated = false; // متغیر برای بررسی تغییرات
|
|
|
|
|
let updated = false;
|
|
|
|
|
|
|
|
|
|
if (name && name !== product.name) { |
|
|
|
|
product.name = name; |
|
|
|
@ -156,6 +160,9 @@ export class ProductsService { |
|
|
|
|
|
|
|
|
|
return product; |
|
|
|
|
} catch (error) { |
|
|
|
|
if(error instanceof HttpException){ |
|
|
|
|
throw error |
|
|
|
|
} |
|
|
|
|
throw new HttpException("An error occurred while updating the product.", HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -177,7 +184,6 @@ export class ProductsService { |
|
|
|
|
if (error instanceof HttpException) { |
|
|
|
|
throw error; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
throw new HttpException("An unexpected error occurred while deleting the product.", HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|