diff --git a/src/app/components/building-passport/Toolbar.tsx b/src/app/components/building-passport/Toolbar.tsx index 58866ed..0c7807a 100644 --- a/src/app/components/building-passport/Toolbar.tsx +++ b/src/app/components/building-passport/Toolbar.tsx @@ -6,6 +6,8 @@ import { HomeModernIcon, WrenchScrewdriverIcon, SunIcon, + CircleStackIcon, + BoltIcon, } from "@heroicons/react/24/outline"; import { NavigationMenu, @@ -35,7 +37,7 @@ export function Toolbar({ propertyId, portfolioId }: ToolbarProps) { href={`/portfolio/${portfolioId}/building-passport/${propertyId}/pre-assessment-report`} > - Pre-assessment Condition Report + Data ); @@ -44,18 +46,28 @@ export function Toolbar({ propertyId, portfolioId }: ToolbarProps) { className={navigationMenuTriggerStyle() + " ml-3 mr-2"} href={`/portfolio/${portfolioId}/building-passport/${propertyId}/energy-assessment`} > - + Energy Assessment ); + const documentsButton = ( + + + Documents + + ); + const solarAnalysisButton = ( - Solar Analysis + Solar ); @@ -76,13 +88,14 @@ export function Toolbar({ propertyId, portfolioId }: ToolbarProps) { href={`/portfolio/${portfolioId}/building-passport/${propertyId}`} > - Property Information + Summary {preAssessmentReportButton} {solarAnalysisButton} {recommendationsButton} + {documentsButton} {energyAssessmentsReportButton} companyInfo.id), +}); + +// --- buildings table --- +export const buildings = pgTable("buildings", { + id: uuid("id").primaryKey().defaultRandom(), + address: text("address").notNull(), + postcode: text("postcode").notNull(), + uprn: text("UPRN").notNull(), + landlordId: text("landlord_id").notNull(), + domnaId: text("domna_id").notNull(), +}); + +// --- documents table --- +export const documents = pgTable("documents", { + id: uuid("id").primaryKey().defaultRandom(), + + authorId: uuid("assessor_id") + .notNull() + .references(() => assessorInfo.id), + createdAt: timestamp("created_at", { withTimezone: true }).notNull(), + documentType: reportType("document_type").notNull(), + + buildingId: uuid("building_id") + .notNull() + .references(() => buildings.id), + targetTable: text("target_table").notNull(), + targetId: uuid("target_id").notNull(), +}); + +export type Building = InferModel; +export type Document = InferModel; diff --git a/src/app/db/documents_schema/relations.ts b/src/app/db/documents_schema/relations.ts new file mode 100644 index 0000000..99ad5cd --- /dev/null +++ b/src/app/db/documents_schema/relations.ts @@ -0,0 +1,14 @@ +import { pgTable, serial, text, integer } from "drizzle-orm/pg-core"; +import { relations } from "drizzle-orm"; +import { buildings, documents } from "@/app/db/documents_schema/documents"; + +export const buildingsRelations = relations(buildings, ({ many }) => ({ + documents: many(documents), +})); + +export const postsRelations = relations(documents, ({ one }) => ({ + building: one(buildings, { + fields: [documents.buildingId], + references: [buildings.id], + }), +})); diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/page.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/page.tsx new file mode 100644 index 0000000..b8c064b --- /dev/null +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/page.tsx @@ -0,0 +1,57 @@ +import { documentsDB } from "@/app/db/documents_db"; +import { + buildings, + Document, + Building, +} from "@/app/db/documents_schema/documents"; +import { getPropertyMeta } from "@/app/portfolio/[slug]/building-passport/[propertyId]/utils"; +import { eq } from "drizzle-orm"; + +export type BuildingWithDocuments = Building & { + documents: Document[]; +}; + +async function getDocuments( + uprn: number +): Promise { + const result = documentsDB.query.buildings.findFirst({ + where: eq(buildings.uprn, String(uprn)), + with: { + documents: true, + }, + }); + + // If we have no buildings, we return an empty object + if (!result) { + return { + id: "", + address: "", + postcode: "", + uprn: String(uprn), + landlordId: "", + domnaId: "", + documents: [], + } as BuildingWithDocuments; + } + + return result; +} + +export default async function DocumentsPage({ + params, +}: { + params: { slug: string; propertyId: string }; +}) { + // Get the property UPRN + const propertyId = params.propertyId; + if (!propertyId || propertyId === "0") { + throw Error("Invalid propertyId"); + } + + const propertyMeta = await getPropertyMeta(propertyId); + console.log("Property Meta:", propertyMeta.uprn); + const documents = await getDocuments(propertyMeta.uprn); + console.log("Documents:", documents); + + return
Document go here
; +}