add: product price
This commit is contained in:
@@ -13,6 +13,9 @@ export class CreateProductDto {
|
||||
@IsNotEmpty()
|
||||
price: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
markUpPrice: number;
|
||||
|
||||
@IsUUID()
|
||||
subCategoriesId: string;
|
||||
}
|
||||
|
||||
17
src/product/dto/product/update-price-product.dto.ts
Normal file
17
src/product/dto/product/update-price-product.dto.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
import { productType } from '../../../helper/enum-list';
|
||||
|
||||
export class UpdatePriceProductDto {
|
||||
@IsNotEmpty()
|
||||
price: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
markUpPrice: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
type: productType;
|
||||
|
||||
startDate: Date;
|
||||
|
||||
endDate: Date;
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { OmitType, PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateProductDto } from './create-product.dto';
|
||||
|
||||
export class UpdateProductDto extends PartialType(CreateProductDto) {}
|
||||
export class UpdateProductDto extends PartialType(
|
||||
OmitType(CreateProductDto, ['price'] as const),
|
||||
) {}
|
||||
|
||||
@@ -19,6 +19,9 @@ export class ProductHistoryPrice extends BaseModel {
|
||||
@Column()
|
||||
price: number;
|
||||
|
||||
@Column()
|
||||
markUpPrice: number;
|
||||
|
||||
@Column({ type: 'date' })
|
||||
startDate: Date;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { ProductSubCategoriesService } from './product-sub-categories.service';
|
||||
import { UpdateProductDto } from './dto/product/update-product.dto';
|
||||
import { ProductHistoryPrice } from './entities/product-history-price.entity';
|
||||
import { productType } from '../helper/enum-list';
|
||||
import { UpdatePriceProductDto } from './dto/product/update-price-product.dto';
|
||||
|
||||
export class ProductService {
|
||||
constructor(
|
||||
@@ -33,6 +34,8 @@ export class ProductService {
|
||||
await this.productHistoryPrice.insert({
|
||||
product: result.identifiers[0],
|
||||
type: productType.NORMAL,
|
||||
price: createProductDto.price,
|
||||
markUpPrice: createProductDto.markUpPrice,
|
||||
startDate: new Date(),
|
||||
endDate: null,
|
||||
});
|
||||
@@ -84,6 +87,7 @@ export class ProductService {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
const subCategories = await this.productSubCategoriesService.findOne(
|
||||
updateProductDto.subCategoriesId,
|
||||
);
|
||||
@@ -93,12 +97,29 @@ export class ProductService {
|
||||
code: updateProductDto.code,
|
||||
status: updateProductDto.status,
|
||||
subCategories: subCategories,
|
||||
price: updateProductDto.price,
|
||||
});
|
||||
|
||||
return this.productRepository.findOneOrFail(id);
|
||||
}
|
||||
|
||||
async updatePrice(
|
||||
code: string,
|
||||
updatePriceProductDto: UpdatePriceProductDto,
|
||||
) {
|
||||
const product = await this.findOne(code);
|
||||
|
||||
await this.productHistoryPrice.insert({
|
||||
product: product,
|
||||
type: updatePriceProductDto.type,
|
||||
price: updatePriceProductDto.price,
|
||||
markUpPrice: updatePriceProductDto.markUpPrice,
|
||||
startDate: updatePriceProductDto.startDate,
|
||||
endDate: updatePriceProductDto.endDate,
|
||||
});
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
try {
|
||||
await this.productRepository.findOneOrFail(id);
|
||||
|
||||
Reference in New Issue
Block a user