mirror of
https://github.com/yusufipk/dead-man-switch-2.0.git
synced 2026-09-11 09:26:07 +00:00
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { getServerSession } from 'next-auth';
|
|
import { authOptions } from '@/lib/auth/options';
|
|
import { prisma } from '@/lib/prisma';
|
|
|
|
export async function POST(
|
|
req: Request,
|
|
{ params }: { params: Promise<{ messageId: string }> }
|
|
) {
|
|
const session = await getServerSession(authOptions);
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const { messageId } = await params;
|
|
const { status } = await req.json();
|
|
|
|
if (!['DRAFT', 'ACTIVE'].includes(status)) {
|
|
return NextResponse.json({ error: 'Invalid status' }, { status: 400 });
|
|
}
|
|
|
|
const message = await prisma.message.findUnique({
|
|
where: { id: messageId, userId: session.user.id },
|
|
});
|
|
|
|
if (!message) {
|
|
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
|
}
|
|
|
|
const updated = await prisma.message.update({
|
|
where: { id: messageId },
|
|
data: { status, lastPing: new Date() },
|
|
});
|
|
|
|
return NextResponse.json({ success: true, status: updated.status });
|
|
}
|