Added isDefault

This commit is contained in:
Khalim Conn-Kowlessar 2024-07-30 21:40:10 +01:00
parent 92158bb94d
commit 3015c3062e
9 changed files with 5617 additions and 3 deletions

View file

@ -0,0 +1 @@
ALTER TABLE "scenario" ADD COLUMN "is_default" boolean;

View file

@ -0,0 +1 @@
ALTER TABLE "scenario" ALTER COLUMN "is_default" SET NOT NULL;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -603,6 +603,20 @@
"when": 1722359570368,
"tag": "0085_nosy_gideon",
"breakpoints": true
},
{
"idx": 86,
"version": "5",
"when": 1722371857711,
"tag": "0086_happy_excalibur",
"breakpoints": true
},
{
"idx": 87,
"version": "5",
"when": 1722371993027,
"tag": "0087_nebulous_umar",
"breakpoints": true
}
]
}

View file

@ -115,6 +115,7 @@ export const scenario = pgTable("scenario", {
),
exclusions: text("exclusions"),
multiPlan: boolean("multi_plan"),
isDefault: boolean("is_default").notNull(),
// Aggregations that were previously being stored against the portfolio, that are now being stored against the scenario
cost: real("cost"),
totalWorkHours: real("total_work_hours"),

View file

@ -1,5 +1,5 @@
import { HomeIcon } from "@heroicons/react/24/outline";
import { getPortfolio, getProperties } from "../utils";
import { getPortfolio, getPortfolioPerformance, getProperties } from "../utils";
import DataTable from "@/app/portfolio/[slug]/components/propertyTable";
import { columns } from "@/app/portfolio/[slug]/components/propertyTableColumns";
import { PropertyWithRelations } from "@/app/db/schema/property";
@ -215,6 +215,9 @@ export default async function Page({
labourDays,
} = await getPortfolio(portfolioId);
const portfolioPerformance = await getPortfolioPerformance(portfolioId);
console.log(portfolioPerformance);
// Default limit to 1000 and offset to 0 for now - will handle pagination later
const properties: PropertyWithRelations[] = await getProperties(
portfolioId,

View file

@ -3,6 +3,7 @@ import {
recommendation,
UnnestedRecommendation,
PortfolioPlanRecommendation,
scenario,
} from "./../../db/schema/recommendations";
import { and, ConsoleLogWriter, eq, inArray } from "drizzle-orm";
import { db } from "@/app/db/db";
@ -11,6 +12,7 @@ import { property } from "@/app/db/schema/property";
import type { Portfolio } from "@/app/db/schema/portfolio";
import type { PropertyWithRelations } from "@/app/db/schema/property";
import { plan, planRecommendations } from "@/app/db/schema/recommendations";
import { a } from "drizzle-orm/column.d-b7dc3bdb";
export async function getPortfolio(portfolioId: string): Promise<Portfolio> {
const data = await db
@ -29,6 +31,22 @@ export async function getPortfolio(portfolioId: string): Promise<Portfolio> {
return data[0];
}
export async function getPortfolioPerformance(portfolioId: string) {
// This function will grab portfolio metrics from the database, but it will firstly check for the existence of scenarios and
// use those figures. If they don't exist, we will use the default figures from the portfolio table
const scenarios = await db
.select()
.from(scenario)
.where(eq(scenario.portfolioId, BigInt(portfolioId)));
// If we have scenarios, return them
if (scenarios.length > 0) {
return scenarios;
}
return [];
}
// Types needed for the overview page
export interface ChartData {
name: string;

View file

@ -1,8 +1,8 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"target": "es5",
// "target": "ESNext",
// "target": "es5",
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,