Merge branch 'master' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into devops-production
This commit is contained in:
commit
db8e09bc70
20
src/product/entities/product-history-status.entity.ts
Normal file
20
src/product/entities/product-history-status.entity.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Product } from './product.entity';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { productType } from '../../helper/enum-list';
|
||||
import { Partner } from '../../users/entities/partner.entity';
|
||||
|
||||
@Entity()
|
||||
export class ProductHistoryStatus extends BaseModel {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@ManyToOne(() => Product, (product) => product.id)
|
||||
product: Product;
|
||||
|
||||
@ManyToOne(() => Partner, (partner) => partner.id)
|
||||
partner: Partner;
|
||||
|
||||
@Column()
|
||||
status: string;
|
||||
}
|
|
@ -3,6 +3,7 @@ import { ProductSubCategories } from './product-sub-category.entity';
|
|||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { Supplier } from '../../users/entities/supplier.entity';
|
||||
import { ProductHistoryPrice } from './product-history-price.entity';
|
||||
import {ProductHistoryStatus} from "./product-history-status.entity";
|
||||
|
||||
@Entity()
|
||||
export class Product extends BaseModel {
|
||||
|
@ -53,6 +54,19 @@ export class Product extends BaseModel {
|
|||
)
|
||||
supplier: Supplier;
|
||||
|
||||
|
||||
@OneToMany(
|
||||
() => {
|
||||
return ProductHistoryStatus;
|
||||
},
|
||||
(php) => {
|
||||
return php.product;
|
||||
},
|
||||
)
|
||||
statusHistory: ProductHistoryStatus;
|
||||
|
||||
currentStatus: ProductHistoryStatus;
|
||||
|
||||
@OneToMany(
|
||||
() => {
|
||||
return ProductHistoryPrice;
|
||||
|
|
|
@ -10,6 +10,7 @@ import { ProductSubCategories } from './entities/product-sub-category.entity';
|
|||
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";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -17,6 +18,7 @@ import { ProductHistoryPriceService } from './history-price/history-price.servic
|
|||
Product,
|
||||
ProductCategories,
|
||||
ProductHistoryPrice,
|
||||
ProductHistoryStatus,
|
||||
ProductSubCategories,
|
||||
]),
|
||||
forwardRef(() => UsersModule),
|
||||
|
|
|
@ -13,6 +13,7 @@ import { SupplierService } from '../users/supplier/supplier.service';
|
|||
import { parsingFile } from '../helper/csv-parser';
|
||||
import { PartnerService } from '../users/partner/partner.service';
|
||||
import { mapSeries } from 'bluebird';
|
||||
import { ProductHistoryStatus } from './entities/product-history-status.entity';
|
||||
|
||||
export class ProductService {
|
||||
constructor(
|
||||
|
@ -20,6 +21,8 @@ export class ProductService {
|
|||
private productRepository: Repository<Product>,
|
||||
@InjectRepository(ProductHistoryPrice)
|
||||
private productHistoryPrice: Repository<ProductHistoryPrice>,
|
||||
@InjectRepository(ProductHistoryStatus)
|
||||
private productHistoryStatus: Repository<ProductHistoryStatus>,
|
||||
private productSubCategoriesService: ProductSubCategoriesService,
|
||||
private usersService: UsersService,
|
||||
private supplierService: SupplierService,
|
||||
|
@ -103,6 +106,13 @@ export class ProductService {
|
|||
});
|
||||
}
|
||||
|
||||
await this.productHistoryStatus.insert({
|
||||
product: productData,
|
||||
partner: it[6] != '-' ? partnerData : null,
|
||||
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
||||
|
||||
});
|
||||
|
||||
await this.productHistoryPrice.insert({
|
||||
product: productData,
|
||||
mark_up_price: it[4],
|
||||
|
@ -129,6 +139,12 @@ export class ProductService {
|
|||
type: it[7] == 'postpaid' ? 'postpaid' : 'prepaid',
|
||||
});
|
||||
|
||||
await this.productHistoryStatus.insert({
|
||||
product: savedProduct.identifiers[0],
|
||||
partner: partnerData,
|
||||
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
||||
});
|
||||
|
||||
return await this.productHistoryPrice.insert({
|
||||
product: savedProduct.identifiers[0],
|
||||
mark_up_price: it[4],
|
||||
|
@ -178,6 +194,12 @@ export class ProductService {
|
|||
'current_price',
|
||||
'current_price.end_date is NULL',
|
||||
)
|
||||
.innerJoinAndMapOne(
|
||||
'product.currentStatus',
|
||||
'product.statusHistory',
|
||||
'history_status',
|
||||
'history_status.deleted_at is NULL'
|
||||
)
|
||||
.select(['product.id'])
|
||||
.addSelect([
|
||||
'product.name',
|
||||
|
@ -185,8 +207,8 @@ export class ProductService {
|
|||
'sub_categories.name',
|
||||
'supplier.name',
|
||||
'category.name',
|
||||
'product.status',
|
||||
])
|
||||
.addSelect('history_status.status', 'status')
|
||||
.addSelect('current_price.price', 'price')
|
||||
.addSelect('current_price.partner_fee', 'partner_fee')
|
||||
.addSelect('current_price.admin_price', 'admin_price')
|
||||
|
@ -260,6 +282,8 @@ export class ProductService {
|
|||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
|
||||
.leftJoin('product.statusHistory', 'status_history')
|
||||
|
||||
.leftJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
|
@ -267,7 +291,7 @@ export class ProductService {
|
|||
'current_price.partner_id is NULL and current_price.end_date is NULL',
|
||||
)
|
||||
.where(
|
||||
`product.supplier_id = :supplier_id and product.status = 'ACTIVE'`,
|
||||
`product.supplier_id = :supplier_id and status_history.status = 'ACTIVE'`,
|
||||
{
|
||||
supplier_id: supplier,
|
||||
},
|
||||
|
@ -329,7 +353,6 @@ export class ProductService {
|
|||
'supplier',
|
||||
'supplier.status = true',
|
||||
)
|
||||
.where(`product.status = 'ACTIVE'`)
|
||||
.innerJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
|
@ -339,18 +362,29 @@ export class ProductService {
|
|||
id_partner: user.partner.id,
|
||||
},
|
||||
)
|
||||
.innerJoinAndMapOne(
|
||||
'product.currentStatus',
|
||||
'product.statusHistory',
|
||||
'history_status',
|
||||
'history_status.deleted_at is NULL'
|
||||
)
|
||||
.where(`history_status.partner_id = :id_partner and history_status.status = 'ACTIVE'`,
|
||||
{
|
||||
id_partner: user.partner.id,
|
||||
},
|
||||
)
|
||||
.select(['product.id'])
|
||||
.addSelect([
|
||||
'product.name',
|
||||
'product.code',
|
||||
'product.type',
|
||||
'product.status',
|
||||
'sub_categories.name',
|
||||
'current_price.admin_price as admin_price',
|
||||
'current_price.mark_up_price as markup_price',
|
||||
'current_price.partner_fee as partner_fee',
|
||||
'current_price.price as price',
|
||||
])
|
||||
.addSelect('history_status.status', 'status')
|
||||
// .addSelect(
|
||||
// '(current_price.price + current_price.mark_up_price) as price',
|
||||
// );
|
||||
|
@ -369,7 +403,7 @@ export class ProductService {
|
|||
if (subCategories && filterSubCategories.length > 0) {
|
||||
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
||||
subCategoryId: filterSubCategories,
|
||||
}).andWhere(`product.status = 'ACTIVE'`)
|
||||
}).andWhere(`history_status.status = 'ACTIVE'`)
|
||||
}
|
||||
|
||||
const newData = []
|
||||
|
@ -435,7 +469,6 @@ export class ProductService {
|
|||
relations: ['supplier'],
|
||||
where: {
|
||||
code: code,
|
||||
status: 'ACTIVE',
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
|
@ -497,6 +530,15 @@ export class ProductService {
|
|||
updateProductDto.subCategoriesId,
|
||||
);
|
||||
|
||||
const dataStatus = await this.productHistoryStatus.findOne({
|
||||
where: {
|
||||
product: id,
|
||||
},
|
||||
});
|
||||
|
||||
await this.productHistoryStatus.update(dataStatus.id, {
|
||||
status: updateProductDto.status,
|
||||
});
|
||||
const result = await this.productRepository.update(id, {
|
||||
name: updateProductDto.name,
|
||||
code: updateProductDto.code,
|
||||
|
|
|
@ -310,7 +310,7 @@ export class TransactionService {
|
|||
'prepaid',
|
||||
);
|
||||
|
||||
if (!productData.status.includes('ACTIVE')) {
|
||||
if (!productData.statusHistory.status.includes('ACTIVE')) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
|
@ -467,7 +467,7 @@ export class TransactionService {
|
|||
'prepaid',
|
||||
);
|
||||
|
||||
if (!productData.status.includes('ACTIVE')) {
|
||||
if (!productData.statusHistory.status.includes('ACTIVE')) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
|
|
Loading…
Reference in New Issue
Block a user