Skip to content

Commit

Permalink
Merge branch 'feature/ai'
Browse files Browse the repository at this point in the history
  • Loading branch information
schobele committed Nov 15, 2024
2 parents 5dfce79 + af83a28 commit 2476155
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/app/api/v1/checkly/alertreceiver/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
generateContextAnalysisSummary,
} from "src/aggregator/chains";
import { WebhookAlertDto } from "src/checkly/alertDTO";
import { prisma } from "src/prisma";
import { Prisma } from "@prisma/client";

export async function GET() {
return NextResponse.json({ message: "Hello from Next.js!" });
Expand All @@ -29,8 +31,21 @@ export async function POST(request: NextRequest) {
const contextAnalysis = await generateContextAnalysis(context);
const summary = await generateContextAnalysisSummary(contextAnalysis);

// TODO: Save the alert to the database
console.log("Context analysis summary:", summary);
await prisma.alert
.create({
data: {
data: { ...alertDto } as unknown as Prisma.InputJsonValue,
context: JSON.stringify(contextAnalysis),
summary,
},
})
.catch((error) => {
console.error("Error saving alert to the database:", error);
return NextResponse.json(
{ message: "Error saving alert to the database" },
{ status: 500 }
);
});

return NextResponse.json({ message: "OK" });
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion src/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PrismaClient } from "@prisma/client";

export const prisma = new PrismaClient();
export const prisma = new PrismaClient({
datasourceUrl: process.env.DATABASE_URL,
});

0 comments on commit 2476155

Please sign in to comment.