mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
move types to dedicated files
This commit is contained in:
parent
5e252b1df1
commit
fb7adc3998
7 changed files with 67 additions and 28 deletions
|
|
@ -9,29 +9,10 @@ import {
|
|||
TableHead,
|
||||
TableCell,
|
||||
} from "@/app/shadcn_components/ui/table";
|
||||
import { Element } from "../types/element";
|
||||
import { ASPECT_TYPE_LABELS, ELEMENT_TYPE_LABELS } from "../constants";
|
||||
|
||||
|
||||
export type AspectCondition = {
|
||||
id: string;
|
||||
elementId: string;
|
||||
aspectType: string;
|
||||
aspectInstance: number;
|
||||
value: string | null;
|
||||
quantity: number | null;
|
||||
installDate: string | null;
|
||||
renewalYear: number | null;
|
||||
comments: string | null;
|
||||
};
|
||||
|
||||
export type Element = {
|
||||
id: string;
|
||||
surveyId: string;
|
||||
elementType: string;
|
||||
elementInstance: number;
|
||||
aspects: AspectCondition[];
|
||||
};
|
||||
|
||||
export type ElementGroup = {
|
||||
elementType: string;
|
||||
elementInstance: number;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import { getPropertyMeta } from "../utils";
|
||||
import { db } from "@/app/db/db";
|
||||
import ElementTable, { ElementGroup, Element } from "./components/ElementTable";
|
||||
import { Element } from "./types/element";
|
||||
import { Survey } from "./types/survey";
|
||||
import { Renewal } from "./viewModels/renewal";
|
||||
import ElementTable, { ElementGroup } from "./components/ElementTable";
|
||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/app/shadcn_components/ui/tabs";
|
||||
|
||||
type ConditionPageProps = {
|
||||
|
|
@ -10,14 +13,11 @@ type ConditionPageProps = {
|
|||
};
|
||||
};
|
||||
|
||||
type Survey = {
|
||||
id: string;
|
||||
uprn: string;
|
||||
date: string;
|
||||
source: string;
|
||||
elements: Element[];
|
||||
type RenewalTimelineProps = {
|
||||
renewals: Renewal[];
|
||||
};
|
||||
|
||||
|
||||
function serializeBigInt(obj: unknown): Survey[] {
|
||||
return JSON.parse(
|
||||
JSON.stringify(obj, (_key, value) => (typeof value === "bigint" ? value.toString() : value))
|
||||
|
|
@ -39,6 +39,23 @@ async function getConditionsByUprn(uprn: number): Promise<Survey[]> {
|
|||
return serializeBigInt(surveys);
|
||||
}
|
||||
|
||||
function buildRenewals(elements: Element[]): Renewal[] {
|
||||
return elements.flatMap(element =>
|
||||
element.aspects
|
||||
.filter(aspect => aspect.renewalYear !== null)
|
||||
.map(aspect => ({
|
||||
id: `${element.id}-${aspect.id}`,
|
||||
elementId: element.id,
|
||||
aspectId: aspect.id,
|
||||
renewalYear: aspect.renewalYear!,
|
||||
elementType: element.elementType,
|
||||
aspectType: aspect.aspectType,
|
||||
label: `${element.elementType} ${element.elementInstance} – ${aspect.aspectType}`,
|
||||
comments: aspect.comments,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
export default async function Condition({ params }: ConditionPageProps) {
|
||||
const { propertyId } = params;
|
||||
const propertyMeta = await getPropertyMeta(propertyId);
|
||||
|
|
@ -49,7 +66,7 @@ export default async function Condition({ params }: ConditionPageProps) {
|
|||
return <div>No survey data found for this property.</div>;
|
||||
}
|
||||
|
||||
const survey = surveys[0]; // assuming one survey per property
|
||||
const survey = surveys[0]; // TODO: handle more than one survey per property
|
||||
|
||||
const groupedElements: ElementGroup[] = Object.values(
|
||||
survey.elements.reduce((acc: Record<string, ElementGroup>, el: Element) => {
|
||||
|
|
@ -64,6 +81,8 @@ export default async function Condition({ params }: ConditionPageProps) {
|
|||
}, {})
|
||||
);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div style={{ padding: "1rem" }}>
|
||||
<Tabs defaultValue="surveys" className="w-full">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
export type AspectCondition = {
|
||||
id: string;
|
||||
elementId: string;
|
||||
aspectType: string;
|
||||
aspectInstance: number;
|
||||
value: string | null;
|
||||
quantity: number | null;
|
||||
installDate: string | null;
|
||||
renewalYear: number | null;
|
||||
comments: string | null;
|
||||
};
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import { AspectCondition } from "./aspectCondition";
|
||||
|
||||
export type Element = {
|
||||
id: string;
|
||||
surveyId: string;
|
||||
elementType: string;
|
||||
elementInstance: number;
|
||||
aspects: AspectCondition[];
|
||||
};
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import { Element } from "./element";
|
||||
|
||||
export type Survey = {
|
||||
id: string;
|
||||
uprn: string;
|
||||
date: string;
|
||||
source: string;
|
||||
elements: Element[];
|
||||
};
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
export type Renewal = {
|
||||
id: string; // unique for timeline
|
||||
elementId: string;
|
||||
aspectId: string;
|
||||
label: string; // what user sees
|
||||
renewalYear: number;
|
||||
elementType: string;
|
||||
aspectType: string;
|
||||
comments?: string | null;
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue