From be0f537dc4fe384eef09436833c6407e6482c16d Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 9 Nov 2023 15:40:16 +0700 Subject: Initial commit --- src/app/api/location/route.tsx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/app/api/location/route.tsx (limited to 'src/app/api/location') diff --git a/src/app/api/location/route.tsx b/src/app/api/location/route.tsx new file mode 100644 index 0000000..452a85d --- /dev/null +++ b/src/app/api/location/route.tsx @@ -0,0 +1,27 @@ +import { NextRequest, NextResponse } from "next/server"; +import { prisma } from "prisma/client"; +import { Credential } from "@/common/types/auth" + +export async function GET(request: NextRequest) { + const searchParams = request.nextUrl.searchParams; + const search = searchParams.get('search'); + + const credentialStr = request.cookies.get('credential')?.value + const credential: Credential | null = credentialStr ? JSON.parse(credentialStr) : null + + if (!credential) { + return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) + } + + const { companyId } = credential + + const locations = await prisma.location.findMany({ + where: { + companyId, + name: { contains: search ?? '' } + }, + take: 20 + }) + + return NextResponse.json(locations) +} \ No newline at end of file -- cgit v1.2.3