Skip to content

Commit

Permalink
added client api
Browse files Browse the repository at this point in the history
  • Loading branch information
aatbip committed Feb 2, 2024
1 parent f0b535f commit 77c70f6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/app/api/client/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { respondError } from '@/utils/common';
import { CopilotAPI } from '@/utils/copilotApiUtils';
import { NextResponse, NextRequest } from 'next/server';
import { z } from 'zod';

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams;
const clientId = searchParams.get('clientId');
const token = searchParams.get('token');
if (!token) {
return respondError('Missing token', 422);
}
if (!clientId) {
respondError('Missing client Id', 422);
}
const copilotClient = new CopilotAPI(z.string().parse(token));
try {
const client = await copilotClient.getClient(z.string().parse(clientId));

return NextResponse.json({ data: client });
} catch (error) {
console.log(error);
return respondError('Client not found.', 404);
}
}

0 comments on commit 77c70f6

Please sign in to comment.