mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
added api to trigger eco spreadsheet
This commit is contained in:
parent
912f55311a
commit
c6dec2b56c
1 changed files with 56 additions and 0 deletions
56
src/app/api/eco-spreadsheet/route.ts
Normal file
56
src/app/api/eco-spreadsheet/route.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
|
||||
const BodySchema = z.object({
|
||||
folderKey: z.string(),
|
||||
userId: z.string(),
|
||||
});
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json();
|
||||
let validatedBody;
|
||||
|
||||
try {
|
||||
validatedBody = BodySchema.parse(body);
|
||||
} catch (error) {
|
||||
console.error("Invalid input: ", error);
|
||||
return new NextResponse(JSON.stringify({ msg: "Invalid input" }), {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
// We'll trigger the plan build in our fastapi backend and then the user will just have to
|
||||
// wait for the plan to be ready
|
||||
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
|
||||
console.log("validatedBody", validatedBody);
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.ECO_SPREADSHEET_API_URL}/eco-spreadsheet`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
body: JSON.stringify(validatedBody),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("API request failed");
|
||||
}
|
||||
|
||||
const responseData = await response.json();
|
||||
|
||||
return new NextResponse(JSON.stringify(responseData), {
|
||||
status: 200,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return new NextResponse(JSON.stringify({ msg: "Internal server error" }), {
|
||||
status: 500,
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue