Added scenario name to plan cards

This commit is contained in:
Khalim Conn-Kowlessar 2024-07-30 20:47:06 +01:00
parent f0d197a1a8
commit 92158bb94d
6 changed files with 80 additions and 7 deletions

View file

@ -27,6 +27,7 @@ export const recommendationsRelations = relations(
references: [property.id],
}),
recommendationMaterials: many(recommendationMaterials),
planRecommendations: many(planRecommendations),
})
);

View file

@ -9,8 +9,6 @@ export default async function Recommendations({
const propertyMeta = await getPropertyMeta(params.propertyId);
const recommendations = await getRecommendations(params.planId);
console.log(recommendations);
return (
<div className="leading-loose tracking-wider">
<div className="flex py-8 text-lg">Recommendations</div>

View file

@ -9,6 +9,7 @@ function PlanCard({
createdAt,
totalEstimatedCost,
totalSapPoints,
planName,
planId,
isDefault,
}: {
@ -16,6 +17,7 @@ function PlanCard({
createdAt: Date;
totalEstimatedCost: number;
totalSapPoints: number;
planName: string | null;
planId: string;
isDefault: boolean;
}) {
@ -29,7 +31,13 @@ function PlanCard({
/>
</div>
<div className="flex-grow pl-4 flex flex-col justify-between">
<CardHeader className="flex justify-end items-center"></CardHeader>
<CardHeader className="flex justify-end items-start">
{planName && (
<div className="text-lg font-bold mb-2 text-gray-900">
{planName}
</div>
)}
</CardHeader>
<CardContent>
<div className="flex justify-between mb-2">
<span>Total cost:</span>
@ -103,6 +111,7 @@ export default async function RecommendationPlans({
createdAt={plan.createdAt}
totalEstimatedCost={totalEstimatedCost}
totalSapPoints={totalSapPoints}
planName={plan.name}
planId={String(plan.id)}
isDefault={plan.isDefault}
/>

View file

@ -153,6 +153,7 @@ export const columns: ColumnDef<PropertyWithRelations>[] = [
const recommendations = row.original.recommendations;
const currentSapPoints = row.original.currentSapPoints;
const expectedapPoints = recommendations.reduce(
(acc: number, rec: PropertyToRecommendation) => {
if (rec.sapPoints === null || rec.sapPoints === undefined) {

View file

@ -4,7 +4,7 @@ import {
UnnestedRecommendation,
PortfolioPlanRecommendation,
} from "./../../db/schema/recommendations";
import { and, eq, inArray } from "drizzle-orm";
import { and, ConsoleLogWriter, eq, inArray } from "drizzle-orm";
import { db } from "@/app/db/db";
import { portfolio, portfolioUsers } from "@/app/db/schema/portfolio";
import { property } from "@/app/db/schema/property";
@ -264,6 +264,57 @@ export async function getProperties(
limit: number = 1000,
offset: number = 0
): Promise<PropertyWithRelations[]> {
// When pulling in the associated recommendations, we need to pull in the associated plan and take recommendations that are associated to the
// default plans
// const data: PropertyWithRelations[] = await db.query.property.findMany({
// limit: limit,
// offset: offset,
// columns: {
// id: true,
// portfolioId: true,
// address: true,
// postcode: true,
// status: true,
// creationStatus: true,
// currentEpcRating: true,
// currentSapPoints: true,
// },
// where: eq(property.portfolioId, BigInt(portfolioId)),
// with: {
// target: {
// columns: {
// epc: true,
// },
// },
// recommendations: {
// columns: {
// id: true,
// estimatedCost: true,
// sapPoints: true,
// },
// where: eq(recommendation.default, true),
// with: {
// planRecommendations: {
// columns: {
// planId: true,
// },
// with: {
// plan: {
// columns: {
// id: true,
// isDefault: true,
// },
// where: eq(plan.isDefault, true),
// },
// },
// },
// },
// },
// },
// });
// We need to perform the query like this because the nested query is not supported in the ORM right now
const data: PropertyWithRelations[] = await db.query.property.findMany({
limit: limit,
offset: offset,
@ -286,10 +337,23 @@ export async function getProperties(
},
recommendations: {
columns: {
id: true,
estimatedCost: true,
sapPoints: true,
},
where: eq(recommendation.default, true),
where: and(
eq(recommendation.default, true),
inArray(
recommendation.id,
db
.select({
recommendationId: planRecommendations.recommendationId,
})
.from(planRecommendations)
.innerJoin(plan, eq(plan.id, planRecommendations.planId))
.where(eq(plan.isDefault, true))
)
),
},
},
});

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,