import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { EntityNotFoundError, IsNull, Repository } from 'typeorm'; import { InjectRepository } from '@nestjs/typeorm'; import { ProductCategories } from '../entities/product-category.entity'; import { ProductHistoryPrice } from '../entities/product-history-price.entity'; @Injectable() export class ProductHistoryPriceService { constructor( @InjectRepository(ProductHistoryPrice) private productHistoryPriceService: Repository, ) {} async findOne(product: string, partner: string) { try { return await this.productHistoryPriceService.findOneOrFail({ where: { product: product, endDate: IsNull(), partner: partner ? partner : IsNull(), }, }); } catch (e) { if (e instanceof EntityNotFoundError) { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, error: 'Data not found', }, HttpStatus.NOT_FOUND, ); } else { throw e; } } } }