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,
|
2024-10-15 23:55:03 +00:00
|
|
|
props: { params: Promise<{ cardId: string }> }
|
2024-08-22 18:43:08 +00:00
|
|
|
) {
|
2024-10-15 23:55:03 +00:00
|
|
|
const params = await props.params;
|
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 });
|
|
|
|
}
|
|
|
|
}
|