23 lines
757 B
TypeScript
23 lines
757 B
TypeScript
|
|
import { NextRequest, NextResponse } from "next/server";
|
||
|
|
import { getServerSession } from "next-auth";
|
||
|
|
import { authOptions } from "@/app/_lib/auth";
|
||
|
|
import { getUserMetadata, saveUserMetadata } from "@/app/_lib/opensearch";
|
||
|
|
|
||
|
|
export const POST = async (req: NextRequest) => {
|
||
|
|
const session = await getServerSession(authOptions);
|
||
|
|
const { user: { email } }: any = session;
|
||
|
|
const { name, query } = await req.json();
|
||
|
|
const result = await getUserMetadata(email);
|
||
|
|
const { savedSearches } = result;
|
||
|
|
await saveUserMetadata(email, {
|
||
|
|
savedSearches: [...savedSearches, { name, query }]
|
||
|
|
});
|
||
|
|
const { savedSearches: updatedSavedSearches } = await getUserMetadata(email);
|
||
|
|
|
||
|
|
return NextResponse.json(updatedSavedSearches);
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|