summaryrefslogtreecommitdiff
path: root/app/api/upload/generalContract/complete/route.ts
blob: 5f711f0779a17c44a7e774c37dc61e9db92bb6d5 (plain)
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
import { NextRequest, NextResponse } from 'next/server';
import { createContractTemplate } from '@/lib/general-contract-template/service';
import { revalidatePath, revalidateTag } from 'next/cache';
import { createContractTemplateSchema } from '@/lib/general-contract-template/validations';

export async function POST(request: NextRequest) {
  try {
    const json = await request.json();
    const parsed = createContractTemplateSchema.safeParse(json);
    
    if (!parsed.success) {
      return NextResponse.json(
        { success: false, error: parsed.error.flatten() },
        { status: 400 }
      );
    }

    const { data, error } = await createContractTemplate(parsed.data);

    revalidatePath('/evcp/general-contract-template');
    revalidateTag("general-contract-templates");

    if (error) {
      throw new Error(error);
    }
    
    return NextResponse.json({ success: true, data });
    
  } catch (error) {
    console.error('템플릿 저장 오류:', error);
    return NextResponse.json({ success: false, error: '서버 오류' }, { status: 500 });
  }
}