Housekeeping

This commit is contained in:
KMKoushik
2024-04-28 09:39:47 +10:00
parent 814d9e9e37
commit e78befd4cf
6 changed files with 29 additions and 50 deletions
-36
View File
@@ -1,36 +0,0 @@
import { headers } from "next/headers";
import { hashToken } from "~/server/auth";
import { db } from "~/server/db";
import { sendEmail } from "~/server/service/email-service";
export async function GET() {
return Response.json({ data: "Hello" });
}
export async function POST(req: Request) {
const token = headers().get("authorization")?.split(" ")[1];
console.log(token);
if (!token) {
return new Response("authorization token is required", {
status: 401,
});
}
const hashedToken = hashToken(token);
const team = await db.team.findFirst({
where: {
apiKeys: {
some: {
tokenHash: hashedToken,
},
},
},
});
const data = await req.json();
try {
const email = await sendEmail({ ...data, teamId: team?.id });
return Response.json({ data: email });
} catch (e) {
return Response.json({ error: (e as Error).message }, { status: 500 });
}
}