Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgnlez committed Dec 10, 2024
1 parent aeeed89 commit 2fea9c2
Show file tree
Hide file tree
Showing 10 changed files with 434 additions and 252 deletions.
3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint:fix": "next lint --fix"
"lint:fix": "next lint --fix",
"check-types": "tsc"
},
"dependencies": {
"@hookform/resolvers": "3.9.0",
Expand Down
1 change: 1 addition & 0 deletions client/src/app/auth/api/[...nextauth]/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cookies } from "next/headers";

import { UserWithAccessToken } from "@shared/dtos/users/user.dto";
import { LogInSchema } from "@shared/schemas/auth/login.schema";
import type {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ui/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const AccordionContent = React.forwardRef<
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Content
ref={ref}
className="overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
className="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm"
{...props}
>
<div className={cn("pb-4 pt-0", className)}>{children}</div>
Expand Down
2 changes: 0 additions & 2 deletions client/src/components/ui/radio-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";

import { cn } from "@/lib/utils";

import { Label } from "@/components/ui/label";

const RadioGroup = React.forwardRef<
React.ElementRef<typeof RadioGroupPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
Expand Down
2 changes: 0 additions & 2 deletions client/src/containers/projects/form/assumptions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useMemo } from "react";

import { useFormContext } from "react-hook-form";

import { ASSUMPTIONS_NAME_TO_DTO_MAP } from "@shared/schemas/assumptions/assumptions.enums";
Expand Down
3 changes: 0 additions & 3 deletions client/src/containers/projects/new/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
import { FormProvider, useForm } from "react-hook-form";

import { zodResolver } from "@hookform/resolvers/zod";
import { ApiResponse } from "@shared/dtos/global/api-response.dto";
import { ACTIVITY } from "@shared/entities/activity.enum";
import { EMISSION_FACTORS_TIER_TYPES } from "@shared/entities/carbon-inputs/emission-factors.entity";
import {
CARBON_REVENUES_TO_COVER,
PROJECT_SPECIFIC_EMISSION,
} from "@shared/entities/custom-project.entity";
import { ECOSYSTEM } from "@shared/entities/ecosystem.enum";
import { ModelAssumptions } from "@shared/entities/model-assumptions.entity";
import { ASSUMPTIONS_NAME_TO_DTO_MAP } from "@shared/schemas/assumptions/assumptions.enums";
import {
// CombinedCustomProjectSchema,
CreateCustomProjectSchema,
LOSS_RATE_USED,
} from "@shared/schemas/custom-projects/create-custom-project.schema";
Expand Down
636 changes: 408 additions & 228 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

25 changes: 11 additions & 14 deletions shared/contracts/custom-projects.contract.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { initContract } from "@ts-rest/core";
import {
ApiPaginationResponse,
ApiResponse,
ErrorResponse,
} from "@shared/dtos/global/api-response.dto";
import { ApiPaginationResponse, ApiResponse } from "@shared/dtos/global/api-response.dto";
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 { GetDefaultCostInputsSchema } from "@shared/schemas/custom-projects/get-cost-inputs.schema";
import { OverridableCostInputs } from "@api/modules/custom-projects/dto/project-cost-inputs.dto";
import { GetAssumptionsSchema } from "@shared/schemas/assumptions/get-assumptions.schema";
import { ModelAssumptions } from "@shared/entities/model-assumptions.entity";

import { CreateCustomProjectSchema, InputCostsSchema } from "@shared/schemas/custom-projects/create-custom-project.schema";
import { z } from "zod";
import { generateEntityQuerySchema } from "@shared/schemas/query-param.schema";
import { GetActivityTypesDefaultsSchema } from "@shared/schemas/custom-projects/activity-types-defaults.schema";
import { ActivityTypesDefaults } from "@shared/dtos/custom-projects/activity-types-defaults";
import { GetActivityTypesDefaultsSchema } from "@shared/schemas/custom-projects/activity-types-defaults.schema";

export const customProjecsQuerySchema =
generateEntityQuerySchema(CustomProject);
Expand All @@ -34,7 +31,7 @@ export const customProjectContract = contract.router({
method: "GET",
path: "/custom-projects/available-countries",
responses: {
201: contract.type<ApiResponse<Pick<Country, "name" | "code">>>(),
201: contract.type<ApiResponse<Pick<Country, "name" | "code">[]>>(),
},
summary: "Get available countries to create a custom project",
},
Expand All @@ -43,7 +40,7 @@ export const customProjectContract = contract.router({
method: "GET",
path: "/custom-projects/assumptions",
responses: {
200: contract.type<ApiResponse<Partial<ModelAssumptions>>>(),
200: contract.type<ApiResponse<Partial<ModelAssumptions>[]>>(),
},
query: GetAssumptionsSchema,
summary: "Get default model assumptions",
Expand All @@ -52,7 +49,7 @@ export const customProjectContract = contract.router({
method: "GET",
path: "/custom-projects/cost-inputs",
responses: {
200: contract.type<ApiResponse<OverridableCostInputs>>(),
200: contract.type<ApiResponse<z.infer<typeof InputCostsSchema>>>(),
},
query: GetDefaultCostInputsSchema,
},
Expand All @@ -62,7 +59,7 @@ export const customProjectContract = contract.router({
responses: {
201: contract.type<ApiResponse<CustomProject>>(),
},
body: contract.type<CreateCustomProjectDto>(),
body: CreateCustomProjectSchema,
},
getCustomProjects: {
method: "GET",
Expand Down Expand Up @@ -90,4 +87,4 @@ export const customProjectContract = contract.router({
},
});

// TODO: Due to dificulties crafting a deeply nested conditional schema, I will go forward with nestjs custom validation pipe for now
// TODO: Due to dificulties crafting a deeply nested conditional schema, I will go forward with nestjs custom validation pipe for now
10 changes: 10 additions & 0 deletions shared/entities/custom-project.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ export enum CARBON_REVENUES_TO_COVER {
CAPEX_AND_OPEX = "Capex and Opex",
}

export enum PROJECT_SPECIFIC_EMISSION {
ONE_EMISSION_FACTOR = 'One emission factor',
TWO_EMISSION_FACTORS = 'Two emission factors',
}
export enum PROJECT_EMISSION_FACTORS {
TIER_1 = 'Tier 1 - Global emission factor',
TIER_2 = 'Tier 2 - Country-specific emission factor',
TIER_3 = 'Tier 3 - Project specific emission factor',
}

@Entity({ name: "custom_projects" })
export class CustomProject {
@PrimaryGeneratedColumn("uuid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const CreateCustomProjectSchema = z.object({
// parameters: ConservationCustomProjectSchema.or(RestorationCustomProjectSchema),
parameters: ConservationCustomProjectSchema,
assumptions: AssumptionsSchema.optional(),
costInputs: InputCostsSchema,
costInputs: InputCostsSchema.optional(),
})

// export const CombinedCustomProjectSchema = z.union([
Expand Down

0 comments on commit 2fea9c2

Please sign in to comment.