mirror of
https://github.com/yusufipk/dead-man-switch-2.0.git
synced 2026-09-12 01:36:06 +00:00
feat: phase 4 completed
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { authOptions } from "@/lib/auth/options";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function GET(
|
||||
req: Request,
|
||||
{ params }: { params: Promise<{ messageId: string }> }
|
||||
) {
|
||||
const { messageId } = await params;
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const message = await prisma.message.findUnique({
|
||||
where: { id: messageId, userId: session.user.id },
|
||||
include: { attachments: true },
|
||||
});
|
||||
|
||||
if (!message) {
|
||||
return new NextResponse("Not found", { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
message.attachments.map((a) => ({ id: a.id, fileName: a.fileName }))
|
||||
);
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export async function PATCH(
|
||||
|
||||
try {
|
||||
const body = await req.json();
|
||||
const { title, content, recipients, checkInterval } = body;
|
||||
const { title, content, recipients, checkInterval, isEncrypted } = body;
|
||||
|
||||
const existingMessage = await prisma.message.findUnique({
|
||||
where: { id: messageId, userId: session.user.id },
|
||||
@@ -40,6 +40,7 @@ export async function PATCH(
|
||||
title,
|
||||
content,
|
||||
checkInterval,
|
||||
isEncrypted: isEncrypted || existingMessage.isEncrypted,
|
||||
recipients: {
|
||||
create: recipients.map((email: string) => ({ email })),
|
||||
},
|
||||
|
||||
@@ -12,7 +12,7 @@ export async function POST(req: Request) {
|
||||
|
||||
try {
|
||||
const body = await req.json();
|
||||
const { title, content, recipients, checkInterval } = body;
|
||||
const { title, content, recipients, checkInterval, isEncrypted } = body;
|
||||
|
||||
const message = await prisma.message.create({
|
||||
data: {
|
||||
@@ -20,6 +20,7 @@ export async function POST(req: Request) {
|
||||
title,
|
||||
content,
|
||||
checkInterval,
|
||||
isEncrypted: isEncrypted || false,
|
||||
recipients: {
|
||||
create: recipients.map((email: string) => ({ email })),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user