Skip to content

Commit

Permalink
create yearly brakdown columns and user relation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Nov 11, 2024
1 parent 43d37c8 commit c99b8ca
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 6 deletions.
16 changes: 15 additions & 1 deletion shared/entities/custom-project.entity.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -70,4 +81,7 @@ export class CustomProject {
(costEstimate) => costEstimate.customProject,
)
costEstimates: CustomProjectCostEstimate[];

@ManyToOne(() => User, (user) => user.customProjects)
user: User;
}
160 changes: 155 additions & 5 deletions shared/entities/users/custom-project-cost-estimates.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions shared/entities/users/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,4 +45,7 @@ export class User extends BaseEntity {

@CreateDateColumn({ name: "created_at", type: "timestamp" })
createdAt: Date;

@OneToMany(() => CustomProject, (costEstimate) => costEstimate.user)
customProjects: CustomProject[];
}

0 comments on commit c99b8ca

Please sign in to comment.