-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathroute.ts
More file actions
34 lines (28 loc) · 1.06 KB
/
Copy pathroute.ts
File metadata and controls
34 lines (28 loc) · 1.06 KB
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
import { headers } from 'next/headers';
import { NextResponse } from 'next/server';
import { z } from 'zod';
import { skillsArraySchema } from '@/interface/skills';
import { getUserSession } from '@/features/auth/utils/getUserSession';
import { getEmailEstimate } from '@/features/listing-builder/components/Form/Boost/server-queries';
const BodySchema = z.object({
skills: skillsArraySchema,
region: z.string().optional().nullable(),
});
export async function POST(request: Request) {
const session = await getUserSession(await headers());
if (session.status !== 200 || !session.data) {
return NextResponse.json(
{ error: session.error || 'Unauthorized' },
{ status: session.status || 401 },
);
}
try {
const json = await request.json();
const { skills, region } = BodySchema.parse(json);
const count = await getEmailEstimate(skills, region);
return NextResponse.json({ count });
} catch (error) {
console.error('email-estimate error', error);
return NextResponse.json({ error: 'Bad Request' }, { status: 400 });
}
}