Skip to content

Commit

Permalink
Merge pull request #191 from mikepsinn/develop
Browse files Browse the repository at this point in the history
Save measurements if the user is logged in
  • Loading branch information
mikepsinn authored Apr 28, 2024
2 parents 88861f0 + a1857ca commit e28517f
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 e28517f

Please sign in to comment.