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