UI overhault
This commit is contained in:
27
app/api/emails/mark-read/route.ts
Normal file
27
app/api/emails/mark-read/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { db } from '@/app/db/drizzle';
|
||||
import { emails } from '@/app/db/schema';
|
||||
import { authenticate } from '@/app/lib/utils';
|
||||
import { inArray } from 'drizzle-orm';
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
if (!authenticate(req)) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const { keys } = await req.json();
|
||||
|
||||
if (!Array.isArray(keys) || keys.length === 0) {
|
||||
return NextResponse.json({ error: 'Invalid keys' }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
await db
|
||||
.update(emails)
|
||||
.set({ processed: true, processedAt: new Date() })
|
||||
.where(inArray(emails.s3Key, keys));
|
||||
|
||||
return NextResponse.json({ success: true, count: keys.length });
|
||||
} catch (error) {
|
||||
console.error('Error marking emails as read:', error);
|
||||
return NextResponse.json({ error: 'Failed to mark as read' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user