fix: get tranasction history by user
This commit is contained in:
37
src/product/history-price/history-price.service.ts
Normal file
37
src/product/history-price/history-price.service.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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<ProductHistoryPrice>,
|
||||
) {}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user