feat(SPG-782): update base price at item rate when price on item rate not edited before

pull/59/head
Firman Ramdhani 2024-08-08 13:19:03 +07:00
parent f8618ec0cd
commit 8de744bc58
3 changed files with 30 additions and 0 deletions

View File

@ -43,6 +43,7 @@ import { TransactionModel } from 'src/modules/transaction/transaction/data/model
import { TransactionTaxModel } from 'src/modules/transaction/transaction/data/models/transaction-tax.model';
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
@Module({
imports: [
@ -50,6 +51,7 @@ import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
TypeOrmModule.forFeature(
[
ItemModel,
ItemRateModel,
UserModel,
TransactionModel,
TransactionTaxModel,

View File

@ -5,13 +5,30 @@ import { InjectRepository } from '@nestjs/typeorm';
import { ItemModel } from '../models/item.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { Repository } from 'typeorm';
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
@Injectable()
export class ItemDataService extends BaseDataService<ItemEntity> {
constructor(
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<ItemModel>,
@InjectRepository(ItemRateModel, CONNECTION_NAME.DEFAULT)
private repoItemRate: Repository<ItemRateModel>,
) {
super(repo);
}
async updateItemRatePrice(
oldPrice: number,
newPrice: number,
itemId: string,
): Promise<void> {
console.log({ oldPrice, newPrice, itemId });
this.repoItemRate.update(
{ item_id: itemId, price: oldPrice },
{ price: newPrice },
);
}
}

View File

@ -11,15 +11,26 @@ import {
@Injectable()
export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
protected oldBasePrice: number;
async validateProcess(): Promise<void> {
return;
}
async beforeProcess(): Promise<void> {
this.oldBasePrice = this.oldData.base_price;
return;
}
async afterProcess(): Promise<void> {
const newBasePrice = this.result.base_price;
const itemId = this.result.id;
await this.dataService.updateItemRatePrice(
this.oldBasePrice,
newBasePrice,
itemId,
);
return;
}