feat(SPG-782): update base price at item rate when price on item rate not edited before
parent
f8618ec0cd
commit
8de744bc58
|
@ -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,
|
||||
|
|
|
@ -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 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue