diff --git a/api/src/modules/import/services/entity.preprocessor.ts b/api/src/modules/import/services/entity.preprocessor.ts index 6d2d0bf3..4a2f286f 100644 --- a/api/src/modules/import/services/entity.preprocessor.ts +++ b/api/src/modules/import/services/entity.preprocessor.ts @@ -1118,9 +1118,9 @@ export class EntityPreprocessor { project.projectSize = row.project_size_ha; project.projectSizeFilter = row.project_size_filter; project.abatementPotential = row.abatement_potential; - project.opexNpv = row.opex_npv; + project.opexNPV = row.opex_npv; project.opex = row.opex; - project.capexNpv = row.capex_npv; + project.capexNPV = row.capex_npv; project.capex = row.capex; project.totalCostNPV = row.total_cost_npv; project.totalCost = row.total_cost; diff --git a/api/src/modules/projects/projects.service.ts b/api/src/modules/projects/projects.service.ts index cd17f263..ad78b0c4 100644 --- a/api/src/modules/projects/projects.service.ts +++ b/api/src/modules/projects/projects.service.ts @@ -28,27 +28,34 @@ export class ProjectsService extends AppBaseService< public async findAllProjectsWithMaximums( query: ProjectFetchSpecificacion, ): Promise { + // Elena told us that the maximum values of the abatement_potential and max_total_cost bars is the sum of all values of the filtered results const qb = this.dataSource .createQueryBuilder() - .select('SUM(abatement_potential)::integer', 'maxAbatementPotential') + .select('SUM(abatement_potential)::BIGINT', 'maxAbatementPotential') .from(Project, 'project'); const { costRangeSelector } = query; if (costRangeSelector == COST_TYPE_SELECTOR.NPV) { - qb.addSelect('SUM(capex_npv + opex_npv)::integer', 'maxTotalCost'); + qb.addSelect('SUM(capex_npv + opex_npv)::BIGINT', 'maxTotalCost'); } else { - qb.addSelect('SUM(capex + opex)::integer', 'maxTotalCost'); + qb.addSelect('SUM(capex + opex)::BIGINT', 'maxTotalCost'); } const totalsQuery = this.applySearchFiltersToQueryBuilder(qb, query); - const [maximums, { metadata, data }] = await Promise.all([ - totalsQuery.getRawOne(), - this.findAllPaginated(query), - ]); + const [{ maxAbatementPotential, maxTotalCost }, { metadata, data }] = + await Promise.all([ + totalsQuery.getRawOne(), + this.findAllPaginated(query), + ]); + + // The numbers are too big at the moment. return { metadata, - maximums, + maximums: { + maxAbatementPotential: Number(maxAbatementPotential), + maxTotalCost: Number(maxTotalCost), + }, data, }; } diff --git a/shared/dtos/projects/projects.dto.ts b/shared/dtos/projects/projects.dto.ts index 1e8f9daf..d1f5b7cc 100644 --- a/shared/dtos/projects/projects.dto.ts +++ b/shared/dtos/projects/projects.dto.ts @@ -6,6 +6,6 @@ export class PaginatedProjectsWithMaximums { data: Partial[]; maximums: { maxAbatementPotential: number; - maxCost: number; + maxTotalCost: number; }; } diff --git a/shared/entities/projects.entity.ts b/shared/entities/projects.entity.ts index 84a26f31..c207eaf6 100644 --- a/shared/entities/projects.entity.ts +++ b/shared/entities/projects.entity.ts @@ -73,13 +73,13 @@ export class Project extends BaseEntity { abatementPotential: number; @Column({ name: "capex_npv", type: "decimal", nullable: true }) - capexNpv: number; + capexNPV: number; @Column({ name: "capex", type: "decimal", nullable: true }) capex: number; @Column({ name: "opex_npv", type: "decimal", nullable: true }) - opexNpv: number; + opexNPV: number; @Column({ name: "opex", type: "decimal", nullable: true }) opex: number; diff --git a/shared/lib/entity-mocks.ts b/shared/lib/entity-mocks.ts index 7ac4aae3..66f93c88 100644 --- a/shared/lib/entity-mocks.ts +++ b/shared/lib/entity-mocks.ts @@ -55,9 +55,9 @@ export const createProject = async ( totalCost: 100, costPerTCO2eNPV: 100, costPerTCO2e: 100, - capexNpv: 100, + capexNPV: 100, capex: 50, - opexNpv: 100, + opexNPV: 100, opex: 50, initialPriceAssumption: "$100", priceType: PROJECT_PRICE_TYPE.MARKET_PRICE,