fix: update item to update item rate
parent
9815c667f0
commit
464c10722c
|
@ -6,6 +6,7 @@ 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';
|
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
|
||||||
|
import { ItemRateDataService } from 'src/modules/item-related/item-rate/data/services/item-rate-data.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ItemDataService extends BaseDataService<ItemEntity> {
|
export class ItemDataService extends BaseDataService<ItemEntity> {
|
||||||
|
@ -15,6 +16,7 @@ export class ItemDataService extends BaseDataService<ItemEntity> {
|
||||||
|
|
||||||
@InjectRepository(ItemRateModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(ItemRateModel, CONNECTION_NAME.DEFAULT)
|
||||||
private repoItemRate: Repository<ItemRateModel>,
|
private repoItemRate: Repository<ItemRateModel>,
|
||||||
|
private rateService: ItemRateDataService,
|
||||||
) {
|
) {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
@ -31,4 +33,34 @@ export class ItemDataService extends BaseDataService<ItemEntity> {
|
||||||
{ price: newPrice },
|
{ price: newPrice },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateBreakdownBundling(id: string): Promise<void> {
|
||||||
|
const item_rates = await this.repoItemRate.find({
|
||||||
|
where: {
|
||||||
|
item_id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const rate of item_rates) {
|
||||||
|
const { item_id, season_period_id } = rate;
|
||||||
|
const bundling = await this.repo.findOne({
|
||||||
|
relations: ['bundling_items'],
|
||||||
|
where: {
|
||||||
|
id: item_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(bundling.name);
|
||||||
|
const ids = bundling.bundling_items.map((item) => item.id);
|
||||||
|
const totalRates = await this.rateService.itemsRateTotal(
|
||||||
|
season_period_id,
|
||||||
|
ids,
|
||||||
|
);
|
||||||
|
this.rateService.updateRatesBySeasonItem(
|
||||||
|
season_period_id,
|
||||||
|
bundling.id,
|
||||||
|
totalRates,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,4 +16,5 @@ export interface ItemEntity extends BaseStatusEntity {
|
||||||
|
|
||||||
use_queue: boolean;
|
use_queue: boolean;
|
||||||
show_to_booking: boolean;
|
show_to_booking: boolean;
|
||||||
|
breakdown_bundling?: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,10 @@ export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
|
||||||
newBasePrice,
|
newBasePrice,
|
||||||
itemId,
|
itemId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.result.breakdown_bundling) {
|
||||||
|
this.dataService.updateBreakdownBundling(itemId);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue