fix: get tranasction history by user

This commit is contained in:
ilham
2021-12-15 15:17:59 +07:00
parent 53575f36d6
commit 8c5e944cc8
5 changed files with 121 additions and 8 deletions

View 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;
}
}
}
}