database from python is now linked

This commit is contained in:
Jun-te kim 2025-08-19 12:05:28 +00:00
parent 662a27bf38
commit 5b3a1afea0
5 changed files with 33 additions and 9 deletions

View file

@ -2,8 +2,7 @@
import { NextResponse } from "next/server";
import { z, ZodError } from "zod";
import { insertUploadedFile } from "../../utils/utility"; // ensure path is correct
import { ReportTypeSchema } from "../../schema/documents";
import { ReportTypeSchema, reportTypeToDbLabel } from "../../schema/documents";
export const runtime = "nodejs";
// Helper: "" or whitespace -> undefined (so optional() can drop it)

View file

@ -52,4 +52,22 @@ export const documentTypeFileTypes: Record<ReportType, ".pdf" | ".xml" | ".xml,.
// floor_plan: ".pdf",
// occupancy_assessment: ".pdf",
};
export const ReportTypeSchema = z.enum(REPORT_TYPES);
export const ReportTypeSchema = z.enum(REPORT_TYPES);
// Map UI value -> DB enum NAME
export const reportTypeToDbLabel: Record<ReportType, string> = {
osmosis_condition_pas_2035_report: "ECO_CONDITION_REPORT",
energy_performance_report_summary_information: "ENERGY_PERFORMANCE_REPORT_SUMMARY_INFORMATION",
lodgement_xml_needed_for_lodgement_to_like_trademark: "LIG_XML",
reduce_xml_needed_to_generate_full_sap_xml: "RDSAP_XML",
full_xml_needed_for_co_ordination: "FULLSAP_XML",
};
// Optional reverse map (for reading from API):
export const dbLabelToReportType: Record<string, ReportType> = {
ECO_CONDITION_REPORT: "osmosis_condition_pas_2035_report",
ENERGY_PERFORMANCE_REPORT_SUMMARY_INFORMATION: "energy_performance_report_summary_information",
LIG_XML: "lodgement_xml_needed_for_lodgement_to_like_trademark",
RDSAP_XML: "reduce_xml_needed_to_generate_full_sap_xml",
FULLSAP_XML: "full_xml_needed_for_co_ordination",
};

View file

@ -1,9 +1,15 @@
import { pgTable, uuid, text, timestamp } from "drizzle-orm/pg-core";
import { pgEnum } from "drizzle-orm/pg-core";
export const DB_REPORT_TYPES = [
"ECO_CONDITION_REPORT",
"ENERGY_PERFORMANCE_REPORT_SUMMARY_INFORMATION",
"LIG_XML",
"RDSAP_XML",
"FULLSAP_XML",
] as const;
import { REPORT_TYPES } from "./documents";
export const docTypeEnum = pgEnum("doc_type_enum", [...REPORT_TYPES]);
export const docTypeEnum = pgEnum("reporttype", DB_REPORT_TYPES);
export const uploaded_files = pgTable("uploaded_files", {
id: uuid("id").primaryKey().defaultRandom(),

View file

@ -1,7 +1,8 @@
// insertUploadedFile.ts
import { uploaded_files } from "@/app/db/surveyDB/schema/surveyDB";
import { surveyDB } from "../connection";
import type { ReportType } from "../schema/documents";
import type { ReportType, ReportTypeSchema} from "../schema/documents";
import { reportTypeToDbLabel } from "../schema/documents";
export interface UploadedFileInput {
s3JsonUri?: string; // optional
@ -18,7 +19,7 @@ export async function insertUploadedFile(data: UploadedFileInput) {
.values({
s3JsonUri: data.s3JsonUri ?? null, // Pass null if missing
s3FileUri: data.s3FileUri,
docType: data.docType,
docType: reportTypeToDbLabel[data.docType], // map UI value -> DB enum NAME
s3FileUploadTimestamp: data.s3FileUploadTimestamp,
s3JsonUploadTimestamp: data.s3JsonUploadTimestamp ?? null, // Pass null if missing
uprn: data.uprn,

View file

@ -128,7 +128,7 @@ export const UploadModal = ({ open, onClose, documentType, uprn }: UploadModalPr
console.error("DB insert failed:", err);
throw new Error("Failed to insert uploaded file record");
}
console.log("returned",res.json());
// Success — close the dialog and let parent refresh UI
onClose();
} catch (err) {