From c99b8ca4b682f28eed3aa1774a0e26e50d08ffe6 Mon Sep 17 00:00:00 2001 From: alexeh Date: Mon, 11 Nov 2024 04:44:43 +0100 Subject: [PATCH] create yearly brakdown columns and user relation --- shared/entities/custom-project.entity.ts | 16 +- .../custom-project-cost-estimates.entity.ts | 160 +++++++++++++++++- shared/entities/users/user.entity.ts | 6 + 3 files changed, 176 insertions(+), 6 deletions(-) diff --git a/shared/entities/custom-project.entity.ts b/shared/entities/custom-project.entity.ts index c1a1abbd..63b4d2c4 100644 --- a/shared/entities/custom-project.entity.ts +++ b/shared/entities/custom-project.entity.ts @@ -1,5 +1,13 @@ -import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm"; +import { + Column, + CreateDateColumn, + Entity, + ManyToOne, + OneToMany, + PrimaryGeneratedColumn, +} from "typeorm"; import { CustomProjectCostEstimate } from "@shared/entities/users/custom-project-cost-estimates.entity"; +import { User } from "@shared/entities/users/user.entity"; /** * @description: This entity is to save Custom Projects (that are calculated, and can be saved only by registered users. Most likely, we don't need to add these as a resource @@ -13,6 +21,9 @@ export class CustomProject { @PrimaryGeneratedColumn() id: number; + @CreateDateColumn({ name: "created_at", type: "timestamp" }) + createdAt: Date; + @Column({ name: "project_name", type: "varchar", length: 255 }) projectName: string; @@ -70,4 +81,7 @@ export class CustomProject { (costEstimate) => costEstimate.customProject, ) costEstimates: CustomProjectCostEstimate[]; + + @ManyToOne(() => User, (user) => user.customProjects) + user: User; } diff --git a/shared/entities/users/custom-project-cost-estimates.entity.ts b/shared/entities/users/custom-project-cost-estimates.entity.ts index 47ff430a..13ddb31f 100644 --- a/shared/entities/users/custom-project-cost-estimates.entity.ts +++ b/shared/entities/users/custom-project-cost-estimates.entity.ts @@ -16,14 +16,164 @@ export class CustomProjectCostEstimate extends BaseEntity { @Column({ name: "year", type: "int" }) year: number; - @Column({ name: "cost_type", type: "varchar", length: 255 }) - costType: string; + @Column({ + name: "feasibility_analysis", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + feasibilityAnalysis: number; - @Column({ name: "total_cost", type: "float" }) + @Column({ + name: "conservation_planning_and_admin", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + conservationPlanningAndAdmin: number; + + @Column({ + name: "data_collection_and_field", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + dataCollectionAndField: number; + + @Column({ + name: "community_representation", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + communityRepresentation: number; + + @Column({ + name: "blue_carbon_project_planning", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + blueCarbonProjectPlanning: number; + + @Column({ + name: "establishing_carbon_rights", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + establishingCarbonRights: number; + + @Column({ + name: "validation", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + validation: number; + + @Column({ + name: "implementation_labor", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + implementationLabor: number; + + @Column({ + name: "monitoring", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + monitoring: number; + + @Column({ + name: "maintenance", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + maintenance: number; + + @Column({ + name: "community_benefit_sharing_fund", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + communityBenefitSharingFund: number; + + @Column({ + name: "carbon_standard_fees", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + carbonStandardFees: number; + + @Column({ + name: "baseline_reassessment", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + baselineReassessment: number; + + @Column({ name: "mrv", type: "decimal", precision: 15, scale: 2, default: 0 }) + mrv: number; + + @Column({ + name: "long_term_project_operating", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + longTermProjectOperating: number; + + @Column({ + name: "capex_total", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + capexTotal: number; + + @Column({ + name: "opex_total", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) + opexTotal: number; + + @Column({ + name: "total_cost", + type: "decimal", + precision: 15, + scale: 2, + default: 0, + }) totalCost: number; - @Column({ name: "total_cost_npv", type: "float" }) - totalCostNpv: number; + @Column({ name: "npv", type: "decimal", precision: 15, scale: 2, default: 0 }) + npv: number; @ManyToOne( () => CustomProject, diff --git a/shared/entities/users/user.entity.ts b/shared/entities/users/user.entity.ts index ec4ffcac..3775a7c6 100644 --- a/shared/entities/users/user.entity.ts +++ b/shared/entities/users/user.entity.ts @@ -4,9 +4,12 @@ import { Entity, PrimaryGeneratedColumn, BaseEntity, + OneToMany, } from "typeorm"; import { Exclude } from "class-transformer"; import { ROLES } from "@shared/entities/users/roles.enum"; +import { CustomProjectCostEstimate } from "@shared/entities/users/custom-project-cost-estimates.entity"; +import { CustomProject } from "@shared/entities/custom-project.entity"; // TODO: For future reference: // https://github.com/typeorm/typeorm/issues/2897 @@ -42,4 +45,7 @@ export class User extends BaseEntity { @CreateDateColumn({ name: "created_at", type: "timestamp" }) createdAt: Date; + + @OneToMany(() => CustomProject, (costEstimate) => costEstimate.user) + customProjects: CustomProject[]; }