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>;
|
||||
23
frontend/app/api/company/delete/route.ts
Normal file
23
frontend/app/api/company/delete/route.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
|
||||
const searchParams = new URL(request.url).searchParams;
|
||||
const uuid = searchParams.get('uuid');
|
||||
console.dir({ uuid }, { depth: null });
|
||||
if (!uuid) { return NextResponse.json({ error: 'UUID not found in search params' }, { status: 400 }) }
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`mutation DeleteCompany($uuid: String!) { deleteCompany(uuid: $uuid) }`;
|
||||
const data = await client.request(query, { uuid });
|
||||
return NextResponse.json({ data: data.deleteUserType, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
|
||||
}
|
||||
47
frontend/app/api/company/list/route.ts
Normal file
47
frontend/app/api/company/list/route.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const { limit, skip, sort, filters } = body;
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
query GetCompanies($input: ListArguments!) {
|
||||
getCompanies(input:$input) {
|
||||
data {
|
||||
_id
|
||||
uuid
|
||||
company_type
|
||||
commercial_type
|
||||
tax_no
|
||||
default_lang_type
|
||||
default_money_type
|
||||
is_commercial
|
||||
is_blacklist
|
||||
workplace_no
|
||||
official_address
|
||||
top_responsible_company
|
||||
parent_id
|
||||
company_tag
|
||||
formal_name
|
||||
public_name
|
||||
parent_id
|
||||
expiryStarts
|
||||
expiryEnds
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { input: { limit, skip, sort, filters } };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.getCompanies.data, totalCount: data.getCompanies.totalCount });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
24
frontend/app/api/company/update/route.ts
Normal file
24
frontend/app/api/company/update/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { UpdateCompanyInputSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const searchUrl = new URL(request.url);
|
||||
const uuid = searchUrl.searchParams.get("uuid") || "";
|
||||
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||
const body = await request.json();
|
||||
const validatedBody = UpdateCompanyInputSchema.parse(body);
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`mutation UpdateCompany($uuid: String!, $input: UpdateCompanyInput!) { updateCompany(uuid:$uuid, input: $input) {_id} }`;
|
||||
const variables = { uuid: uuid, input: { ...validatedBody } };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.updateCompany, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
23
frontend/app/api/company/update/schema.ts
Normal file
23
frontend/app/api/company/update/schema.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const UpdateCompanyInputSchema = 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 UpdateCompanyInput = z.infer<typeof UpdateCompanyInputSchema>;
|
||||
21
frontend/app/api/living-space/add/route.ts
Normal file
21
frontend/app/api/living-space/add/route.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { CreateLivingSpaceInputSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const validatedBody = CreateLivingSpaceInputSchema.parse(body);
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`mutation CreateLivingSpace($input: CreateLivingSpaceInput!) { createLivingSpace(input:$input) { _id }}`;
|
||||
const variables = { input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.createLivingSpace, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
14
frontend/app/api/living-space/add/schema.ts
Normal file
14
frontend/app/api/living-space/add/schema.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const CreateLivingSpaceInputSchema = z.object({
|
||||
buildID: z.string(),
|
||||
collectionToken: z.string(),
|
||||
partID: z.string(),
|
||||
userTypeID: z.string(),
|
||||
companyID: z.string(),
|
||||
personID: z.string(),
|
||||
expiryStarts: z.string().optional(),
|
||||
expiryEnds: z.string().optional(),
|
||||
});
|
||||
|
||||
export type CreateLivingSpaceInput = z.infer<typeof CreateLivingSpaceInputSchema>;
|
||||
23
frontend/app/api/living-space/delete/route.ts
Normal file
23
frontend/app/api/living-space/delete/route.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
|
||||
const searchParams = new URL(request.url).searchParams;
|
||||
const uuid = searchParams.get('uuid');
|
||||
console.dir({ uuid }, { depth: null });
|
||||
if (!uuid) { return NextResponse.json({ error: 'UUID not found in search params' }, { status: 400 }) }
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`mutation DeleteCompany($uuid: String!) { deleteCompany(uuid: $uuid) }`;
|
||||
const data = await client.request(query, { uuid });
|
||||
return NextResponse.json({ data: data.deleteUserType, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
|
||||
}
|
||||
47
frontend/app/api/living-space/list/route.ts
Normal file
47
frontend/app/api/living-space/list/route.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const { limit, skip, sort, filters } = body;
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
query GetCompanies($input: ListArguments!) {
|
||||
getCompanies(input:$input) {
|
||||
data {
|
||||
_id
|
||||
uuid
|
||||
company_type
|
||||
commercial_type
|
||||
tax_no
|
||||
default_lang_type
|
||||
default_money_type
|
||||
is_commercial
|
||||
is_blacklist
|
||||
workplace_no
|
||||
official_address
|
||||
top_responsible_company
|
||||
parent_id
|
||||
company_tag
|
||||
formal_name
|
||||
public_name
|
||||
parent_id
|
||||
expiryStarts
|
||||
expiryEnds
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { input: { limit, skip, sort, filters } };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.getCompanies.data, totalCount: data.getCompanies.totalCount });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
24
frontend/app/api/living-space/update/route.ts
Normal file
24
frontend/app/api/living-space/update/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { UpdateLivingSpaceInputSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const searchUrl = new URL(request.url);
|
||||
const uuid = searchUrl.searchParams.get("uuid") || "";
|
||||
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||
const body = await request.json();
|
||||
const validatedBody = UpdateLivingSpaceInputSchema.parse(body);
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`mutation UpdateLivingSpace($uuid: String!, $input: UpdateLivingSpaceInput!) { updateLivingSpace(uuid:$uuid, input: $input) {_id} }`;
|
||||
const variables = { uuid: uuid, input: { ...validatedBody } };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.updateLivingSpace, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
14
frontend/app/api/living-space/update/schema.ts
Normal file
14
frontend/app/api/living-space/update/schema.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const UpdateLivingSpaceInputSchema = z.object({
|
||||
buildID: z.string(),
|
||||
collectionToken: z.string(),
|
||||
partID: z.string(),
|
||||
userTypeID: z.string(),
|
||||
companyID: z.string(),
|
||||
personID: z.string(),
|
||||
expiryStarts: z.string().optional(),
|
||||
expiryEnds: z.string().optional(),
|
||||
});
|
||||
|
||||
export type UpdateLivingSpaceInput = z.infer<typeof UpdateLivingSpaceInputSchema>;
|
||||
5
frontend/app/living-spaces/add/page.tsx
Normal file
5
frontend/app/living-spaces/add/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { PageLivingSpaceAdd } from "@/pages/living-space/add/page";
|
||||
|
||||
const SSRPageLivingSpaceAdd = () => { return <><PageLivingSpaceAdd /></> }
|
||||
|
||||
export default SSRPageLivingSpaceAdd;
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PageLivingSpace } from "@/pages/living-space/tables/page"
|
||||
// import { PageLivingSpace } from "@/pages/living-space/add/page"
|
||||
|
||||
const SSRPageLivingSpace = () => { return <><PageLivingSpace /></> }
|
||||
const SSRPageLivingSpace = () => { return <><div>PageLivingSpace</div></> }
|
||||
|
||||
export default SSRPageLivingSpace;
|
||||
|
||||
Reference in New Issue
Block a user