fix: update price
This commit is contained in:
		| @@ -2,23 +2,53 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; | ||||
| import { EntityNotFoundError, IsNull, Repository } from 'typeorm'; | ||||
| import { InjectRepository } from '@nestjs/typeorm'; | ||||
| import { ProductHistoryPrice } from '../entities/product-history-price.entity'; | ||||
| import { UpdateUserDto } from '../../users/dto/update-user.dto'; | ||||
| import { hashPassword } from '../../helper/hash_password'; | ||||
| import { COA } from '../../transaction/entities/coa.entity'; | ||||
|  | ||||
| @Injectable() | ||||
| export class ProductHistoryPriceService { | ||||
|   constructor( | ||||
|     @InjectRepository(ProductHistoryPrice) | ||||
|     private productHistoryPriceService: Repository<ProductHistoryPrice>, | ||||
|     private productHistoryPriceRepository: Repository<ProductHistoryPrice>, | ||||
|   ) {} | ||||
|  | ||||
|   async create(dataProduct: ProductHistoryPrice) { | ||||
|     const result = await this.productHistoryPriceService.save(dataProduct); | ||||
|     const result = await this.productHistoryPriceRepository.insert(dataProduct); | ||||
|  | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   async updateEndDate(idProduct: string) { | ||||
|     try { | ||||
|       const dataPrice = await this.productHistoryPriceRepository | ||||
|         .createQueryBuilder() | ||||
|         .update(ProductHistoryPrice) | ||||
|         .set({ | ||||
|           endDate: new Date(), | ||||
|         }) | ||||
|         .where('product_id = :id and endDate is null', { id: idProduct }) | ||||
|         .execute(); | ||||
|  | ||||
|       return dataPrice; | ||||
|     } catch (e) { | ||||
|       if (e instanceof EntityNotFoundError) { | ||||
|         throw new HttpException( | ||||
|           { | ||||
|             statusCode: HttpStatus.NOT_FOUND, | ||||
|             error: 'Failed to update', | ||||
|           }, | ||||
|           HttpStatus.NOT_FOUND, | ||||
|         ); | ||||
|       } else { | ||||
|         throw e; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async findOne(product: string, partner: string) { | ||||
|     try { | ||||
|       return await this.productHistoryPriceService.findOneOrFail({ | ||||
|       return await this.productHistoryPriceRepository.findOneOrFail({ | ||||
|         where: { | ||||
|           product: product, | ||||
|           endDate: IsNull(), | ||||
| @@ -42,7 +72,7 @@ export class ProductHistoryPriceService { | ||||
|  | ||||
|   async findById(id: string) { | ||||
|     try { | ||||
|       return await this.productHistoryPriceService.findOneOrFail({ | ||||
|       return await this.productHistoryPriceRepository.findOneOrFail({ | ||||
|         where: { | ||||
|           id: id, | ||||
|         }, | ||||
| @@ -70,7 +100,7 @@ export class ProductHistoryPriceService { | ||||
|     pageSize?: number, | ||||
|   ) { | ||||
|     try { | ||||
|       const query = this.productHistoryPriceService | ||||
|       const query = this.productHistoryPriceRepository | ||||
|         .createQueryBuilder('product_history_price') | ||||
|         .leftJoin('product_history_price.product', 'product') | ||||
|         .where({ product: productId }) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user