tasko/app/api/cards/[cardId]/logs/route.ts

36 lines
815 B
TypeScript
Raw Normal View History

2024-03-21 21:15:27 +00:00
import { auth } from '@clerk/nextjs/server';
2024-02-16 01:49:19 +00:00
import { ENTITY_TYPE } from '@prisma/client';
import { NextResponse } from 'next/server';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import { db } from '@/lib/db';
2024-02-15 02:30:10 +00:00
2024-08-22 18:43:08 +00:00
export async function GET(
req: Request,
{ params }: { params: { cardId: string } }
) {
2024-02-15 02:30:10 +00:00
try {
const { orgId, userId } = auth();
if (!orgId || !userId)
2024-02-16 01:49:19 +00:00
return new NextResponse(JSON.stringify({ error: 'Unauthorized' }), {
2024-02-15 02:30:10 +00:00
status: 401,
});
const auditLogs = await db.auditLog.findMany({
where: {
orgId,
entityId: params.cardId,
entityType: ENTITY_TYPE.CARD,
},
orderBy: {
2024-02-16 01:49:19 +00:00
createdAt: 'desc',
2024-02-15 02:30:10 +00:00
},
take: 3,
});
return NextResponse.json(auditLogs);
} catch (error) {
return new NextResponse(JSON.stringify(error), { status: 500 });
}
}