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

42 lines
860 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 { 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,
props: { params: Promise<{ cardId: string }> }
2024-08-22 18:43:08 +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 card = await db.card.findUnique({
where: {
id: params.cardId,
list: {
board: {
orgId,
},
},
},
include: {
list: {
select: {
title: true,
},
},
},
});
return NextResponse.json(card);
} catch (error) {
return new NextResponse(JSON.stringify(error), { status: 500 });
}
}