- fix when product not active can't order
This commit is contained in:
		
							
								
								
									
										44
									
								
								src/product/history-status/history-status.service.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/product/history-status/history-status.service.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; | ||||
| import { InjectRepository } from '@nestjs/typeorm'; | ||||
| import { EntityNotFoundError, IsNull, Repository } from 'typeorm'; | ||||
| import { ProductHistoryStatus } from '../entities/product-history-status.entity'; | ||||
|  | ||||
| @Injectable() | ||||
| export class ProductHistoryStatusService { | ||||
|   constructor( | ||||
|     @InjectRepository(ProductHistoryStatus) | ||||
|     private productHistoryStatusRepository: Repository<ProductHistoryStatus>, | ||||
|   ) {} | ||||
|  | ||||
|   async create(dataProduct: ProductHistoryStatus) { | ||||
|     const result = await this.productHistoryStatusRepository.insert( | ||||
|       dataProduct, | ||||
|     ); | ||||
|  | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   async findOneActive(productId: string, partnerId: string) { | ||||
|     try { | ||||
|       return await this.productHistoryStatusRepository.findOneOrFail({ | ||||
|         relations: ['product'], | ||||
|         where: { | ||||
|           product: productId, | ||||
|           partner: partnerId, | ||||
|         }, | ||||
|       }); | ||||
|     } catch (e) { | ||||
|       if (e instanceof EntityNotFoundError) { | ||||
|         throw new HttpException( | ||||
|           { | ||||
|             statusCode: HttpStatus.NOT_FOUND, | ||||
|             error: 'Product not active', | ||||
|           }, | ||||
|           HttpStatus.NOT_FOUND, | ||||
|         ); | ||||
|       } else { | ||||
|         throw e; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @@ -11,6 +11,7 @@ import { ProductSubCategoriesService } from './product-sub-categories.service'; | ||||
| import { UsersModule } from '../users/users.module'; | ||||
| import { ProductHistoryPriceService } from './history-price/history-price.service'; | ||||
| import {ProductHistoryStatus} from "./entities/product-history-status.entity"; | ||||
| import {ProductHistoryStatusService} from "./history-status/history-status.service"; | ||||
|  | ||||
| @Module({ | ||||
|   imports: [ | ||||
| @@ -29,7 +30,8 @@ import {ProductHistoryStatus} from "./entities/product-history-status.entity"; | ||||
|     ProductCategoriesService, | ||||
|     ProductSubCategoriesService, | ||||
|     ProductHistoryPriceService, | ||||
|     ProductHistoryStatusService, | ||||
|   ], | ||||
|   exports: [ProductService, ProductHistoryPriceService], | ||||
|   exports: [ProductService, ProductHistoryPriceService, ProductHistoryStatusService], | ||||
| }) | ||||
| export class ProductModule {} | ||||
|   | ||||
| @@ -12,7 +12,8 @@ import { UsersModule } from 'src/users/users.module'; | ||||
| import { ConfigurableModule } from '../configurable/configurable.module'; | ||||
| import { CheckBillHistory } from './entities/check-bill-history.entity'; | ||||
| import { CallbackPartner } from './entities/callback-partner.entity'; | ||||
| import {ProductHistoryPrice} from "../product/entities/product-history-price.entity"; | ||||
| import { ProductHistoryPrice } from '../product/entities/product-history-price.entity'; | ||||
| import { ProductHistoryStatus } from '../product/entities/product-history-status.entity'; | ||||
|  | ||||
| @Module({ | ||||
|   imports: [ | ||||
| @@ -23,6 +24,7 @@ import {ProductHistoryPrice} from "../product/entities/product-history-price.ent | ||||
|       CheckBillHistory, | ||||
|       CallbackPartner, | ||||
|       ProductHistoryPrice, | ||||
|       ProductHistoryStatus, | ||||
|     ]), | ||||
|     ProductModule, | ||||
|     ConfigurableModule, | ||||
|   | ||||
| @@ -37,6 +37,7 @@ import axios from 'axios'; | ||||
| import { CheckBillHistory } from './entities/check-bill-history.entity'; | ||||
| import { CallbackPartner } from './entities/callback-partner.entity'; | ||||
| import { doAuthorizeHemat } from '../helper/sihemat-authorization'; | ||||
| import { ProductHistoryStatusService } from '../product/history-status/history-status.service'; | ||||
|  | ||||
| @Injectable() | ||||
| export class TransactionService { | ||||
| @@ -58,6 +59,7 @@ export class TransactionService { | ||||
|       private coaService: CoaService, | ||||
|       private productService: ProductService, | ||||
|       private productHistoryPriceService: ProductHistoryPriceService, | ||||
|       private productHistoryStatusService: ProductHistoryStatusService, | ||||
|       private userService: UsersService, | ||||
|       private commissionService: CommissionService, | ||||
|       private supplierService: SupplierService, | ||||
| @@ -520,6 +522,20 @@ export class TransactionService { | ||||
|         product.supplier.code, | ||||
|     ); | ||||
|  | ||||
|     const statusProduct = await this.productHistoryStatusService.findOneActive( | ||||
|       product.id, | ||||
|       userData.partner.id ? userData.partner.id : null, | ||||
|     ); | ||||
|  | ||||
|     if (statusProduct.status == 'NOT ACTIVE') { | ||||
|       throw new HttpException( | ||||
|             { | ||||
|               statusCode: HttpStatus.INTERNAL_SERVER_ERROR, | ||||
|               error: `Transaction Failed because product is not active`, | ||||
|             }, | ||||
|             HttpStatus.INTERNAL_SERVER_ERROR, | ||||
|         ); | ||||
|     } else { | ||||
|     console.log('userdatapartnerid', userData.partner?.id); | ||||
|  | ||||
|     let product_price = await this.productHistoryPriceService.findOne( | ||||
| @@ -618,8 +634,8 @@ export class TransactionService { | ||||
|     console.log('iniresponsupplier', hitSupplier.harga) | ||||
|     console.log(supplier.code, 'sdkfjsd'); | ||||
|     console.log(product_price, 'price'); | ||||
|      | ||||
|      | ||||
|  | ||||
|  | ||||
|     if (supplier.code == 'metro') { | ||||
|       const parsingResponse = hitSupplier.split(' '); | ||||
|       console.log('parsingResponse', parsingResponse) | ||||
| @@ -651,7 +667,7 @@ export class TransactionService { | ||||
|     } | ||||
|  | ||||
|     console.log(hitSupplier, 'newhitSupplier'); | ||||
|      | ||||
|  | ||||
|     // const hitSupplier = { | ||||
|     //   harga: 2000, | ||||
|     //   success: true, | ||||
| @@ -768,7 +784,7 @@ export class TransactionService { | ||||
|       amount: product_price.mark_up_price + product_price.price, | ||||
|       status: status, | ||||
|     }; | ||||
|     // } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async orderTransactionBillProd( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user