|
|
|
@ -50,4 +50,22 @@ export class ProductsService { |
|
|
|
|
throw new HttpException("An error occurred while retrieving products.", HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async findOne(id: string): Promise<Product> { |
|
|
|
|
try { |
|
|
|
|
const product = await this.productModel.findByPk(id); |
|
|
|
|
|
|
|
|
|
if (!product) { |
|
|
|
|
throw new HttpException("Product not found with the given id.", HttpStatus.NOT_FOUND); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return product; |
|
|
|
|
} catch (error) { |
|
|
|
|
if (error instanceof HttpException) { |
|
|
|
|
throw error; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
throw new HttpException("An error occurred while retrieving the product.", HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|