Skip to content

Commit

Permalink
refactor enums to shared
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Nov 21, 2024
1 parent 47b99e6 commit 5d1c442
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
24 changes: 5 additions & 19 deletions api/src/modules/calculations/assumptions.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,11 @@ import { ModelAssumptions } from '@shared/entities/model-assumptions.entity';
import { GetOverridableAssumptionsDTO } from '@shared/dtos/custom-projects/get-overridable-assumptions-d-t.o';
import { ACTIVITY } from '@shared/entities/activity.enum';
import { ECOSYSTEM } from '@shared/entities/ecosystem.enum';

export enum ECOSYSTEM_RESTORATION_RATE_NAMES {
MANGROVE = 'Mangrove restoration rate',
SEAGRASS = 'Seagrass restoration rate',
SALT_MARSH = 'Salt marsh restoration rate',
}

export enum ACTIVITY_PROJECT_LENGTH_NAMES {
CONSERVATION = 'Conservation project length',
RESTORATION = 'Restoration project length',
}

export const COMMON_OVERRIDABLE_ASSUMPTION_NAMES = [
'Baseline reassessment frequency',
'Buffer',
'Carbon price increase',
'Discount rate',
'Verification frequency',
] as const;
import {
ACTIVITY_PROJECT_LENGTH_NAMES,
COMMON_OVERRIDABLE_ASSUMPTION_NAMES,
ECOSYSTEM_RESTORATION_RATE_NAMES,
} from '@shared/schemas/assumptions/assumptions.enums';

@Injectable()
export class AssumptionsRepository extends Repository<ModelAssumptions> {
Expand Down
6 changes: 2 additions & 4 deletions shared/contracts/custom-projects.contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { Country } from "@shared/entities/country.entity";
import { ModelAssumptions } from "@shared/entities/model-assumptions.entity";
import { CustomProject } from "@shared/entities/custom-project.entity";
import { CreateCustomProjectDto } from "@api/modules/custom-projects/dto/create-custom-project-dto";
import {
GetAssumptionsSchema,
GetDefaultCostInputsSchema,
} from "@shared/schemas/custom-projects/get-cost-inputs.schema";
import { GetDefaultCostInputsSchema } from "@shared/schemas/custom-projects/get-cost-inputs.schema";
import { CostInputs } from "@api/modules/custom-projects/dto/project-cost-inputs.dto";
import { GetAssumptionsSchema } from "@shared/schemas/assumptions/get-assumptions.schema";

const contract = initContract();
export const customProjectContract = contract.router({
Expand Down
18 changes: 18 additions & 0 deletions shared/schemas/assumptions/assumptions.enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export enum ECOSYSTEM_RESTORATION_RATE_NAMES {
MANGROVE = "Mangrove restoration rate",
SEAGRASS = "Seagrass restoration rate",
SALT_MARSH = "Salt marsh restoration rate",
}

export enum ACTIVITY_PROJECT_LENGTH_NAMES {
CONSERVATION = "Conservation project length",
RESTORATION = "Restoration project length",
}

export const COMMON_OVERRIDABLE_ASSUMPTION_NAMES = [
"Baseline reassessment frequency",
"Buffer",
"Carbon price increase",
"Discount rate",
"Verification frequency",
] as const;
8 changes: 8 additions & 0 deletions shared/schemas/assumptions/get-assumptions.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { z } from "zod";
import { ECOSYSTEM } from "@shared/entities/ecosystem.enum";
import { ACTIVITY } from "@shared/entities/activity.enum";

export const GetAssumptionsSchema = z.object({
ecosystem: z.nativeEnum(ECOSYSTEM),
activity: z.nativeEnum(ACTIVITY),
});
5 changes: 0 additions & 5 deletions shared/schemas/custom-projects/get-cost-inputs.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@ export const GetDefaultCostInputsSchema = z.object({
ecosystem: z.nativeEnum(ECOSYSTEM),
activity: z.nativeEnum(ACTIVITY),
});

export const GetAssumptionsSchema = z.object({
ecosystem: z.nativeEnum(ECOSYSTEM),
activity: z.nativeEnum(ACTIVITY),
});

0 comments on commit 5d1c442

Please sign in to comment.