From af2ba1fddfd99a150059a16777a7f56d0c716ae4 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 30 Aug 2023 11:48:21 +0100 Subject: [PATCH] fixed aggregations on plan page --- src/app/api/plan/trigger/route.ts | 4 +--- src/app/api/portfolio/plan/route.ts | 1 - .../portfolio/plan/PlanTableColumns.tsx | 2 ++ .../[propertyId]/plans/page.tsx | 19 ++++++++++++++----- .../building-passport/[propertyId]/utils.ts | 7 ++++++- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/app/api/plan/trigger/route.ts b/src/app/api/plan/trigger/route.ts index a11a7582..a0ed2647 100644 --- a/src/app/api/plan/trigger/route.ts +++ b/src/app/api/plan/trigger/route.ts @@ -11,7 +11,7 @@ const PresignedUrlBodySchema = z.object({ export async function POST(request: NextRequest) { // For the moment, this api specifically handles uploads of csvs - console.log("in trigger api"); + const body = await request.json(); let validatedBody; @@ -24,8 +24,6 @@ export async function POST(request: NextRequest) { }); } - console.log("Validated body"); - try { // We'll trigger the plan build in our fastapi backend and then the user will just have to // wait for the plan to be ready diff --git a/src/app/api/portfolio/plan/route.ts b/src/app/api/portfolio/plan/route.ts index 56becb17..72c8cf12 100644 --- a/src/app/api/portfolio/plan/route.ts +++ b/src/app/api/portfolio/plan/route.ts @@ -20,7 +20,6 @@ const createPortfolioSchema = z.object({ export async function POST(request: NextRequest) { const body = await request.json(); - console.log("Triggering plan"); return new NextResponse(JSON.stringify({ msg: "plan triggered" }), { status: 201, }); diff --git a/src/app/components/portfolio/plan/PlanTableColumns.tsx b/src/app/components/portfolio/plan/PlanTableColumns.tsx index dee5a59e..a1645384 100644 --- a/src/app/components/portfolio/plan/PlanTableColumns.tsx +++ b/src/app/components/portfolio/plan/PlanTableColumns.tsx @@ -11,6 +11,8 @@ const formattedQuantity = { const formattedMeasure = { internal_wall_insulation: "Internal Wall Insulation", external_wall_insulation: "External Wall Insulation", + suspended_floor_insulation: "Suspension Floor Insulation", + solid_floor_insulation: "Solid Floor Insulation", }; export const portfolioPlanColumns: ColumnDef[] = [ diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/page.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/page.tsx index dd5bd122..8545804e 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/page.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/page.tsx @@ -65,15 +65,24 @@ export default async function RecommendationPlans({
{plans.map((plan, index) => { + // We accumulate the cost and the sap points for only the default recommendations const totalEstimatedCost = plan.planRecommendations.reduce( - (acc, rec) => acc + rec.recommendation.estimatedCost, - 0 - ); - const totalSapPoints = plan.planRecommendations.reduce( - (acc, rec) => acc + rec.recommendation.sapPoints, + (acc, rec) => { + if (rec.recommendation.default) { + return acc + rec.recommendation.estimatedCost; + } + return acc; + }, 0 ); + const totalSapPoints = plan.planRecommendations.reduce((acc, rec) => { + if (rec.recommendation.default) { + return acc + rec.recommendation.sapPoints; + } + return acc; + }, 0); + // Placeholder while we return 999 for all sap points const expectedSapPoints = Math.min( propertyMeta.currentSapPoints + totalSapPoints, diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts b/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts index f7c82012..ba1ec03b 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts @@ -42,7 +42,11 @@ export async function getRecommendations( type PlanRelation = Plan & { planRecommendations: { - recommendation: { estimatedCost: number; sapPoints: number }; + recommendation: { + estimatedCost: number; + sapPoints: number; + default: boolean; + }; }[]; }; @@ -57,6 +61,7 @@ export async function getPlans(propertyId: string): Promise { columns: { estimatedCost: true, sapPoints: true, + default: true, }, }, },