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 { TransactionTaxModel } from 'src/modules/transaction/transaction/data/models/transaction-tax.model';
|
||||||
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
||||||
import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
|
import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
|
||||||
|
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -50,6 +51,7 @@ import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
|
||||||
TypeOrmModule.forFeature(
|
TypeOrmModule.forFeature(
|
||||||
[
|
[
|
||||||
ItemModel,
|
ItemModel,
|
||||||
|
ItemRateModel,
|
||||||
UserModel,
|
UserModel,
|
||||||
TransactionModel,
|
TransactionModel,
|
||||||
TransactionTaxModel,
|
TransactionTaxModel,
|
||||||
|
|
|
@ -5,13 +5,30 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { ItemModel } from '../models/item.model';
|
import { ItemModel } from '../models/item.model';
|
||||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ItemDataService extends BaseDataService<ItemEntity> {
|
export class ItemDataService extends BaseDataService<ItemEntity> {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
|
||||||
private repo: Repository<ItemModel>,
|
private repo: Repository<ItemModel>,
|
||||||
|
|
||||||
|
@InjectRepository(ItemRateModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repoItemRate: Repository<ItemRateModel>,
|
||||||
) {
|
) {
|
||||||
super(repo);
|
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()
|
@Injectable()
|
||||||
export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
|
export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
|
||||||
|
protected oldBasePrice: number;
|
||||||
|
|
||||||
async validateProcess(): Promise<void> {
|
async validateProcess(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async beforeProcess(): Promise<void> {
|
async beforeProcess(): Promise<void> {
|
||||||
|
this.oldBasePrice = this.oldData.base_price;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterProcess(): Promise<void> {
|
async afterProcess(): Promise<void> {
|
||||||
|
const newBasePrice = this.result.base_price;
|
||||||
|
const itemId = this.result.id;
|
||||||
|
|
||||||
|
await this.dataService.updateItemRatePrice(
|
||||||
|
this.oldBasePrice,
|
||||||
|
newBasePrice,
|
||||||
|
itemId,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue