updated living space
This commit is contained in:
21
frontend/app/api/company/add/route.ts
Normal file
21
frontend/app/api/company/add/route.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { CreateCompanyInputSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const validatedBody = CreateCompanyInputSchema.parse(body);
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`mutation createCompany($input: CreateCompanyInput!) { createCompany(input: $input) {_id}}`;
|
||||
const variables = { input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.createCompany, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
26
frontend/app/api/company/add/schema.ts
Normal file
26
frontend/app/api/company/add/schema.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const CreateCompanyInputSchema = z.object({
|
||||
formal_name: z.string(),
|
||||
company_type: z.string(),
|
||||
commercial_type: z.string(),
|
||||
tax_no: z.string(),
|
||||
public_name: z.string(),
|
||||
company_tag: z.string(),
|
||||
|
||||
default_lang_type: z.string().default("TR"),
|
||||
default_money_type: z.string().default("TL"),
|
||||
|
||||
is_commercial: z.boolean().default(false),
|
||||
is_blacklist: z.boolean().default(false),
|
||||
|
||||
parent_id: z.string().optional(),
|
||||
workplace_no: z.string().optional(),
|
||||
official_address: z.string().optional(),
|
||||
top_responsible_company: z.string().optional(),
|
||||
expiryStarts: z.string().optional(),
|
||||
expiryEnds: z.string().optional(),
|
||||
|
||||
});
|
||||
|
||||
export type CreateCompanyInput = z.infer<typeof CreateCompanyInputSchema>;
|
||||
Reference in New Issue
Block a user