fix: get tranasction history by user
This commit is contained in:
		
							
								
								
									
										18
									
								
								src/product/history-price/history-price.service.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/product/history-price/history-price.service.spec.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| import { Test, TestingModule } from '@nestjs/testing'; | ||||
| import { HistoryPriceService } from './history-price.service'; | ||||
|  | ||||
| describe('HistoryPriceService', () => { | ||||
|   let service: HistoryPriceService; | ||||
|  | ||||
|   beforeEach(async () => { | ||||
|     const module: TestingModule = await Test.createTestingModule({ | ||||
|       providers: [HistoryPriceService], | ||||
|     }).compile(); | ||||
|  | ||||
|     service = module.get<HistoryPriceService>(HistoryPriceService); | ||||
|   }); | ||||
|  | ||||
|   it('should be defined', () => { | ||||
|     expect(service).toBeDefined(); | ||||
|   }); | ||||
| }); | ||||
							
								
								
									
										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