diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/pre-assessment-report/page.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/pre-assessment-report/page.tsx index 46e52cb..e930468 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/pre-assessment-report/page.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/pre-assessment-report/page.tsx @@ -12,6 +12,7 @@ import { } from "@/app/components/building-passport/FeatureTableColumns"; import { formatGeneralFeatures, + formatRetrofitFeatures, getConditionReport, getPropertyMeta, } from "../utils"; @@ -268,6 +269,8 @@ export default async function PreAssessmentReport({ propertyMeta.propertyType ); + const retrofitFeatures = formatRetrofitFeatures(conditionReportData); + return (
Pre Assessment Report
@@ -291,9 +294,9 @@ export default async function PreAssessmentReport({
General Features
- {/*
Retrotfit Property Features
+
Existing Property Features
-
Heating Demand
+ {/*
Heating Demand
*/} ); diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts b/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts index b1f7078..ffa4d28 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts @@ -1,10 +1,12 @@ import { db } from "@/app/db/db"; import { + Feature, GeneralFeature, PropertyDetailsEpc, PropertyMeta, propertyDetailsEpc, } from "@/app/db/schema/property"; +import { getRating } from "@/app/utils"; import { eq } from "drizzle-orm"; export async function getPropertyMeta( @@ -92,3 +94,82 @@ export function formatGeneralFeatures( return generealFeatures; } + +export function formatRetrofitFeatures( + conditionReportData: PropertyDetailsEpc +): Feature[] { + // Helper function to convert rating number to string + + const retrofitFeatures: Feature[] = [ + { + feature: "Wall", + description: conditionReportData.walls || "N/A", + rating: getRating(conditionReportData.wallsRating), + }, + { + feature: "Roof", + description: conditionReportData.roof || "N/A", + rating: getRating(conditionReportData.roofRating), + }, + { + feature: "Windows", + description: conditionReportData.windows || "N/A", + rating: getRating(conditionReportData.windowsRating), + }, + { + feature: "Heating", + description: conditionReportData.heating || "N/A", + rating: getRating(conditionReportData.heatingRating), + }, + { + feature: "Heating Control", + description: conditionReportData.heatingControls || "N/A", + rating: getRating(conditionReportData.heatingControlsRating), + }, + { + feature: "Hot Water", + description: conditionReportData.hotWater || "N/A", + rating: getRating(conditionReportData.hotWaterRating), + }, + { + feature: "Lighting", + description: conditionReportData.lighting || "N/A", + rating: getRating(conditionReportData.lightingRating), + }, + { + feature: "Floor", + description: conditionReportData.floor || "N/A", + rating: getRating(conditionReportData.floorRating), + }, + { + feature: "Ventilation", + description: conditionReportData.ventilation || "N/A", + rating: "N/A", + }, + { + feature: "Solar Photo Voltaic", + description: + conditionReportData.solarPv != null + ? "Present in the property" + : "Not present in the property", + rating: "N/A", + }, + { + feature: "Solar Hot Water", + description: conditionReportData.solarHotWater + ? "Heating is solar powered" + : "Heating is not solar powered", + rating: "N/A", + }, + { + feature: "Wind Turbines", + description: + conditionReportData.windTurbine != null + ? `${conditionReportData.windTurbine} wind turbines present` + : "No wind turbines present", + rating: "N/A", + }, + ]; + + return retrofitFeatures; +} diff --git a/src/app/utils.ts b/src/app/utils.ts index e6e85bd..4196bf1 100644 --- a/src/app/utils.ts +++ b/src/app/utils.ts @@ -1,3 +1,25 @@ +import { Rating } from "./db/schema/property"; + +export const getRating = (rating: number | null): Rating => { + if (rating == null) { + return "N/A"; + } + + if (![1, 2, 3, 4, 5].includes(rating)) { + throw new Error("Rating should be between 1 and 5."); + } + + const ratingMap: { [key in 1 | 2 | 3 | 4 | 5]: string } = { + 1: "Very poor", + 2: "Poor", + 3: "Average", + 4: "Good", + 5: "Very good", + }; + + return ratingMap[rating as 1 | 2 | 3 | 4 | 5]; // You can assert that rating is one of these values since you've already checked it +}; + export const serializeBigInt = (_: any, value: any): string | any => { // Simple utility function to convert BigInts to strings with JSON.stringify return typeof value === "bigint" ? value.toString() : value;