mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
added retrival of spatial data from database to app
This commit is contained in:
parent
35d6a5641b
commit
8e0720c3f0
5 changed files with 58 additions and 13 deletions
|
|
@ -13,6 +13,7 @@ export async function GET(
|
|||
const propertyMeta = await db.query.property.findFirst({
|
||||
columns: {
|
||||
id: true,
|
||||
uprn: true,
|
||||
address: true,
|
||||
postcode: true,
|
||||
hasPreConditionReport: true,
|
||||
|
|
|
|||
|
|
@ -379,6 +379,13 @@
|
|||
"when": 1701217628773,
|
||||
"tag": "0053_reflective_virginia_dare",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 54,
|
||||
"version": "5",
|
||||
"when": 1701440165529,
|
||||
"tag": "0054_sharp_mojo",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ import { InferModel } from "drizzle-orm";
|
|||
// This is a placeholder for the property schema
|
||||
export interface PropertyMeta {
|
||||
id: number;
|
||||
uprn: number;
|
||||
address: string;
|
||||
postcode: string;
|
||||
hasPreConditionReport: boolean;
|
||||
|
|
@ -165,6 +166,18 @@ export const propertyDetailsEpc = pgTable("property_details_epc", {
|
|||
adjustedEnergyConsumption: real("adjusted_energy_consumption"),
|
||||
});
|
||||
|
||||
export const propertyDetailsSpatial = pgTable("property_details_spatial", {
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
uprn: bigint("uprn", { mode: "bigint" }),
|
||||
xCoordinate: real("x_coordinate"),
|
||||
yCoordinate: real("y_coordinate"),
|
||||
latitude: real("latitude"),
|
||||
longitude: real("longitude"),
|
||||
conservationStatus: boolean("conservation_status"),
|
||||
isListedBuilding: boolean("is_listed_building"),
|
||||
isHeritageBuilding: boolean("is_heritage_building"),
|
||||
});
|
||||
|
||||
export const propertyDetailsMeter = pgTable("property_details_meter", {
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
uprn: bigint("uprn", { mode: "bigint" }),
|
||||
|
|
@ -188,13 +201,16 @@ export const propertyTargets = pgTable("property_targets", {
|
|||
heatDemand: text("heat_demand"),
|
||||
});
|
||||
|
||||
// TODO: We'll need a property details buildings materials for verisk data?
|
||||
|
||||
export type Property = InferModel<typeof property, "select">;
|
||||
export type PropertyDetailsEpc = InferModel<
|
||||
typeof propertyDetailsEpc,
|
||||
"select"
|
||||
>;
|
||||
export type PropertyDetailsSpatial = InferModel<
|
||||
typeof propertyDetailsSpatial,
|
||||
"select"
|
||||
>;
|
||||
|
||||
// This type is used for the getProperties function in src/app/portfolio/[slug]/utils.ts
|
||||
export interface PropertyToRecommendation {
|
||||
estimatedCost?: number | null;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import FeatureTable from "@/app/components/building-passport/FeatureTable";
|
|||
import {
|
||||
ConditionReportData,
|
||||
PropertyDetailsEpc,
|
||||
PropertyDetailsSpatial,
|
||||
PropertyMeta,
|
||||
} from "@/app/db/schema/property";
|
||||
import { formatDateTime } from "@/app/utils";
|
||||
|
|
@ -16,6 +17,7 @@ import {
|
|||
formatRetrofitFeatures,
|
||||
getConditionReport,
|
||||
getPropertyMeta,
|
||||
getSpatialData,
|
||||
} from "../utils";
|
||||
|
||||
function AddressCard({ address }: { address: string | null }) {
|
||||
|
|
@ -30,10 +32,7 @@ function AddressCard({ address }: { address: string | null }) {
|
|||
interface PropertyDetailsCardProps {
|
||||
conditionReportData: PropertyDetailsEpc;
|
||||
propertyMeta: PropertyMeta;
|
||||
propertyDetailsSpatial: {
|
||||
inConservationArea: string;
|
||||
isListedorHeritage: string;
|
||||
};
|
||||
propertyDetailsSpatial: PropertyDetailsSpatial;
|
||||
}
|
||||
|
||||
const rowTitleStyle = "text-brandblue align-top pb-3";
|
||||
|
|
@ -48,6 +47,9 @@ function PropertyDetailsCard({
|
|||
.filter(Boolean)
|
||||
.join(" ");
|
||||
|
||||
console.log("KJHEKJLWFWEL");
|
||||
console.log(propertyDetailsSpatial);
|
||||
|
||||
return (
|
||||
<div className="w-full flex flex-col items-center p-4 shadow rounded-md justify-start bg-gray-100">
|
||||
<div className="grid grid-cols-2 gap-8 text-m w-full h-full text-sm">
|
||||
|
|
@ -72,13 +74,19 @@ function PropertyDetailsCard({
|
|||
<tr>
|
||||
<td className={rowTitleStyle}>In conservation area:</td>
|
||||
<td className={rowValueStyle}>
|
||||
{propertyDetailsSpatial.inConservationArea}
|
||||
{propertyDetailsSpatial.conservationStatus ? "Yes" : "No"}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className={rowTitleStyle}>Is listed or heritage:</td>
|
||||
<td className={rowTitleStyle}>Is listed:</td>
|
||||
<td className={rowValueStyle}>
|
||||
{propertyDetailsSpatial.isListedorHeritage}
|
||||
{propertyDetailsSpatial.isListedBuilding ? "Yes" : "No"}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className={rowTitleStyle}>Is heritage:</td>
|
||||
<td className={rowValueStyle}>
|
||||
{propertyDetailsSpatial.isHeritageBuilding ? "Yes" : "No"}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
@ -118,10 +126,7 @@ export default async function PreAssessmentReport({
|
|||
}) {
|
||||
const propertyMeta = await getPropertyMeta(params.propertyId);
|
||||
const conditionReportData = await getConditionReport(params.propertyId);
|
||||
const propertyDetailsSpatial = {
|
||||
inConservationArea: "No",
|
||||
isListedorHeritage: "No",
|
||||
};
|
||||
const propertyDetailsSpatial = await getSpatialData(propertyMeta.uprn);
|
||||
const generalFeatures = formatGeneralFeatures(
|
||||
conditionReportData,
|
||||
propertyMeta.propertyType
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ import {
|
|||
Feature,
|
||||
GeneralFeature,
|
||||
PropertyDetailsEpc,
|
||||
PropertyDetailsSpatial,
|
||||
PropertyMeta,
|
||||
propertyDetailsEpc,
|
||||
propertyDetailsSpatial,
|
||||
} from "@/app/db/schema/property";
|
||||
import { plan, Plan } from "@/app/db/schema/recommendations";
|
||||
import { getRating } from "@/app/utils";
|
||||
|
|
@ -108,6 +110,20 @@ export async function getConditionReport(
|
|||
return data;
|
||||
}
|
||||
|
||||
export async function getSpatialData(
|
||||
uprn: number
|
||||
): Promise<PropertyDetailsSpatial> {
|
||||
const data = await db.query.propertyDetailsSpatial.findFirst({
|
||||
where: eq(propertyDetailsSpatial.uprn, BigInt(uprn)),
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export function formatGeneralFeatures(
|
||||
conditionReportData: PropertyDetailsEpc,
|
||||
propertyType: string
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue