-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
37 lines (33 loc) · 1014 Bytes
/
route.ts
File metadata and controls
37 lines (33 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { NextRequest, NextResponse } from "next/server";
import { getDataToken } from "@/utils/getDataToken";
import prisma from "../../../../lib/prisma";
export async function GET(request: NextRequest, response: NextResponse) {
try {
await getDataToken(request);
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.searchParams);
const id = searchParams.get("categoryId");
if (!id) {
return NextResponse.json(
{ error: "categoryId is required" },
{ status: 400 }
);
}
const categoryItems = await prisma.category.findUnique({
where: {
id: id,
},
include: {
categoryItems: {
include: {
Item: true,
},
},
},
});
const items = categoryItems?.categoryItems.map((ci) => ci.Item);
return NextResponse.json({ items }, { status: 200 });
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 400 });
}
}