From 462f6186296968001e35deead003817767ffa9f7 Mon Sep 17 00:00:00 2001 From: Catalin Oancea Date: Wed, 18 Dec 2024 12:29:07 +0200 Subject: [PATCH] Import all project columns --- shared/contracts/projects.contract.ts | 11 + shared/entities/project-scorecard.view.ts | 284 ++++++++++++++++++++- shared/entities/projects.entity.ts | 296 +++++++++++++++++++++- shared/lib/entity-mocks.ts | 2 +- 4 files changed, 571 insertions(+), 22 deletions(-) diff --git a/shared/contracts/projects.contract.ts b/shared/contracts/projects.contract.ts index 40df6bc7..a7173900 100644 --- a/shared/contracts/projects.contract.ts +++ b/shared/contracts/projects.contract.ts @@ -52,6 +52,17 @@ export const projectsContract = contract.router({ }, query: getProjectScorecardQuerySchema, }, + getProjectWithScorecard: { + method: "GET", + path: "/projects/:id/scorecard", + pathParams: z.object({ + id: z.coerce.string().uuid(), + }), + responses: { + 200: contract.type>(), + }, + query: projectScorecardQuerySchema, + }, getProject: { method: "GET", path: "/projects/:id", diff --git a/shared/entities/project-scorecard.view.ts b/shared/entities/project-scorecard.view.ts index 3eb1175d..308b8cb0 100644 --- a/shared/entities/project-scorecard.view.ts +++ b/shared/entities/project-scorecard.view.ts @@ -10,23 +10,72 @@ export const decimalTransformer: ValueTransformer = { name: "project_scorecard_view", expression: ` SELECT + p.id as id, p.country_code AS country_code, p.ecosystem AS ecosystem, - p.activity AS activity, - p.restoration_activity AS activity_subtype, - p.project_name AS project_name, + p.activity AS activity, + p.restoration_activity AS activity_subtype, + p.project_name AS project_name, ps.financial_feasibility AS financial_feasibility, - ps.legal_feasibility AS legal_feasibility, - ps.implementation_feasibility AS implementation_feasibility, - ps.social_feasibility AS social_feasibility, - ps.security_rating AS security_rating, - ps.availability_of_experienced_labor AS availability_of_experienced_labor, - ps.availability_of_alternating_funding AS availability_of_alternating_funding, - ps.coastal_protection_benefits AS coastal_protection_benefits, - ps.biodiversity_benefit AS biodiversity_benefit, - p.abatement_potential AS abatement_potential, - p.total_cost AS total_cost, - p.total_cost_npv AS total_cost_npv + ps.legal_feasibility AS legal_feasibility, + ps.implementation_feasibility AS implementation_feasibility, + ps.social_feasibility AS social_feasibility, + ps.security_rating AS security_rating, + ps.availability_of_experienced_labor AS availability_of_experienced_labor, + ps.availability_of_alternating_funding AS availability_of_alternating_funding, + ps.coastal_protection_benefits AS coastal_protection_benefits, + ps.biodiversity_benefit AS biodiversity_benefit, + p.total_cost AS total_cost, + p.total_cost_npv AS total_cost_npv, + p.project_size AS project_size, + p.project_size_filter AS project_size_filter, + p.price_type AS price_type, + p.abatement_potential AS abatement_potential, + p.capex_npv AS capex_npv, + p.capex AS capex, + p.opex_npv AS opex_npv, + p.opex AS opex, + p.cost_per_tco2e_npv AS cost_per_tco2e_npv, + p.cost_per_tco2e AS cost_per_tco2e, + p.feasibility_analysis_npv AS feasibility_analysis_npv, + p.feasibility_analysis AS feasibility_analysis, + p.conservation_planning_npv AS conservation_planning_npv, + p.conservation_planning AS conservation_planning, + p.data_collection_npv AS data_collection_npv, + p.data_collection AS data_collection, + p.community_representation_npv AS community_representation_npv, + p.community_representation AS community_representation, + p.blue_carbon_project_planning_npv AS blue_carbon_project_planning_npv, + p.blue_carbon_project_planning AS blue_carbon_project_planning, + p.establishing_carbon_rights_npv AS establishing_carbon_rights_npv, + p.establishing_carbon_rights AS establishing_carbon_rights, + p.validation_npv AS validation_npv, + p.validation AS validation, + p.implementation_labor_npv AS implementation_labor_npv, + p.implementation_labor AS implementation_labor, + p.monitoring_npv AS monitoring_npv, + p.monitoring AS monitoring, + p.maintenance_npv AS maintenance_npv, + p.maintenance AS maintenance, + p.monitoring_maintenance_mpv AS monitoring_maintenance_mpv, + p.monitoring_maintenance AS monitoring_maintenance, + p.community_benefit_npv AS community_benefit_npv, + p.community_benefit AS community_benefit, + p.carbon_standard_fees_npv AS carbon_standard_fees_npv, + p.carbon_standard_fees AS carbon_standard_fees, + p.baseline_reassessment_npv AS baseline_reassessment_npv, + p.baseline_reassessment AS baseline_reassessment, + p.mrv_npv AS mrv_npv, + p.mrv AS mrv, + p.long_term_project_operating_npv AS long_term_project_operating_npv, + p.long_term_project_operating AS long_term_project_operating, + p.initial_price_assumption AS initial_price_assumption, + p.leftover_after_opex_npv AS leftover_after_opex_npv, + p.leftover_after_opex AS leftover_after_opex, + p.total_revenue_npv AS total_revenue_npv, + p.total_revenue AS total_revenue, + p.credits_issued AS credits_issued, + p.score_card_rating AS score_card_rating FROM projects p LEFT JOIN @@ -36,6 +85,9 @@ ON ps."ecosystem"::VARCHAR = p."ecosystem"::VARCHAR`, }) export class ProjectScorecardView { + @ViewColumn({ name: "id" }) + id: string; + @ViewColumn({ name: "country_code" }) countryCode: string; @@ -86,4 +138,208 @@ export class ProjectScorecardView { @ViewColumn({ name: "total_cost_npv", transformer: decimalTransformer }) totalCostNPV: number; + + @ViewColumn({ name: "project_size", transformer: decimalTransformer }) + projectSize: number; + + @ViewColumn({ name: "project_size_filter" }) + projectSizeFilter: string; + + @ViewColumn({ name: "price_type" }) + priceType: string; + + @ViewColumn({ name: "capex_npv", transformer: decimalTransformer }) + capexNPV: number; + + @ViewColumn({ name: "capex", transformer: decimalTransformer }) + capex: number; + + @ViewColumn({ name: "opex_npv", transformer: decimalTransformer }) + opexNPV: number; + + @ViewColumn({ name: "opex", transformer: decimalTransformer }) + opex: number; + + @ViewColumn({ name: "cost_per_tco2e_npv", transformer: decimalTransformer }) + costPerTCO2eNPV: number; + + @ViewColumn({ name: "cost_per_tco2e", transformer: decimalTransformer }) + costPerTCO2e: number; + + @ViewColumn({ + name: "feasibility_analysis_npv", + transformer: decimalTransformer, + }) + feasibilityAnalysisNPV: number; + + @ViewColumn({ name: "feasibility_analysis", transformer: decimalTransformer }) + feasibilityAnalysis: number; + + @ViewColumn({ + name: "conservation_planning_npv", + transformer: decimalTransformer, + }) + conservationPlanningNPV: number; + + @ViewColumn({ + name: "conservation_planning", + transformer: decimalTransformer, + }) + conservationPlanning: number; + + @ViewColumn({ name: "data_collection_npv", transformer: decimalTransformer }) + dataCollectionNPV: number; + + @ViewColumn({ name: "data_collection", transformer: decimalTransformer }) + dataCollection: number; + + @ViewColumn({ + name: "community_representation_npv", + transformer: decimalTransformer, + }) + communityRepresentationNPV: number; + + @ViewColumn({ + name: "community_representation", + transformer: decimalTransformer, + }) + communityRepresentation: number; + + @ViewColumn({ + name: "blue_carbon_project_planning_npv", + transformer: decimalTransformer, + }) + blueCarbonProjectPlanningNPV: number; + + @ViewColumn({ + name: "blue_carbon_project_planning", + transformer: decimalTransformer, + }) + blueCarbonProjectPlanning: number; + + @ViewColumn({ + name: "establishing_carbon_rights_npv", + transformer: decimalTransformer, + }) + establishingCarbonRightsNPV: number; + + @ViewColumn({ + name: "establishing_carbon_rights", + transformer: decimalTransformer, + }) + establishingCarbonRights: number; + + @ViewColumn({ name: "validation_npv", transformer: decimalTransformer }) + validationNPV: number; + + @ViewColumn({ name: "validation", transformer: decimalTransformer }) + validation: number; + + @ViewColumn({ + name: "implementation_labor_npv", + transformer: decimalTransformer, + }) + implementationLaborNPV: number; + + @ViewColumn({ name: "implementation_labor", transformer: decimalTransformer }) + implementationLabor: number; + + @ViewColumn({ name: "monitoring_npv", transformer: decimalTransformer }) + monitoringNPV: number; + + @ViewColumn({ name: "monitoring", transformer: decimalTransformer }) + monitoring: number; + + @ViewColumn({ name: "maintenance_npv", transformer: decimalTransformer }) + maintenanceNPV: number; + + @ViewColumn({ name: "maintenance", transformer: decimalTransformer }) + maintenance: number; + + @ViewColumn({ + name: "monitoring_maintenance_mpv", + transformer: decimalTransformer, + }) + monitoringMaintenanceMPV: number; + + @ViewColumn({ + name: "monitoring_maintenance", + transformer: decimalTransformer, + }) + monitoringMaintenance: number; + + @ViewColumn({ + name: "community_benefit_npv", + transformer: decimalTransformer, + }) + communityBenefitNPV: number; + + @ViewColumn({ name: "community_benefit", transformer: decimalTransformer }) + communityBenefit: number; + + @ViewColumn({ + name: "carbon_standard_fees_npv", + transformer: decimalTransformer, + }) + carbonStandardFeesNPV: number; + + @ViewColumn({ name: "carbon_standard_fees", transformer: decimalTransformer }) + carbonStandardFees: number; + + @ViewColumn({ + name: "baseline_reassessment_npv", + transformer: decimalTransformer, + }) + baselineReassessmentNPV: number; + + @ViewColumn({ + name: "baseline_reassessment", + transformer: decimalTransformer, + }) + baselineReassessment: number; + + @ViewColumn({ name: "mrv_npv", transformer: decimalTransformer }) + mrvNPV: number; + + @ViewColumn({ name: "mrv", transformer: decimalTransformer }) + mrv: number; + + @ViewColumn({ + name: "long_term_project_operating_npv", + transformer: decimalTransformer, + }) + longTermProjectOperatingNPV: number; + + @ViewColumn({ + name: "long_term_project_operating", + transformer: decimalTransformer, + }) + longTermProjectOperating: number; + + @ViewColumn({ + name: "initial_price_assumption", + transformer: decimalTransformer, + }) + initialPriceAssumption: number; + + @ViewColumn({ + name: "leftover_after_opex_npv", + transformer: decimalTransformer, + }) + leftoverAfterOpexNPV: number; + + @ViewColumn({ name: "leftover_after_opex", transformer: decimalTransformer }) + leftoverAfterOpex: number; + + @ViewColumn({ name: "total_revenue_npv", transformer: decimalTransformer }) + totalRevenueNPV: number; + + @ViewColumn({ name: "total_revenue", transformer: decimalTransformer }) + totalRevenue: number; + + @ViewColumn({ name: "credits_issued", transformer: decimalTransformer }) + creditsIssued: number; + + @ViewColumn({ name: "score_card_rating" }) + scoreCardRating: string; } diff --git a/shared/entities/projects.entity.ts b/shared/entities/projects.entity.ts index 2263a25c..452af0d2 100644 --- a/shared/entities/projects.entity.ts +++ b/shared/entities/projects.entity.ts @@ -69,6 +69,14 @@ export class Project extends BaseEntity { }) projectSizeFilter: string; + @Column({ + name: "price_type", + enum: PROJECT_PRICE_TYPE, + type: "enum", + nullable: true, + }) + priceType: PROJECT_PRICE_TYPE; + @Column({ name: "abatement_potential", type: "decimal", nullable: true }) abatementPotential: number; @@ -78,27 +86,301 @@ export class Project extends BaseEntity { @Column({ name: "total_cost", type: "decimal", nullable: true }) totalCost: number; + @Column({ name: "capex_npv", type: "decimal", nullable: true, default: 0 }) + capexNPV: number; + + @Column({ name: "capex", type: "decimal", nullable: true, default: 0 }) + capex: number; + + @Column({ name: "opex_npv", type: "decimal", nullable: true, default: 0 }) + opexNPV: number; + + @Column({ name: "opex", type: "decimal", nullable: true, default: 0 }) + opex: number; + @Column({ name: "cost_per_tco2e_npv", type: "decimal", nullable: true }) costPerTCO2eNPV: number; @Column({ name: "cost_per_tco2e", type: "decimal", nullable: true }) costPerTCO2e: number; + @Column({ + name: "feasibility_analysis_npv", + type: "decimal", + nullable: true, + default: 0, + }) + feasibilityAnalysisNPV: number; + + @Column({ + name: "feasibility_analysis", + type: "decimal", + nullable: true, + default: 0, + }) + feasibilityAnalysis: number; + + @Column({ + name: "conservation_planning_npv", + type: "decimal", + nullable: true, + default: 0, + }) + conservationPlanningNPV: number; + + @Column({ + name: "conservation_planning", + type: "decimal", + nullable: true, + default: 0, + }) + conservationPlanning: number; + + @Column({ + name: "data_collection_npv", + type: "decimal", + nullable: true, + default: 0, + }) + dataCollectionNPV: number; + + @Column({ + name: "data_collection", + type: "decimal", + nullable: true, + default: 0, + }) + dataCollection: number; + + @Column({ + name: "community_representation_npv", + type: "decimal", + nullable: true, + default: 0, + }) + communityRepresentationNPV: number; + + @Column({ + name: "community_representation", + type: "decimal", + nullable: true, + default: 0, + }) + communityRepresentation: number; + + @Column({ + name: "blue_carbon_project_planning_npv", + type: "decimal", + nullable: true, + default: 0, + }) + blueCarbonProjectPlanningNPV: number; + + @Column({ + name: "blue_carbon_project_planning", + type: "decimal", + nullable: true, + default: 0, + }) + blueCarbonProjectPlanning: number; + + @Column({ + name: "establishing_carbon_rights_npv", + type: "decimal", + nullable: true, + default: 0, + }) + establishingCarbonRightsNPV: number; + + @Column({ + name: "establishing_carbon_rights", + type: "decimal", + nullable: true, + default: 0, + }) + establishingCarbonRights: number; + + @Column({ + name: "validation_npv", + type: "decimal", + nullable: true, + default: 0, + }) + validationNPV: number; + + @Column({ name: "validation", type: "decimal", nullable: true, default: 0 }) + validation: number; + + @Column({ + name: "implementation_labor_npv", + type: "decimal", + nullable: true, + default: 0, + }) + implementationLaborNPV: number; + + @Column({ + name: "implementation_labor", + type: "decimal", + nullable: true, + default: 0, + }) + implementationLabor: number; + + @Column({ + name: "monitoring_npv", + type: "decimal", + nullable: true, + default: 0, + }) + monitoringNPV: number; + + @Column({ name: "monitoring", type: "decimal", nullable: true, default: 0 }) + monitoring: number; + + @Column({ + name: "maintenance_npv", + type: "decimal", + nullable: true, + default: 0, + }) + maintenanceNPV: number; + + @Column({ name: "maintenance", type: "decimal", nullable: true, default: 0 }) + maintenance: number; + + @Column({ + name: "monitoring_maintenance_mpv", + type: "decimal", + nullable: true, + default: 0, + }) + monitoringMaintenanceNPV: number; + + @Column({ + name: "monitoring_maintenance", + type: "decimal", + nullable: true, + default: 0, + }) + monitoringMaintenance: number; + + @Column({ + name: "community_benefit_npv", + type: "decimal", + nullable: true, + default: 0, + }) + communityBenefitNPV: number; + + @Column({ + name: "community_benefit", + type: "decimal", + nullable: true, + default: 0, + }) + communityBenefit: number; + + @Column({ + name: "carbon_standard_fees_npv", + type: "decimal", + nullable: true, + default: 0, + }) + carbonStandardFeesNPV: number; + + @Column({ + name: "carbon_standard_fees", + type: "decimal", + nullable: true, + default: 0, + }) + carbonStandardFees: number; + + @Column({ + name: "baseline_reassessment_npv", + type: "decimal", + nullable: true, + default: 0, + }) + baselineReassessmentNPV: number; + + @Column({ + name: "baseline_reassessment", + type: "decimal", + nullable: true, + default: 0, + }) + baselineReassessment: number; + + @Column({ name: "mrv_npv", type: "decimal", nullable: true, default: 0 }) + mrvNPV: number; + + @Column({ name: "mrv", type: "decimal", nullable: true, default: 0 }) + mrv: number; + + @Column({ + name: "long_term_project_operating_npv", + type: "decimal", + nullable: true, + default: 0, + }) + longTermProjectOperatingNPV: number; + + @Column({ + name: "long_term_project_operating", + type: "decimal", + nullable: true, + default: 0, + }) + longTermProjectOperating: number; + @Column({ name: "initial_price_assumption", - type: "varchar", - length: 255, + type: "decimal", nullable: true, }) - initialPriceAssumption: string; + initialPriceAssumption: number; @Column({ - name: "price_type", - enum: PROJECT_PRICE_TYPE, - type: "enum", + name: "leftover_after_opex_npv", + type: "decimal", nullable: true, + default: 0, }) - priceType: PROJECT_PRICE_TYPE; + leftoverAfterOpexNPV: number; + + @Column({ + name: "leftover_after_opex", + type: "decimal", + nullable: true, + default: 0, + }) + leftoverAfterOpex: number; + + @Column({ + name: "total_revenue_npv", + type: "decimal", + nullable: true, + default: 0, + }) + totalRevenueNPV: number; + + @Column({ + name: "total_revenue", + type: "decimal", + nullable: true, + default: 0, + }) + totalRevenue: number; + + @Column({ + name: "credits_issued", + type: "decimal", + nullable: true, + default: 0, + }) + creditsIssued: number; @Column({ type: "enum", diff --git a/shared/lib/entity-mocks.ts b/shared/lib/entity-mocks.ts index 6eda8c00..0b77bbf1 100644 --- a/shared/lib/entity-mocks.ts +++ b/shared/lib/entity-mocks.ts @@ -55,7 +55,7 @@ export const createProject = async ( totalCost: 100, costPerTCO2eNPV: 100, costPerTCO2e: 100, - initialPriceAssumption: "$100", + initialPriceAssumption: 100, priceType: PROJECT_PRICE_TYPE.MARKET_PRICE, };