2024-03-21 21:15:27 +00:00
|
|
|
import { auth } from '@clerk/nextjs/server';
|
2024-02-16 01:49:19 +00:00
|
|
|
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 {
|
2024-10-23 23:17:45 +00:00
|
|
|
const { orgId, userId } = await auth();
|
2024-02-15 02:30:10 +00:00
|
|
|
|
|
|
|
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 card = await db.card.findUnique({
|
|
|
|
where: {
|
|
|
|
id: params.cardId,
|
|
|
|
list: {
|
|
|
|
board: {
|
|
|
|
orgId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
include: {
|
|
|
|
list: {
|
|
|
|
select: {
|
|
|
|
title: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-12-23 19:14:15 +00:00
|
|
|
return new NextResponse(JSON.stringify(card), {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Cache-Control': 'public, s-maxage=1',
|
|
|
|
'CDN-Cache-Control': 'public, s-maxage=60',
|
|
|
|
'Vercel-CDN-Cache-Control': 'public, s-maxage=3600',
|
|
|
|
},
|
|
|
|
});
|
2024-02-15 02:30:10 +00:00
|
|
|
} catch (error) {
|
|
|
|
return new NextResponse(JSON.stringify(error), { status: 500 });
|
|
|
|
}
|
|
|
|
}
|