Compare commits
No commits in common. "7c7b121b493822febae105376156e594f9eef546" and "fc15cb9db6588d74925bcf261794b9135a479af2" have entirely different histories.
7c7b121b49
...
fc15cb9db6
|
@ -13,7 +13,7 @@ export class FixDemographyNationality1723716561482
|
||||||
`ALTER TABLE "transaction_demographies" DROP COLUMN "foreign"`,
|
`ALTER TABLE "transaction_demographies" DROP COLUMN "foreign"`,
|
||||||
);
|
);
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`CREATE TYPE "public"."transaction_demographies_nationality_enum" AS ENUM('local', 'foreign', 'mix')`,
|
`CREATE TYPE "public"."transaction_demographies_nationality_enum" AS ENUM('local', 'foreign')`,
|
||||||
);
|
);
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`ALTER TABLE "transaction_demographies" ADD "nationality" "public"."transaction_demographies_nationality_enum" NOT NULL DEFAULT 'local'`,
|
`ALTER TABLE "transaction_demographies" ADD "nationality" "public"."transaction_demographies_nationality_enum" NOT NULL DEFAULT 'local'`,
|
||||||
|
|
|
@ -4,64 +4,14 @@ import { ItemRateEntity } from '../../domain/entities/item-rate.entity';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { ItemRateModel } from '../models/item-rate.model';
|
import { ItemRateModel } from '../models/item-rate.model';
|
||||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
import { In, Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ItemRateDataService extends BaseDataService<ItemRateEntity> {
|
export class ItemRateDataService extends BaseDataService<ItemRateEntity> {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(ItemRateModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(ItemRateModel, CONNECTION_NAME.DEFAULT)
|
||||||
private repo: Repository<ItemRateModel>,
|
private repo: Repository<ItemRateModel>,
|
||||||
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private itemRepo: Repository<ItemModel>,
|
|
||||||
) {
|
) {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
async itemsRateTotal(season_id: string, items: string[]): Promise<number> {
|
|
||||||
const rates = await this.repo.find({
|
|
||||||
where: {
|
|
||||||
season_period_id: season_id,
|
|
||||||
item_id: In(items),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return rates.reduce((total, current) => total + Number(current.price), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateRatesBySeasonItem(
|
|
||||||
season_id: string,
|
|
||||||
item_id: string,
|
|
||||||
price: number,
|
|
||||||
): Promise<void> {
|
|
||||||
this.repo.update(
|
|
||||||
{
|
|
||||||
season_period_id: season_id,
|
|
||||||
item_id,
|
|
||||||
},
|
|
||||||
{ price },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async findBundlingByItem(item_id: string): Promise<ItemModel[]> {
|
|
||||||
const bundlings = await this.itemRepo.find({
|
|
||||||
where: {
|
|
||||||
breakdown_bundling: true,
|
|
||||||
bundling_items: {
|
|
||||||
id: item_id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.all(
|
|
||||||
await bundlings.map(async (bundling) => {
|
|
||||||
return await this.itemRepo.findOne({
|
|
||||||
relations: ['bundling_items'],
|
|
||||||
where: {
|
|
||||||
id: bundling.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { ItemRateEntity } from '../entities/item-rate.entity';
|
||||||
import { DeleteItemRateManager } from './managers/delete-item-rate.manager';
|
import { DeleteItemRateManager } from './managers/delete-item-rate.manager';
|
||||||
import { UpdateItemRateManager } from './managers/update-item-rate.manager';
|
import { UpdateItemRateManager } from './managers/update-item-rate.manager';
|
||||||
import { BaseDataOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data.orchestrator';
|
import { BaseDataOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data.orchestrator';
|
||||||
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { BatchDeleteItemRateManager } from './managers/batch-delete-item-rate.manager';
|
import { BatchDeleteItemRateManager } from './managers/batch-delete-item-rate.manager';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
|
|
@ -20,7 +20,6 @@ export class UpdateItemRateManager extends BaseUpdateManager<ItemRateEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterProcess(): Promise<void> {
|
async afterProcess(): Promise<void> {
|
||||||
this.updateBundlingBreakdown(this.dataId);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,25 +42,4 @@ export class UpdateItemRateManager extends BaseUpdateManager<ItemRateEntity> {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateBundlingBreakdown(id: string) {
|
|
||||||
const { item_id, season_period_id } =
|
|
||||||
await this.dataService.getOneByOptions({
|
|
||||||
where: { id },
|
|
||||||
});
|
|
||||||
const bundlings = await this.dataService.findBundlingByItem(item_id);
|
|
||||||
|
|
||||||
for (const bundling of bundlings) {
|
|
||||||
const ids = bundling.bundling_items.map((item) => item.id);
|
|
||||||
const totalRates = await this.dataService.itemsRateTotal(
|
|
||||||
season_period_id,
|
|
||||||
ids,
|
|
||||||
);
|
|
||||||
this.dataService.updateRatesBySeasonItem(
|
|
||||||
season_period_id,
|
|
||||||
bundling.id,
|
|
||||||
totalRates,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { Body, Controller, Get, Param, Put } from '@nestjs/common';
|
import { Body, Controller, Delete, Param, Post, Put } from '@nestjs/common';
|
||||||
import { ItemRateDataOrchestrator } from '../domain/usecases/item-rate-data.orchestrator';
|
import { ItemRateDataOrchestrator } from '../domain/usecases/item-rate-data.orchestrator';
|
||||||
import { ItemRateDto } from './dto/item-rate.dto';
|
import { ItemRateDto } from './dto/item-rate.dto';
|
||||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { ItemRateEntity } from '../domain/entities/item-rate.entity';
|
import { ItemRateEntity } from '../domain/entities/item-rate.entity';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.ITEM_RATE.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.ITEM_RATE.split('-').join(' ')} - data`)
|
||||||
|
|
|
@ -19,14 +19,13 @@ import { ItemRateModel } from './data/models/item-rate.model';
|
||||||
import { SeasonPeriodHolidayHandler } from './domain/usecases/handlers/item-created.handler';
|
import { SeasonPeriodHolidayHandler } from './domain/usecases/handlers/item-created.handler';
|
||||||
import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service';
|
import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service';
|
||||||
import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model';
|
import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model';
|
||||||
import { ItemModel } from '../item/data/models/item.model';
|
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
TypeOrmModule.forFeature(
|
TypeOrmModule.forFeature(
|
||||||
[ItemRateModel, SeasonPeriodModel, ItemModel],
|
[ItemRateModel, SeasonPeriodModel],
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
|
|
|
@ -33,5 +33,4 @@ export const TransactionModels = [
|
||||||
export enum DemographyNationality {
|
export enum DemographyNationality {
|
||||||
LOCAL = 'local',
|
LOCAL = 'local',
|
||||||
FOREIGN = 'foreign',
|
FOREIGN = 'foreign',
|
||||||
MIX = 'mix',
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue