Skip to content

Commit

Permalink
Save measurements if the user is logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepsinn committed Apr 27, 2024
1 parent c474fff commit 2aca004
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/nextjs/app/api/text2measurements/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { NextRequest, NextResponse } from 'next/server';
import { text2measurements } from "@/lib/text2measurements";
import {dfdaPOST} from "@/lib/dfda";
import {getServerSession} from "next-auth/next";
import {authOptions} from "@/lib/auth";

export async function POST(request: NextRequest) {
let { statement, localDateTime, text } = await request.json();
statement = statement || text;

try {
const measurements = await text2measurements(statement, localDateTime);
// If you want to save them, uncomment await dfdaPOST('/v3/measurements', measurements, session?.user.id);
const session = await getServerSession(authOptions);
const userId = session?.user.id;
if(userId){
await dfdaPOST('/v3/measurements', measurements, session?.user.id);
}
return NextResponse.json({ success: true, measurements: measurements });
} catch (error) {
// Log and handle any errors encountered during the request to OpenAI
Expand Down

0 comments on commit 2aca004

Please sign in to comment.