mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
changing api to pass additional keys to describe the file format
This commit is contained in:
parent
5131c3184e
commit
f9d72e7ad5
3 changed files with 9 additions and 1 deletions
|
|
@ -20,6 +20,8 @@ const PresignedUrlBodySchema = z.object({
|
|||
// optional scenario_id to link the plan to an existing scenario
|
||||
scenario_id: z.string().optional().nullable(),
|
||||
file_type: z.enum(["csv", "xlsx"]).optional(), // Specify the file type
|
||||
file_format: z.enum(["domna_asset_list"]).optional().nullable(), // Specify the file format
|
||||
sheet_name: z.string().optional().nullable(), // Specify the sheet name if applicable
|
||||
});
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
|
|
@ -27,7 +29,6 @@ export async function POST(request: NextRequest) {
|
|||
console.log("Triggering plan build");
|
||||
|
||||
const body = await request.json();
|
||||
console.log("Unvalidated body: ", body);
|
||||
let validatedBody;
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -75,5 +75,6 @@ export async function POST(req: NextRequest) {
|
|||
isStandardised,
|
||||
file_type: fileType,
|
||||
...(fileType === "xlsx" && isStandardised ? { sheetNames } : {}),
|
||||
fileFormat: isStandardised ? "domna_asset_list" : null,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ export function useUploadCsvPlan({
|
|||
measures,
|
||||
onSuccessRedirect,
|
||||
fileType,
|
||||
fileFormat,
|
||||
}: {
|
||||
file: File;
|
||||
portfolioId: string;
|
||||
|
|
@ -121,6 +122,7 @@ export function useUploadCsvPlan({
|
|||
measures: (typeof measuresList)[number][];
|
||||
onSuccessRedirect: (path: string) => void;
|
||||
fileType: "csv" | "xlsx";
|
||||
fileFormat: "domna_asset_list" | null;
|
||||
}) {
|
||||
const session = useSession();
|
||||
const userId = String(session.data?.user.dbId);
|
||||
|
|
@ -161,6 +163,7 @@ export function useUploadCsvPlan({
|
|||
sheet_name: selectedSheet,
|
||||
ashp_cop: ashpCop,
|
||||
file_type: fileType, // Pass the file type for backend processing
|
||||
file_format: fileFormat,
|
||||
};
|
||||
|
||||
const triggerRes = await fetch("/api/plan/trigger", {
|
||||
|
|
@ -219,6 +222,7 @@ export default function UploadCsvModal({
|
|||
const [selectedScenario, setSelectedScenario] = useState<string | null>(null);
|
||||
const [showMeasures, setShowMeasures] = useState(false);
|
||||
const [fileType, setFileType] = useState<"csv" | "xlsx">("csv");
|
||||
const [fileFormat, setFileFormat] = useState<"domna_asset_list" | null>(null);
|
||||
|
||||
const scenarioOptions = useMemo(
|
||||
() =>
|
||||
|
|
@ -251,6 +255,7 @@ export default function UploadCsvModal({
|
|||
setSelectedSheet("");
|
||||
}
|
||||
setFileType(data.file_type); // capture file type
|
||||
setFileFormat(data.fileFormat || null);
|
||||
},
|
||||
onError: () => {
|
||||
setSheetNames([]);
|
||||
|
|
@ -292,6 +297,7 @@ export default function UploadCsvModal({
|
|||
scenarioName: form.watch("scenario"),
|
||||
measures: form.watch("measures"),
|
||||
fileType: fileType,
|
||||
fileFormat: fileFormat,
|
||||
portfolioId,
|
||||
selectedSheet,
|
||||
onSuccessRedirect: (path) => router.push(path),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue