mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
refreshed upload page
This commit is contained in:
parent
2c23670158
commit
59d6bf2151
1 changed files with 26 additions and 67 deletions
|
|
@ -1,84 +1,43 @@
|
|||
import { getPropertyMeta } from "@/app/portfolio/[slug]/building-passport/[propertyId]/utils";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { DocumentsTable } from "./DocumentsTable";
|
||||
import { GenericDocumentsTable } from "./GenericDocumentsTable";
|
||||
import { surveyDB } from "@/app/db/surveyDB/connection";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "@/app/db/db";
|
||||
import { filesFromSurveyor } from "@/app/db/schema/files_from_surveyor";
|
||||
import type { FilesFromSurveyor } from "@/app/db/schema/files_from_surveyor";
|
||||
import { uploadedFiles } from "@/app/db/surveyDB/schema/surveyDB";
|
||||
import { type getUploadedFiles } from "@/app/db/surveyDB/schema/surveyDB";
|
||||
|
||||
async function getDocuments(uprn: number): Promise<getUploadedFiles> {
|
||||
const result = surveyDB.query.uploadedFiles.findMany({
|
||||
where: eq(uploadedFiles.uprn, String(uprn)),
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async function getSurveyorDocuments(
|
||||
portfolioId: string,
|
||||
propertyId: string
|
||||
): Promise<FilesFromSurveyor[]> {
|
||||
const files = await db
|
||||
.select()
|
||||
.from(filesFromSurveyor)
|
||||
.where(
|
||||
and(
|
||||
eq(filesFromSurveyor.portfolioId, BigInt(portfolioId)),
|
||||
eq(filesFromSurveyor.propertyId, BigInt(propertyId))
|
||||
)
|
||||
);
|
||||
|
||||
return files;
|
||||
}
|
||||
import { uploadedFiles } from "@/app/db/schema/uploaded_files";
|
||||
import { DocumentsClient, type RawFileType } from "./DocumentsClient";
|
||||
|
||||
export default async function DocumentsPage(props: {
|
||||
params: Promise<{ slug: string; propertyId: string }>;
|
||||
}) {
|
||||
const params = await props.params;
|
||||
// Get the property UPRN
|
||||
const propertyId = params.propertyId;
|
||||
const { propertyId } = params;
|
||||
|
||||
if (!propertyId || propertyId === "0") {
|
||||
throw Error("Invalid propertyId");
|
||||
}
|
||||
|
||||
const propertyMeta = await getPropertyMeta(propertyId);
|
||||
const uploadedFiles = await getDocuments(propertyMeta.uprn);
|
||||
|
||||
// We also fetch surveyor documents, which is a temp solution
|
||||
const surveyorDocuments = await getSurveyorDocuments(params.slug, propertyId);
|
||||
const rows = await db
|
||||
.select({
|
||||
id: uploadedFiles.id,
|
||||
s3FileKey: uploadedFiles.s3FileKey,
|
||||
s3FileBucket: uploadedFiles.s3FileBucket,
|
||||
s3UploadTimestamp: uploadedFiles.s3UploadTimestamp,
|
||||
fileType: uploadedFiles.fileType,
|
||||
})
|
||||
.from(uploadedFiles)
|
||||
.where(eq(uploadedFiles.uprn, BigInt(propertyMeta.uprn)));
|
||||
|
||||
const documents = rows.map((row) => ({
|
||||
id: String(row.id),
|
||||
s3FileKey: row.s3FileKey,
|
||||
s3FileBucket: row.s3FileBucket,
|
||||
docType: (row.fileType ?? "unknown") as RawFileType,
|
||||
s3UploadTimestamp: row.s3UploadTimestamp.toISOString(),
|
||||
}));
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="mt-6">
|
||||
<div className="flex items-center justify-between py-4 px-6 bg-brandblue text-white font-semibold text-lg rounded-md">
|
||||
Core Survey Documents
|
||||
</div>
|
||||
<div className="py-4">
|
||||
<DocumentsTable
|
||||
uprn={propertyMeta.uprn.toString()}
|
||||
uploadedFilesData={uploadedFiles}
|
||||
/>
|
||||
</div>
|
||||
<div className="py-4"></div>
|
||||
|
||||
<div className="flex items-center justify-between py-4 px-6 bg-brandblue text-white font-semibold text-lg rounded-md">
|
||||
Surveyor Uploaded Documents
|
||||
</div>
|
||||
<div className="py-4">
|
||||
<GenericDocumentsTable
|
||||
uprn={propertyMeta.uprn.toString()}
|
||||
files={surveyorDocuments}
|
||||
/>
|
||||
</div>
|
||||
<div className="py-4"></div>
|
||||
|
||||
<div className="flex items-center justify-between py-4 px-6 bg-brandblue text-white font-semibold text-lg rounded-md">
|
||||
Coordination
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
<div className="mt-6 px-1">
|
||||
<DocumentsClient documents={documents} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue