2024-03-21 17:15:27 -04:00
|
|
|
import { auth } from '@clerk/nextjs/server';
|
2024-02-15 20:49:19 -05:00
|
|
|
import { NextResponse } from 'next/server';
|
2024-02-14 21:30:10 -05:00
|
|
|
|
2024-02-15 20:49:19 -05:00
|
|
|
import { db } from '@/lib/db';
|
2024-02-14 21:30:10 -05:00
|
|
|
|
2024-08-22 14:43:08 -04:00
|
|
|
export async function GET(
|
|
|
|
req: Request,
|
2024-10-15 19:55:03 -04:00
|
|
|
props: { params: Promise<{ cardId: string }> }
|
2024-08-22 14:43:08 -04:00
|
|
|
) {
|
2024-10-15 19:55:03 -04:00
|
|
|
const params = await props.params;
|
2024-02-14 21:30:10 -05:00
|
|
|
try {
|
2024-10-23 19:17:45 -04:00
|
|
|
const { orgId, userId } = await auth();
|
2024-02-14 21:30:10 -05:00
|
|
|
|
|
|
|
if (!orgId || !userId)
|
2024-02-15 20:49:19 -05:00
|
|
|
return new NextResponse(JSON.stringify({ error: 'Unauthorized' }), {
|
2024-02-14 21:30:10 -05:00
|
|
|
status: 401,
|
|
|
|
});
|
|
|
|
|
|
|
|
const card = await db.card.findUnique({
|
|
|
|
where: {
|
|
|
|
id: params.cardId,
|
|
|
|
list: {
|
|
|
|
board: {
|
|
|
|
orgId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
include: {
|
|
|
|
list: {
|
|
|
|
select: {
|
|
|
|
title: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-12-23 15:54:45 -05:00
|
|
|
cacheStrategy: {
|
|
|
|
ttl: 30,
|
|
|
|
swr: 60,
|
|
|
|
},
|
2024-02-14 21:30:10 -05:00
|
|
|
});
|
|
|
|
|
2024-12-23 14:14:15 -05:00
|
|
|
return new NextResponse(JSON.stringify(card), {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Cache-Control': 'public, s-maxage=1',
|
2024-12-27 18:00:27 -05:00
|
|
|
'CDN-Cache-Control': 'public, s-maxage=30',
|
|
|
|
'Vercel-CDN-Cache-Control': 'public, s-maxage=60',
|
2024-12-23 14:14:15 -05:00
|
|
|
},
|
|
|
|
});
|
2024-02-14 21:30:10 -05:00
|
|
|
} catch (error) {
|
|
|
|
return new NextResponse(JSON.stringify(error), { status: 500 });
|
|
|
|
}
|
|
|
|
}
|