From 25a09acb32e4d31e5a14ce5f348022efc27b6378 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 31 Jul 2023 14:47:14 +0100 Subject: [PATCH] Added property tables schemas --- src/app/db/schema/property.ts | 113 ++++++++++++++++++ .../building-passport/[propertyId]/page.tsx | 2 +- 2 files changed, 114 insertions(+), 1 deletion(-) diff --git a/src/app/db/schema/property.ts b/src/app/db/schema/property.ts index 0e4afc57..5a0d025f 100644 --- a/src/app/db/schema/property.ts +++ b/src/app/db/schema/property.ts @@ -1,3 +1,16 @@ +import { + serial, + text, + timestamp, + pgTable, + real, + pgEnum, + integer, + boolean, +} from "drizzle-orm/pg-core"; +import { portfolio } from "./portfolio"; +import { InferModel } from "drizzle-orm"; + // This is a placeholder for the property schema export interface PropertyMeta { id: number; @@ -46,3 +59,103 @@ export interface ConditionReportData { heatingDemand: GeneralFeature[]; yearBuilt: string; } + +export const PropertyStatus: [string, ...string[]] = [ + "LOADING", + "READY", + "ERROR", +]; + +export const Epc: [string, ...string[]] = ["A", "B", "C", "D", "E", "F", "G"]; + +export const propertyStatusEnum = pgEnum("property_status", PropertyStatus); +export const epcEnum = pgEnum("epc", Epc); + +export const property = pgTable("property", { + id: serial("id").primaryKey(), + portfolioId: integer("portfolio_id") + .notNull() + .references(() => portfolio.id), + status: propertyStatusEnum("status").notNull(), + uprn: integer("uprn"), + address: text("address"), + postcode: text("postcode"), + hasPreConditionReport: boolean("has_pre_condition_report"), + hasRecommendations: boolean("has_recommendations"), + createdAt: timestamp("created_at").notNull(), + updatedAt: timestamp("updated_at").notNull(), + propertyType: text("property_type"), + builtForm: text("built_form"), + localAuthority: text("local_authority"), + constituency: text("constituency"), + numberOfRooms: integer("number_of_rooms"), + yearBuilt: text("year_built"), + tenure: text("tenure"), + currentEpcRating: epcEnum("current_epc_rating"), + currentSapPoints: real("current_sap_points"), +}); + +export const FeatureRating: [string, ...string[]] = [ + "Very good", + "Good", + "Poor", + "Very poor", + "N/A", +]; + +export const featureRatingEnum = pgEnum("feature_rating", FeatureRating); + +export const propertyDetailsEpc = pgTable("property_details_epc", { + id: serial("id").primaryKey(), + propertyId: integer("property_id") + .notNull() + .references(() => property.id), + portfolioId: integer("portfolio_id") + .notNull() + .references(() => portfolio.id), + fullAddress: text("full_address"), + totalFloorArea: real("total_floor_area"), + walls: text("walls"), + wallsRating: featureRatingEnum("walls_rating"), + roof: text("roof"), + roofRating: featureRatingEnum("roof_rating"), + floor: text("floor"), + floorRating: featureRatingEnum("floor_rating"), + windows: text("windows"), + windowsRating: featureRatingEnum("windows_rating"), + heating: text("heating"), + heatingRating: featureRatingEnum("heating_rating"), + heatingContols: text("heating_contols"), + heatingContolsRating: featureRatingEnum("heating_contols_rating"), + hotWater: text("hot_water"), + hotWaterRating: featureRatingEnum("hot_water_rating"), + lighting: text("lighting"), + lightingRating: featureRatingEnum("lighting_rating"), + ventilation: text("ventilation"), + solarPv: text("solar_pv"), + solarHotWater: text("solar_hot_water"), + windTurbine: text("wind_turbine"), + floorHeight: real("floor_height"), + numberHeatedRooms: integer("number_heated_rooms"), + heatLossCorridor: boolean("heat_loss_corridor"), + unheatedCorridorLength: real("unheated_corridor_length"), + numberOpenFireplaces: integer("number_of_open_fireplaces"), + numberExtensions: integer("number_of_extensions"), + numberStoreys: integer("number_of_storeys"), + mainsGas: boolean("mains_gas"), + energyTariff: text("energy_tariff"), + primaryEnergyConsumption: real("primary_energy_consumption"), + co2Emissions: real("co2_emissions"), +}); + +export const propertyDetailsMeter = pgTable("property_details_meter", { + id: serial("id").primaryKey(), + uprn: integer("uprn").notNull(), + energySupplier: text("energy_supplier"), + gasSupplier: text("gas_supplier"), + meterReadingTotal: real("meter_reading_total"), + meterReadingElectricity: real("meter_reading_electricity"), + meterReadingGas: real("meter_reading_gas"), +}); + +// TODO: We'll need a property details buildings materials for verisk data? diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/page.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/page.tsx index ec7cad13..5e015dea 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/page.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/page.tsx @@ -10,7 +10,7 @@ import { UserGroupIcon, } from "@heroicons/react/24/solid"; -export default function BuildingPassportHome() { +export default async function BuildingPassportHome() { const propertyMeta: PropertyMeta = { id: 1, address: "123 Fake Street",