fix: update price
This commit is contained in:
parent
128e915eb2
commit
cfca06ecc5
|
@ -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 })
|
||||
|
|
|
@ -522,11 +522,15 @@ export class TransactionService {
|
|||
|
||||
let newProductPrice = new ProductHistoryPrice();
|
||||
|
||||
newProductPrice = product_price;
|
||||
newProductPrice.id = uuid.v4();
|
||||
newProductPrice.type = product_price.type;
|
||||
newProductPrice.price = hitSupplier.harga;
|
||||
newProductPrice.mark_up_price = product_price.mark_up_price;
|
||||
newProductPrice.startDate = new Date();
|
||||
newProductPrice.product = product;
|
||||
newProductPrice.partner = product_price.partner;
|
||||
|
||||
await this.productHistoryPriceService.create(product_price);
|
||||
await this.productHistoryPriceService.updateEndDate(product.id);
|
||||
await this.productHistoryPriceService.create(newProductPrice);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user